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

fix(FEC-11037): multiple decorator exist after destroy plugin with decorator #544

Merged
merged 16 commits into from
Feb 28, 2021

Conversation

Yuvalke
Copy link
Contributor

@Yuvalke Yuvalke commented Feb 23, 2021

Description of the Changes

Issue: when the plugin has the decorator and the player destroyed the decorator reregister.
Solution: filter out the previous decorator provider and keep the new one only.

CheckLists

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • test are passing in local environment
  • Travis tests are passing (or test results are not worse than on master branch :))
  • Docs have been updated

Issue: when plugin has decorator and player destoryed the decorator reregister.
Solution: filter out the previous decorator provider and keep the new one only
@Yuvalke Yuvalke requested a review from a team February 23, 2021 12:40
@Yuvalke Yuvalke self-assigned this Feb 23, 2021
EngineDecorator._decoratorProviders.push(decoratorProvider);
}
EngineDecorator._decoratorProviders = EngineDecorator._decoratorProviders.filter(
currentDecoratorProvider => currentDecoratorProvider.constructor.name !== decoratorProvider.constructor.name
Copy link
Contributor

Choose a reason for hiding this comment

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

Why name and not id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're not maintaining id field

@OrenMe
Copy link
Contributor

OrenMe commented Feb 23, 2021

Hi @yuval, not sure I fully understand the issue description

@Yuvalke
Copy link
Contributor Author

Yuvalke commented Feb 23, 2021

@OrenMe every setup register decorator provider, after destroy we setup again so if plugin has decorator it will add new decorator provider for each destroy and step and create decorator for each provider, this change will keep the newest plugin instance - decorator provider and remove the older one

@OrenMe
Copy link
Contributor

OrenMe commented Feb 24, 2021 via email

@Yuvalke
Copy link
Contributor Author

Yuvalke commented Feb 24, 2021

@OrenMe static hash? name? I think this check is much better

@OrenMe
Copy link
Contributor

OrenMe commented Feb 24, 2021

I think the entire solution we have today is not ok - it was made when plugins were manager by the playkit lib and not relevant for kaltura player managed plugins.
We register the entire plugin instance in order to just get the decorator from the getEngineDecorator method.
Beside the fact we pass the entire plugin which might cause potential memory leaks, if we ever want to get the registered decorators it is impossible with current implementation.

@Yuvalke
Copy link
Contributor Author

Yuvalke commented Feb 24, 2021

@OrenMe I agree, but in our case, we have to fix multiple decorators after destroy.
I didn't understand why it was OK on playkit and doesn't on kaltura?

@OrenMe
Copy link
Contributor

OrenMe commented Feb 24, 2021

The comment about being ok or not was referring to passing plugin instance from Kaltura player to Playkit.
When playkit managed the plugin instance it made sense, now Kaltura player does it so it makes no sense to pass the entire plugin instance to it just in order for it to call the getDecorator method.

@Yuvalke Yuvalke changed the title fix: multiple decorator exist after destroy plugin with decorator fix(FEC-11037): multiple decorator exist after destroy plugin with decorator Feb 25, 2021
Copy link
Contributor

@OrenMe OrenMe left a comment

Choose a reason for hiding this comment

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

General note - most changes are around naming conventions or keeping existing names

src/engines/engine-decorator.js Outdated Show resolved Hide resolved
src/player.js Outdated
* @returns {void}
* @param {EngineDecoratorGenerator} decoratorGenerator - function to create the decorator
*/
addEngineDecorator(decoratorGenerator: EngineDecoratorGenerator): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
addEngineDecorator(decoratorGenerator: EngineDecoratorGenerator): void {
registerEngineDecoratorProvider(engineDecoratorProvider: EngineDecoratorProvider): void {

src/player.js Outdated
* @param {EngineDecoratorGenerator} decoratorGenerator - function to create the decorator
*/
addEngineDecorator(decoratorGenerator: EngineDecoratorGenerator): void {
if (!this._decoratorManager) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!this._decoratorManager) {
if (!this._engineDecoratorManager) {

class EngineDecoratorManager {
_decoratorGenerators: Array<EngineDecoratorGenerator> = [];

addDecorator(decoratorGenerator: EngineDecoratorGenerator): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
addDecorator(decoratorGenerator: EngineDecoratorGenerator): void {
register(name: string, engineDecoratorProvider: EngineDecoratorProvider): void {

_decoratorGenerators: Array<EngineDecoratorGenerator> = [];

addDecorator(decoratorGenerator: EngineDecoratorGenerator): void {
this._decoratorGenerators.push(decoratorGenerator);
Copy link
Contributor

Choose a reason for hiding this comment

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

add check to see if it is already provided, and with above addition of name it is easier then ever

import type {IEngine} from './engine';

declare interface IEngineDecoratorProvider {
getEngineDecorator(engine: IEngine, dispatchEventHandler: Function): IEngineDecorator;
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be part of the plugin interface, it is ok to remove it from here but need to make sure we define it for plugins in kaltura-player-js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure the change for kaltura player didn't upload yet

@Yuvalke Yuvalke requested a review from OrenMe February 28, 2021 08:31
* @class EngineDecoratorManager
*/
class EngineDecoratorManager {
_decoratorProviders: MultiMap<string, IEngineDecoratorProvider> = new MultiMap();
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be a simple map, multi map is were the value is array but we only have one decorator per plugin

src/player.js Outdated
@@ -390,6 +391,12 @@ export default class Player extends FakeEventTarget {
* @private
*/
_aspectRatio: ?string;
/**
* The engine manager.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* The engine manager.
* The engine decorator manager.

* @implements {IEngineDecorator}
*/
class EngineDecoratorProvider implements IEngineDecoratorProvider {
constructor(plugin: IEngineDecoratorProvider) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this means we are still passing the entire plugin to playkit. lets pass only the decorator provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're passing it but not keeping it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Provider will be getName and getEngineDecorator instead of the plugin itself

@Yuvalke Yuvalke merged commit ee11d45 into master Feb 28, 2021
@Yuvalke Yuvalke deleted the fix-multiple-decorator-after-destroy branch February 28, 2021 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants