diff --git a/package.json b/package.json index d0655b855..577ce0789 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "dependencies": { "@babel/polyfill": "^7.0.0", - "@playkit-js/playkit-js": "0.65.0-canary.9cbf0cf", + "@playkit-js/playkit-js": "0.65.0-canary.6583361", "@playkit-js/playkit-js-dash": "1.20.3", "@playkit-js/playkit-js-hls": "1.21.2", "@playkit-js/playkit-js-ui": "0.60.1", diff --git a/src/common/plugins/plugins-config.js b/src/common/plugins/plugins-config.js index 59fb2d251..38e3cc624 100644 --- a/src/common/plugins/plugins-config.js +++ b/src/common/plugins/plugins-config.js @@ -11,7 +11,11 @@ import {Utils} from '@playkit-js/playkit-js'; * @returns {boolean} - value is evaluated */ const isValueEvaluated = (value: any): boolean => - (typeof value === 'number' || typeof value === 'function' || typeof value === 'string' || typeof value === 'boolean') && + (typeof value === 'number' || + typeof value === 'function' || + typeof value === 'string' || + typeof value === 'boolean' || + Utils.Object.isClassInstance(value)) && !templateRegex.test(value.toString()); /** @@ -22,7 +26,7 @@ const isValueEvaluated = (value: any): boolean => */ const removeUnevaluatedExpression = (obj: Object = {}): Object => Object.entries(obj).reduce((product, [key, value]): Object => { - if (typeof value !== 'function' && Utils.Object.isObject(value)) { + if (Utils.Object.isObject(value) && typeof value !== 'function' && !Utils.Object.isClassInstance(value)) { product[key] = removeUnevaluatedExpression(value); } else if (Array.isArray(value)) { product[key] = value.filter(index => isValueEvaluated(index)); diff --git a/test/src/kaltura-player.spec.js b/test/src/kaltura-player.spec.js index 36dbf9c41..1955c762a 100644 --- a/test/src/kaltura-player.spec.js +++ b/test/src/kaltura-player.spec.js @@ -663,4 +663,86 @@ describe('kaltura player api', function () { player.dispatchEvent(new FakeEvent(player.Event.AD_AUTOPLAY_FAILED, {error: 'mock failure'})); }); }); + + describe('evaluate plugins config', function () { + beforeEach(() => { + PluginManager.register('colors', ColorsPlugin); + }); + + afterEach(() => { + PluginManager.unRegister('colors'); + }); + + it('should pass deep object as plugin config', () => { + const test = {a: {b: {c: 'd'}}}; + const config = { + plugins: { + colors: { + prop: test + } + }, + ui: {}, + provider: {} + }; + const player = new Player(config); + player.getMediaConfig().plugins.should.deep.equals(config.plugins); + }); + + it('should pass class as plugin config', () => { + const test = class Test { + constructor() {} + print() {} + }; + const config = { + plugins: { + colors: { + prop: test + } + }, + ui: {}, + provider: {} + }; + const player = new Player(config); + player.getMediaConfig().plugins.should.deep.equals(config.plugins); + }); + + it('should pass class instance as plugin config', done => { + const test = class Test { + constructor() {} + check() { + done(); + } + }; + const config = { + plugins: { + colors: { + prop: new test() + } + }, + ui: {}, + provider: {} + }; + const player = new Player(config); + player.getMediaConfig().plugins.should.deep.equals(config.plugins); + player.plugins.colors.config.prop.check(); + }); + + it('should pass function as plugin config', done => { + const test = () => { + done(); + }; + const config = { + plugins: { + colors: { + prop: test + } + }, + ui: {}, + provider: {} + }; + const player = new Player(config); + player.getMediaConfig().plugins.should.deep.equals(config.plugins); + player.plugins.colors.config.prop(); + }); + }); }); diff --git a/yarn.lock b/yarn.lock index f1f0e783b..a599d970e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1150,10 +1150,10 @@ react-redux "^7.2.0" redux "^4.0.5" -"@playkit-js/playkit-js@0.65.0-canary.9cbf0cf": - version "0.65.0-canary.9cbf0cf" - resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js/-/playkit-js-0.65.0-canary.9cbf0cf.tgz#949d21e195d46c004ec06e73c7ee5b0b0a2e8392" - integrity sha512-40wyqijY9dKZshimpn+usL5iVus7P40kNJpyZBwLEn3agjX+wtR85AAIGIRX+9SOcUWypDjPVlAYpF4OvYDGFg== +"@playkit-js/playkit-js@0.65.0-canary.6583361": + version "0.65.0-canary.6583361" + resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js/-/playkit-js-0.65.0-canary.6583361.tgz#64e174f8c62e073414ba0a422e11d78a17ca088c" + integrity sha512-9VPST8wdkLsmaaKHTDG7YDCjDc/CbU/TKyaXzV4swYXeQkwjBVi/4fIptJ9xm0aQSfAH+AbheT+A7Wf9e1e13Q== dependencies: js-logger "^1.6.0" ua-parser-js "^0.7.21"