Skip to content

Commit

Permalink
fix(FEC-7501): cleanup on destroy doesn't completely remove player (#131
Browse files Browse the repository at this point in the history
)

handle destroy of both ui and player.
  • Loading branch information
Dan Ziv authored Jul 31, 2018
1 parent 8777430 commit 8be89ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/common/ui-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class UIWrapper {
}
}

destroy(): void {
if (this._disabled) return;
this._uiManager.destroy();
}

setConfig(config: Object, componentAlias?: string): void {
if (this._disabled) return;
this._uiManager.setConfig(config, componentAlias);
Expand Down
15 changes: 14 additions & 1 deletion src/kaltura-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ import {UIWrapper} from './common/ui-wrapper';
export default class KalturaPlayer {
_player: Player;
_playerConfigure: Function;
_playerDestroy: Function;
_provider: Provider;
_uiWrapper: UIWrapper;
_logger: any;

constructor(options: KalturaPlayerOptionsObject) {
this._player = loadPlayer(options);
this._playerConfigure = this._player.configure.bind(this._player);
this._playerDestroy = this._player.destroy.bind(this._player);
this._logger = getLogger('KalturaPlayer' + Utils.Generator.uniqueId(5));
this._uiWrapper = new UIWrapper(this._player, options);
this._provider = new Provider(options.provider, __VERSION__);
Object.assign(this._player, {
loadMedia: mediaInfo => this.loadMedia(mediaInfo),
setMedia: mediaConfig => this.setMedia(mediaConfig),
configure: config => this.configure(config),
setMedia: mediaConfig => this.setMedia(mediaConfig)
destroy: () => this.destroy()
});
Object.defineProperty(this._player, 'Event', this.Event);
return this._player;
Expand Down Expand Up @@ -71,6 +74,16 @@ export default class KalturaPlayer {
this._player.configure(playerConfig);
}

destroy(): void {
const targetId = this._player.config.ui.targetId;
this._playerDestroy();
this._uiWrapper.destroy();
const targetContainer = document.getElementById(targetId);
if (targetContainer && targetContainer.parentNode) {
Utils.Dom.removeChild(targetContainer.parentNode, targetContainer);
}
}

get Event(): Object {
return {
get: () => ({
Expand Down

0 comments on commit 8be89ca

Please sign in to comment.