-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FEC-8364): support adding evaluated expressions also on player s…
…etup and configure API (#139) When calling player.setup or player.configure we need to: Evaluate new expressions that are passed with tokens Add new evaluation tokens to the list of evaluated tokens so they can be re-evaluated on each media change. This feature will create a plugin token config store. On each call to evaluate the list of new expressions will be analyzed, and if it contains evaluation tokens these tokens will be analyzed and also be saved in the config store so in next call to configure, loadMedia or setMedia the player will run the evaluation process on them.
- Loading branch information
Showing
4 changed files
with
221 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
//@flow | ||
import {Utils} from 'playkit-js' | ||
|
||
type dataStoreType = {[pluginName: string]: Object}; | ||
const defaultConfig: dataStoreType = { | ||
"youbora": { | ||
"playerVersion": "{{pVersion}}", | ||
"playerName": "{{pName}}", | ||
"entryId": "{{entryId}}", | ||
"entryName": "{{entryName}}", | ||
"entryType": "{{entryType}}", | ||
"sessionId": "{{sessionId}}", | ||
"uiConfId": "{{uiConfId}}" | ||
}, | ||
"kanalytics": { | ||
"playerVersion": "{{pVersion}}", | ||
"entryId": "{{entryId}}", | ||
"entryType": "{{entryType}}", | ||
"sessionId": "{{sessionId}}", | ||
"ks": "{{ks}}", | ||
"uiConfId": "{{uiConfId}}", | ||
"partnerId": "{{partnerId}}", | ||
"referrer": "{{referrer}}" | ||
}, | ||
"googleAnalytics": { | ||
"entryId": "{{entryId}}", | ||
"entryName": "{{entryName}}", | ||
"uiConfId": "{{uiConfId}}", | ||
"partnerId": "{{partnerId}}" | ||
}, | ||
"ottAnalytics": { | ||
"entryId": "{{entryId}}", | ||
"ks": "{{ks}}", | ||
"isAnonymous": "{{isAnonymous}}", | ||
"partnerId": "{{partnerId}}", | ||
"serviceUrl": "{{serviceUrl}}" | ||
}, | ||
"ima": { | ||
"playerVersion": "{{pVersion}}", | ||
"playerName": "{{pName}}" | ||
}, | ||
"kava": { | ||
"playerVersion": "{{pVersion}}", | ||
"playerName": "{{pName}}", | ||
"partnerId": "{{partnerId}}", | ||
"entryId": "{{entryId}}", | ||
"entryType": "{{entryType}}", | ||
"sessionId": "{{sessionId}}", | ||
"ks": "{{ks}}", | ||
"uiConfId": "{{uiConfId}}", | ||
"referrer": "{{referrer}}" | ||
}, | ||
"comscore": { | ||
"playerVersion": "{{pVersion}}" | ||
}, | ||
"vr": { | ||
"rootElement": "{{domRootElementId}}" | ||
} | ||
}; | ||
|
||
let config = Utils.Object.copyDeep(defaultConfig); | ||
const templateRegex = new RegExp(('{{.*}}')); | ||
|
||
/** | ||
* extract the object members which include an evaluation token of type {{.*}} | ||
* @param {Object} obj - the config object | ||
* @returns {dataStoreType} - the new object with new tokens | ||
*/ | ||
const resolveNewConfig = (obj = {}): Object => | ||
Object.entries(obj) | ||
.reduce( | ||
(product, [key, value]): Object => { | ||
if (Utils.Object.isObject(value)) { | ||
product[key] = resolveNewConfig(value) | ||
} else if (typeof value === "string" && templateRegex.test(value)) { | ||
product[key] = value; | ||
} else { | ||
product[key] = undefined; | ||
} | ||
return product; | ||
}, | ||
{} | ||
); | ||
|
||
/** | ||
* remove undefined members from the token data store | ||
* @param {Object} obj - the config object | ||
* @returns {dataStoreType} - the new object with valid evaluate tokens | ||
*/ | ||
const removeUndefineds = (obj = {}): Object => | ||
Object.entries(obj) | ||
.reduce( | ||
(product, [key, value]): Object => { | ||
if (Utils.Object.isObject(value)) { | ||
product[key] = removeUndefineds(value) | ||
} else if (value) { | ||
product[key] = value; | ||
} | ||
return product; | ||
}, | ||
{} | ||
); | ||
|
||
|
||
const pluginConfig = { | ||
/** | ||
* return the token store object | ||
* @returns {*|any} - token store object | ||
*/ | ||
get: (): dataStoreType => { | ||
return config; | ||
}, | ||
/** | ||
* recalculate the token store data, if new config with token is passed then add it to the data store, and if | ||
* an existing token needs to be removed then remove it | ||
* @param {?dataStoreType} pluginsConfig - the new config object | ||
* @returns {void} | ||
*/ | ||
set: (pluginsConfig: ?dataStoreType): void => { | ||
if (pluginsConfig) { | ||
const newConfig = resolveNewConfig(pluginsConfig); | ||
config = removeUndefineds(Utils.Object.mergeDeep(config, newConfig)); | ||
} | ||
}, | ||
/** | ||
* reset the config store to its initial state | ||
* @returns {void} | ||
*/ | ||
reset: (): void => { | ||
config = Utils.Object.copyDeep(defaultConfig); | ||
} | ||
}; | ||
|
||
export {pluginConfig, templateRegex}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters