Skip to content

Commit

Permalink
fix(FEC-10324): class instances merged like simple object (#368)
Browse files Browse the repository at this point in the history
Issue: config with instance object merged like object.
Solution: check if it's an instance of class and merge it.
  • Loading branch information
Yuvalke authored Nov 25, 2020
1 parent 704dde3 commit 4968c5f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions src/common/plugins/plugins-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

/**
Expand All @@ -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));
Expand Down
82 changes: 82 additions & 0 deletions test/src/kaltura-player.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4968c5f

Please sign in to comment.