Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEC-8696 ui components #387

Merged
merged 9 commits into from
Sep 16, 2019
5 changes: 5 additions & 0 deletions flow-typed/interfaces/preset-components-provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @flow

declare interface IUIComponentsProvider {
getUIComponents(): Array<PKUIComponent>;
}
11 changes: 11 additions & 0 deletions flow-typed/types/ui-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

type PKUIComponent = {
label: string,
presets: Array<string>,
container: string,
get: Function,
props: {},
beforeComponent?: string,
afterComponent?: string,
replaceComponent?: string
};
17 changes: 17 additions & 0 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ export default class Player extends FakeEventTarget {
* @private
*/
_resizeWatcher: ResizeWatcher;
/**
* Holds preset component factories
* @type {?PKUIComponent}
* @private
*/
_uiComponents: Array<PKUIComponent>;

/**
* @param {Object} config - The configuration for the player instance.
Expand All @@ -404,6 +410,7 @@ export default class Player extends FakeEventTarget {
Player.runCapabilities();
this._env = Env;
this._tracks = [];
this._uiComponents = [];
this._firstPlay = true;
this._repositionCuesTimeout = false;
this._loadingMedia = false;
Expand Down Expand Up @@ -936,6 +943,10 @@ export default class Player extends FakeEventTarget {
return Utils.Object.mergeDeep({}, this._config);
}

get uiComponents(): PKUIComponent[] {
return [...this._uiComponents];
}

/**
* Set the _loadingMedia flag to inform the player that a load media request has sent.
* @param {boolean} loading - Whether a load media request has sent.
Expand Down Expand Up @@ -1489,6 +1500,7 @@ export default class Player extends FakeEventTarget {
_configureOrLoadPlugins(plugins: Object = {}): void {
if (plugins) {
const middlewares = [];
const uiComponents = [];
Object.keys(plugins).forEach(name => {
// If the plugin is already exists in the registry we are updating his config
const plugin = this._pluginManager.get(name);
Expand All @@ -1511,12 +1523,17 @@ export default class Player extends FakeEventTarget {
// push the bumper middleware to the end, to play the bumper right before the content
plugin.name === 'bumper' ? middlewares.push(plugin.getMiddlewareImpl()) : middlewares.unshift(plugin.getMiddlewareImpl());
}

if (typeof plugin.getUIComponents === 'function') {
uiComponents.push(...(plugin.getUIComponents() || []));
}
}
} else {
delete this._config.plugins[name];
}
}
});
this._uiComponents = uiComponents;
middlewares.forEach(middleware => this._playbackMiddleware.use(middleware));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/playkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export {Track, VideoTrack, AudioTrack, TextTrack, TextStyle};
// Export utils library
export {Utils};

export {Utils as utils};

// Export Error class
export {Error};

Expand Down