Skip to content

Commit

Permalink
fix(web): have setupPlayer throw an exception on duplicate calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jspizziri committed Nov 6, 2023
1 parent f11da24 commit 522a3e8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions web/TrackPlayer/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Track, Progress, PlaybackState } from '../../src/interfaces';
import { SetupNotCalledError } from './SetupNotCalledError';

export class Player {
protected hasInitialized: boolean = false;
protected element?: HTMLMediaElement;
protected player?: shaka.Player;
protected _current?: Track = undefined;
Expand Down Expand Up @@ -36,6 +37,10 @@ export class Player {
async setupPlayer() {
// shaka only runs in a browser
if (typeof window === 'undefined') return;
if (this.hasInitialized === true) {
// TODO: double check the structure of this error message
throw { code: 'player_already_initialized', message: 'The player is not initialized. Call setupPlayer first.' };
}

// @ts-ignore
const shaka = await import('shaka-player/dist/shaka-player.ui');
Expand Down Expand Up @@ -78,6 +83,7 @@ export class Player {
// Attach player to the window to make it easy to access in the JS console.
// @ts-ignore
window.rntp = this.player;
this.hasInitialized = true;
}

/**
Expand Down

0 comments on commit 522a3e8

Please sign in to comment.