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

feat: support server side config #65

Merged
merged 4 commits into from
Dec 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/kaltura-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ export default class KalturaPlayer {
this._uiManager = new PlaykitUI(this._player, {targetId: targetId, logLevel: playerConfig.logLevel});
const forceTouchUI = playerConfig.ui ? playerConfig.ui.forceTouchUI : false;
setUITouchConfig(forceTouchUI, this._uiManager);
this._provider = new OvpProvider(__VERSION__, providerConfig.partnerId, providerConfig.ks, providerConfig.env, playerConfig.logLevel);
const providerConf = {
ks: providerConfig.ks,
playerVersion: __VERSION__,
config: providerConfig.env,
logLevel: playerConfig.logLevel,
partnerID: providerConfig.partnerId,
loadUiConf: providerConfig.loadUiConf
}
this._provider = new OvpProvider(providerConf);
this._uiManager.buildDefaultUI();
return {
loadMedia: this.loadMedia.bind(this)
Expand Down
18 changes: 9 additions & 9 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function setup(targetId: string, options: Object = {}): KalturaPlayer {
setLogLevel(options);
validateTargetId(targetId);
validateProvidersConfig(options);
let userPlayerConfig = extractPlayerConfig(options);
let userProvidersConfig = extractProvidersConfig(options);
let containerId = createKalturaPlayerContainer(targetId);
setDefaultPlayerConfig(userPlayerConfig);
evaluatePluginsConfig(userPlayerConfig);
setStorageConfig(userPlayerConfig);
let player = loadPlayer(userPlayerConfig);
let kalturaPlayerApi = new KalturaPlayer(player, containerId, userPlayerConfig, userProvidersConfig);
let kalturaPlayer = Object.assign(player, kalturaPlayerApi);
const playerConfig = extractPlayerConfig(options);
const providersConfig = extractProvidersConfig(options);
const containerId = createKalturaPlayerContainer(targetId);
setDefaultPlayerConfig(playerConfig);
evaluatePluginsConfig(playerConfig);
setStorageConfig(playerConfig);
const player = loadPlayer(playerConfig);
const kalturaPlayerApi = new KalturaPlayer(player, containerId, playerConfig, providersConfig);
const kalturaPlayer = Object.assign(player, kalturaPlayerApi);
setStorageTextStyle(kalturaPlayer);
applyStorageSupport(kalturaPlayer);
return kalturaPlayer;
Expand Down
44 changes: 37 additions & 7 deletions src/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ function validateTargetId(targetId: string) {
*/
function extractPlayerConfig(config: ?Object): Object {
let playerConfig = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const (deletable) also in extractProvidersConfig below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Utils.Object.mergeDeep(playerConfig, config);
delete playerConfig.partnerId;
delete playerConfig.entryId;
delete playerConfig.uiConfId;
delete playerConfig.env;
delete playerConfig.ks;
if (config) {
const serverUIConf = extractServerUiconf(config.uiConfId);
Utils.Object.mergeDeep(playerConfig, serverUIConf, config);
delete playerConfig.partnerId;
delete playerConfig.entryId;
delete playerConfig.uiConfId;
delete playerConfig.env;
delete playerConfig.ks;
}
return playerConfig;
}

Expand All @@ -66,12 +69,39 @@ function extractProvidersConfig(config: ?Object): Object {
providerConfig.partnerId = config.partnerId;
providerConfig.entryId = config.entryId;
providerConfig.uiConfId = config.uiConfId;
providerConfig.env = config.env;
providerConfig.loadUiConf = serverUiconfExist(config.uiConfId);
const serverUIConf = extractServerUiconf(config.uiConfId);
providerConfig.env = Utils.Object.mergeDeep({}, serverUIConf.env, config.env);
providerConfig.ks = config.ks;
}
return providerConfig;
}

/**
* checks if the server UIConf exist
* @param {number} uiConfId - The server UIConf
* @returns {boolean} - server UIConf exist
*/
function serverUiconfExist(uiConfId: number): boolean{
return (uiConfId !== null) && (uiConfId !== undefined) &&
window.__kalturaplayerdata &&
window.__kalturaplayerdata.UIConf &&
(window.__kalturaplayerdata.UIConf[uiConfId] !== undefined);
}

/**
* Extracts the server UIConf
* @param {number} uiConfId - The server UIConf
* @returns {Object} - The server UIConf
*/
function extractServerUiconf(uiConfId: number): Object{
let config = {};
if (serverUiconfExist(uiConfId)){
config = window.__kalturaplayerdata.UIConf[uiConfId];
}
return config;
}

/**
* Creates the player container dom element.
* @param {string} targetId - The div id which the player will append to.
Expand Down