Skip to content

Commit

Permalink
fix(esl-media): fix play preconditions for toggle method (#2906)
Browse files Browse the repository at this point in the history
Add the ability to pass `allowActivate` to the `ESLMedia.prototype.toggle`.
Remove `toggle` from provider API (only `play`/`pause`/`stop` are supported on the low level)
  • Loading branch information
NastaLeo authored Feb 4, 2025
1 parent c20268e commit 1f7b8dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
20 changes: 0 additions & 20 deletions src/modules/esl-media/core/esl-media-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@ export abstract class BaseProvider {
this._el?.style.setProperty('aspect-ratio', aspectRatio > 0 ? `${aspectRatio}` : null);
}

/**
* Executes toggle action:
* If the player is PAUSED then it starts playing otherwise it pause playing
*/
protected toggle(): void | Promise<any> {
if ([PlayerStates.PAUSED, PlayerStates.UNSTARTED, PlayerStates.VIDEO_CUED].includes(this.state)) {
return this.play();
} else {
return this.pause();
}
}

/** Executes onConfigChange action when api is ready */
public onSafeConfigChange(param: ProviderObservedParams, value: boolean): void {
this.ready.then(() => this.onConfigChange(param, value));
Expand Down Expand Up @@ -166,14 +154,6 @@ export abstract class BaseProvider {
return this.ready.then(() => this.stop());
}

/**
* Executes toggle when api is ready
* @returns Promise
*/
public safeToggle(): Promise<void> {
return this.ready.then(() => this.toggle());
}

/**
* Register current provider.
* Can be used as a decorator.
Expand Down
10 changes: 7 additions & 3 deletions src/modules/esl-media/core/esl-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,13 @@ export class ESLMedia extends ESLBaseElement {
return this._provider && this._provider.safeStop();
}

/** Toggle play/pause state of the media */
public toggle(): Promise<void> | null {
return this._provider && this._provider.safeToggle();
/**
* Executes toggle action:
* If the player is PAUSED then it starts playing otherwise it pause playing
*/
public toggle(allowActivate: boolean = false): Promise<void> | null {
const shouldActivate = [PlayerStates.PAUSED, PlayerStates.UNSTARTED, PlayerStates.VIDEO_CUED, PlayerStates.UNINITIALIZED].includes(this.state);
return shouldActivate ? this.play(allowActivate) : this.pause();
}

/** Focus inner player **/
Expand Down

0 comments on commit 1f7b8dc

Please sign in to comment.