Skip to content

Commit

Permalink
feat: handle onPresetChange in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
lianbenjamin committed Oct 17, 2023
1 parent 352afc7 commit 658556a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flow-typed/interfaces/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ declare interface IPlugin {
updateConfig(update: Object): void;
loadMedia(): void;
destroy(): void;
reset(): void;
reset(): void
onPresetChange(oldPreset: string, newPreset: string): void;
}
9 changes: 9 additions & 0 deletions src/common/plugins/base-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ export class BasePlugin implements IPlugin {
*/
loadMedia(): void {}

/**
* Runs the onPresetChange logic of the plugin.
* plugin must implement this method.
* @public
* @virtual
* @returns {void}
*/
onPresetChange(): void {}

/**
* Runs the destroy logic of the plugin.
* plugin must implement this method.
Expand Down
11 changes: 11 additions & 0 deletions src/common/plugins/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ export class PluginManager {
Object.keys(this._plugins).forEach(k => this._plugins[k].loadMedia());
}

/**
* Iterates over all the plugins and calls onPresetChange().
* @param {string} oldPreset - The old preset
* @param {string} newPreset - The new preset
* @public
* @returns {void}
*/
onPresetChange(oldPreset: string, newPreset: string): void {
Object.keys(this._plugins).forEach(k => this._plugins[k].onPresetChange(oldPreset, newPreset));
}

/**
* Iterates over all the plugins and calls destroy().
* @public
Expand Down
6 changes: 6 additions & 0 deletions src/kaltura-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,12 @@ class KalturaPlayer extends FakeEventTarget {
this._reset = false;
}
});
this._eventManager.listen(this, UIEventType.UI_PRESET_CHANGE, (event: FakeEvent) => this._onPresetChange(event));
}

_onPresetChange(event: FakeEvent): void {
const {from, to} = event.payload;
this._pluginManager.onPresetChange(from, to);
}

_onChangeSourceEnded(): void {
Expand Down

0 comments on commit 658556a

Please sign in to comment.