@clockworkdog/cogs-client 2.11.1 → 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  // eslint-disable-next-line @typescript-eslint/triple-slash-reference
4
2
  /// <reference path="./types/howler.d.ts" />
5
- const howler_core_min_js_1 = require("howler/dist/howler.core.min.js");
3
+ import { Howl, Howler } from 'howler/dist/howler.core.min.js';
6
4
  const DEBUG = false;
7
5
  // Check an iOS-only property (See https://developer.mozilla.org/en-US/docs/Web/API/Navigator#non-standard_properties)
8
6
  const IS_IOS = typeof navigator.standalone !== 'undefined';
9
- class AudioPlayer {
7
+ export default class AudioPlayer {
10
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
9
  constructor(cogsConnection) {
12
10
  this.cogsConnection = cogsConnection;
@@ -27,7 +25,7 @@ class AudioPlayer {
27
25
  }
28
26
  if (message.audioOutput !== undefined) {
29
27
  const sinkId = cogsConnection.getAudioSinkId(message.audioOutput);
30
- this.setAudioSink(sinkId !== null && sinkId !== void 0 ? sinkId : '');
28
+ this.setAudioSink(sinkId ?? '');
31
29
  }
32
30
  this.updateConfig(message.files);
33
31
  break;
@@ -79,7 +77,7 @@ class AudioPlayer {
79
77
  }
80
78
  setGlobalVolume(volume) {
81
79
  this.globalVolume = volume;
82
- howler_core_min_js_1.Howler.volume(volume);
80
+ Howler.volume(volume);
83
81
  this.notifyStateListeners();
84
82
  }
85
83
  playAudioClip(path, { playId, volume, fade, loop }) {
@@ -142,8 +140,7 @@ class AudioPlayer {
142
140
  clipPlayer.player.once('stop', () => this.handleStoppedClip(path, playId, soundId), soundId);
143
141
  // Looping clips fire the 'end' callback on every loop
144
142
  clipPlayer.player.on('end', () => {
145
- var _a;
146
- if (!((_a = clipPlayer.activeClips[soundId]) === null || _a === void 0 ? void 0 : _a.loop)) {
143
+ if (!clipPlayer.activeClips[soundId]?.loop) {
147
144
  this.handleStoppedClip(path, playId, soundId);
148
145
  }
149
146
  }, soundId);
@@ -157,13 +154,12 @@ class AudioPlayer {
157
154
  // Once clip starts, check if it should actually be paused or stopped
158
155
  // If not, then update state to 'playing'
159
156
  clipPlayer.player.once('play', () => {
160
- var _a;
161
- const clipState = (_a = clipPlayer.activeClips[soundId]) === null || _a === void 0 ? void 0 : _a.state;
162
- if ((clipState === null || clipState === void 0 ? void 0 : clipState.type) === 'pause_requested') {
157
+ const clipState = clipPlayer.activeClips[soundId]?.state;
158
+ if (clipState?.type === 'pause_requested') {
163
159
  log('Clip started playing but should be paused', { path, soundId });
164
160
  this.pauseAudioClip(path, { fade: clipState.fade }, soundId, true);
165
161
  }
166
- else if ((clipState === null || clipState === void 0 ? void 0 : clipState.type) === 'stop_requested') {
162
+ else if (clipState?.type === 'stop_requested') {
167
163
  log('Clip started playing but should be stopped', { path, soundId });
168
164
  this.stopAudioClip(path, { fade: clipState.fade }, soundId, true);
169
165
  }
@@ -192,9 +188,8 @@ class AudioPlayer {
192
188
  this.notifyClipStateListeners(playId, path, 'playing');
193
189
  }
194
190
  pauseAudioClip(path, { fade }, onlySoundId, allowIfPauseRequested) {
195
- var _a, _b;
196
191
  // No active clips to pause
197
- if (Object.keys((_b = (_a = this.audioClipPlayers[path]) === null || _a === void 0 ? void 0 : _a.activeClips) !== null && _b !== void 0 ? _b : {}).length === 0) {
192
+ if (Object.keys(this.audioClipPlayers[path]?.activeClips ?? {}).length === 0) {
198
193
  return;
199
194
  }
200
195
  this.updateAudioClipPlayer(path, (clipPlayer) => {
@@ -235,10 +230,9 @@ class AudioPlayer {
235
230
  });
236
231
  }
237
232
  stopAudioClip(path, { fade }, onlySoundId, allowIfStopRequested) {
238
- var _a, _b, _c;
239
- log('Stop audio clip', { activeClips: (_a = this.audioClipPlayers[path]) === null || _a === void 0 ? void 0 : _a.activeClips });
233
+ log('Stop audio clip', { activeClips: this.audioClipPlayers[path]?.activeClips });
240
234
  // No active clips to stop
241
- if (Object.keys((_c = (_b = this.audioClipPlayers[path]) === null || _b === void 0 ? void 0 : _b.activeClips) !== null && _c !== void 0 ? _c : {}).length === 0) {
235
+ if (Object.keys(this.audioClipPlayers[path]?.activeClips ?? {}).length === 0) {
242
236
  return;
243
237
  }
244
238
  this.updateAudioClipPlayer(path, (clipPlayer) => {
@@ -290,13 +284,12 @@ class AudioPlayer {
290
284
  });
291
285
  }
292
286
  setAudioClipVolume(path, { volume, fade }) {
293
- var _a, _b;
294
287
  if (!(volume >= 0 && volume <= 1)) {
295
288
  console.warn('Invalid volume', volume);
296
289
  return;
297
290
  }
298
291
  // No active clips to set volume for
299
- if (Object.keys((_b = (_a = this.audioClipPlayers[path]) === null || _a === void 0 ? void 0 : _a.activeClips) !== null && _b !== void 0 ? _b : {}).length === 0) {
292
+ if (Object.keys(this.audioClipPlayers[path]?.activeClips ?? {}).length === 0) {
300
293
  return;
301
294
  }
302
295
  this.updateAudioClipPlayer(path, (clipPlayer) => {
@@ -332,13 +325,12 @@ class AudioPlayer {
332
325
  : clipPlayer);
333
326
  }
334
327
  updateAudioClipPlayer(path, update) {
335
- var _a;
336
328
  if (path in this.audioClipPlayers) {
337
329
  this.audioClipPlayers = { ...this.audioClipPlayers, [path]: update(this.audioClipPlayers[path]) };
338
330
  }
339
331
  // Once last instance of an ephemeral clip is removed, cleanup and remove the player
340
332
  const clipPlayer = this.audioClipPlayers[path];
341
- if (clipPlayer && Object.keys((_a = clipPlayer.activeClips) !== null && _a !== void 0 ? _a : {}).length === 0 && clipPlayer.config.ephemeral) {
333
+ if (clipPlayer && Object.keys(clipPlayer.activeClips ?? {}).length === 0 && clipPlayer.config.ephemeral) {
342
334
  clipPlayer.player.unload();
343
335
  delete this.audioClipPlayers[path];
344
336
  }
@@ -409,7 +401,7 @@ class AudioPlayer {
409
401
  this.eventTarget.dispatchEvent(new CustomEvent(type, { detail }));
410
402
  }
411
403
  createPlayer(path, config) {
412
- const player = new howler_core_min_js_1.Howl({
404
+ const player = new Howl({
413
405
  src: this.cogsConnection.getAssetUrl(path),
414
406
  autoplay: false,
415
407
  loop: false,
@@ -436,7 +428,6 @@ class AudioPlayer {
436
428
  return clip;
437
429
  }
438
430
  }
439
- exports.default = AudioPlayer;
440
431
  function log(...data) {
441
432
  if (DEBUG) {
442
433
  console.log(...data);
@@ -449,14 +440,12 @@ function isFadeValid(fade) {
449
440
  return !IS_IOS && typeof fade === 'number' && !isNaN(fade) && fade > 0;
450
441
  }
451
442
  function setPlayerSinkId(player, sinkId) {
452
- var _a;
453
443
  if (sinkId === undefined) {
454
444
  return;
455
445
  }
456
446
  if (player._html5) {
457
- (_a = player._sounds) === null || _a === void 0 ? void 0 : _a.forEach((sound) => {
458
- var _a, _b;
459
- (_b = (_a = sound._node) === null || _a === void 0 ? void 0 : _a.setSinkId) === null || _b === void 0 ? void 0 : _b.call(_a, sinkId);
447
+ player._sounds?.forEach((sound) => {
448
+ sound._node?.setSinkId?.(sinkId);
460
449
  });
461
450
  }
462
451
  else {
@@ -1,15 +1,9 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CogsShowPhaseChangedEvent = exports.CogsMediaConfigChangedEvent = exports.CogsIncomingEvent = exports.CogsStateChangedEvent = exports.CogsConfigChangedEvent = exports.CogsMessageEvent = exports.CogsConnectionCloseEvent = exports.CogsConnectionOpenEvent = void 0;
7
- const ShowPhase_1 = __importDefault(require("./types/ShowPhase"));
8
- const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
9
- const urls_1 = require("./utils/urls");
10
- const DataStore_1 = __importDefault(require("./DataStore"));
11
- const timesync_1 = require("@clockworkdog/timesync");
12
- class CogsConnection {
1
+ import ShowPhase from './types/ShowPhase';
2
+ import ReconnectingWebSocket from 'reconnecting-websocket';
3
+ import { COGS_SERVER_PORT, assetUrl } from './utils/urls';
4
+ import DataStore from './DataStore';
5
+ import { createTimeSyncClient } from '@clockworkdog/timesync';
6
+ export default class CogsConnection {
13
7
  get config() {
14
8
  return { ...this.currentConfig };
15
9
  }
@@ -29,19 +23,17 @@ class CogsConnection {
29
23
  * Return asset URLs using the information about the client and server support for HTTP/2
30
24
  */
31
25
  getAssetUrl(path) {
32
- var _a, _b;
33
- return `${(0, urls_1.assetUrl)(path)}?${(_b = (_a = this.urlParams) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}`;
26
+ return `${assetUrl(path)}?${this.urlParams?.toString() ?? ''}`;
34
27
  }
35
28
  get selectedAudioOutput() {
36
29
  return this._selectedAudioOutput;
37
30
  }
38
- constructor(manifest, { hostname = document.location.hostname, port = urls_1.COGS_SERVER_PORT } = {}, initialClientState, initialDataStoreData) {
39
- var _a;
31
+ constructor(manifest, { hostname = document.location.hostname, port = COGS_SERVER_PORT } = {}, initialClientState, initialDataStoreData) {
40
32
  this.manifest = manifest;
41
33
  this.eventTarget = new EventTarget();
42
34
  this.currentConfig = {}; // Received on open connection
43
35
  this.currentState = {}; // Received on open connection - TODO: set initial state from manifest?
44
- this._showPhase = ShowPhase_1.default.Setup;
36
+ this._showPhase = ShowPhase.Setup;
45
37
  this._timerState = null;
46
38
  this._mediaConfig = null;
47
39
  /**
@@ -50,7 +42,7 @@ class CogsConnection {
50
42
  this.audioOutputs = undefined;
51
43
  this._selectedAudioOutput = '';
52
44
  this.currentState = { ...initialClientState };
53
- this.store = new DataStore_1.default(initialDataStoreData !== null && initialDataStoreData !== void 0 ? initialDataStoreData : {});
45
+ this.store = new DataStore(initialDataStoreData ?? {});
54
46
  const { useReconnectingWebsocket, path, pathParams } = websocketParametersFromUrl(document.location.href);
55
47
  // Store the URL parameters for use in asset URLs
56
48
  // and add screen dimensions which COGS can use to determine the best asset quality to serve
@@ -62,25 +54,26 @@ class CogsConnection {
62
54
  this.urlParams.set('screenHeight', window.screen.height.toString());
63
55
  this.urlParams.set('screenPixelRatio', window.devicePixelRatio.toString());
64
56
  const socketUrl = `ws://${hostname}:${port}${path}?${this.urlParams}`;
65
- this.websocket = useReconnectingWebsocket ? new reconnecting_websocket_1.default(socketUrl) : new WebSocket(socketUrl);
57
+ this.websocket = useReconnectingWebsocket ? new ReconnectingWebSocket(socketUrl) : new WebSocket(socketUrl);
58
+ let timeSyncClient;
66
59
  this.websocket.onopen = () => {
67
60
  this.currentConfig = {}; // Received on open connection
68
61
  this.currentState = {}; // Received on open connection
69
62
  this.dispatchEvent(new CogsConnectionOpenEvent());
70
63
  this.setState(this.currentState); // TODO: Remove this because you should set it manually...??
64
+ timeSyncClient = createTimeSyncClient({
65
+ interval: 60000,
66
+ send: (data) => {
67
+ this.websocket.send(JSON.stringify(data));
68
+ },
69
+ });
71
70
  };
72
- const timeSyncClient = (0, timesync_1.createTimeSyncClient)({
73
- interval: 60000,
74
- send: (data) => {
75
- this.websocket.send(JSON.stringify(data));
76
- },
77
- });
78
71
  this.websocket.addEventListener('message', ({ data }) => {
79
72
  try {
80
73
  const response = JSON.parse(data);
81
74
  if (typeof response === 'object' && response !== null && 'timesync' in response) {
82
75
  const parsed = response;
83
- timeSyncClient.receive(parsed);
76
+ timeSyncClient?.receive(parsed);
84
77
  }
85
78
  }
86
79
  catch (e) {
@@ -88,7 +81,7 @@ class CogsConnection {
88
81
  }
89
82
  });
90
83
  this.websocket.onclose = () => {
91
- timeSyncClient.destroy();
84
+ timeSyncClient?.destroy();
92
85
  this.dispatchEvent(new CogsConnectionCloseEvent());
93
86
  };
94
87
  this.websocket.addEventListener('message', ({ data }) => {
@@ -163,7 +156,7 @@ class CogsConnection {
163
156
  }
164
157
  };
165
158
  this.eventTarget.addEventListener('open', refreshAudioOutputs);
166
- (_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.addEventListener('devicechange', refreshAudioOutputs);
159
+ navigator.mediaDevices?.addEventListener('devicechange', refreshAudioOutputs);
167
160
  refreshAudioOutputs();
168
161
  }
169
162
  }
@@ -190,8 +183,7 @@ class CogsConnection {
190
183
  }
191
184
  }
192
185
  getAudioSinkId(audioOutput) {
193
- var _a, _b;
194
- return audioOutput ? (_b = (_a = this.audioOutputs) === null || _a === void 0 ? void 0 : _a.find(({ label }) => label === audioOutput)) === null || _b === void 0 ? void 0 : _b.deviceId : '';
186
+ return audioOutput ? this.audioOutputs?.find(({ label }) => label === audioOutput)?.deviceId : '';
195
187
  }
196
188
  sendInitialMediaClipStates(allMediaClipStates) {
197
189
  if (this.isConnected) {
@@ -234,17 +226,15 @@ class CogsConnection {
234
226
  this.eventTarget.dispatchEvent(event);
235
227
  }
236
228
  }
237
- exports.default = CogsConnection;
238
229
  function websocketParametersFromUrl(url) {
239
- var _a, _b, _c, _d, _e;
240
230
  const parsedUrl = new URL(url);
241
231
  const pathParams = new URLSearchParams(parsedUrl.searchParams);
242
232
  const localClientId = pathParams.get('local_id');
243
233
  const isSimulator = pathParams.get('simulator') === 'true';
244
- const display = (_a = pathParams.get('display')) !== null && _a !== void 0 ? _a : '';
234
+ const display = pathParams.get('display') ?? '';
245
235
  const pluginId = parsedUrl.pathname.startsWith('/plugin/') ? decodeURIComponent(parsedUrl.pathname.split('/')[2]) : undefined;
246
236
  if (localClientId) {
247
- const type = (_b = pathParams.get('t')) !== null && _b !== void 0 ? _b : '';
237
+ const type = pathParams.get('t') ?? '';
248
238
  pathParams.delete('local_id');
249
239
  return {
250
240
  path: `/local/${encodeURIComponent(localClientId)}`,
@@ -253,7 +243,7 @@ function websocketParametersFromUrl(url) {
253
243
  };
254
244
  }
255
245
  else if (isSimulator) {
256
- const name = (_c = pathParams.get('name')) !== null && _c !== void 0 ? _c : '';
246
+ const name = pathParams.get('name') ?? '';
257
247
  pathParams.delete('simulator');
258
248
  pathParams.delete('name');
259
249
  return {
@@ -263,7 +253,7 @@ function websocketParametersFromUrl(url) {
263
253
  };
264
254
  }
265
255
  else if (display) {
266
- const displayIdIndex = (_d = pathParams.get('displayIdIndex')) !== null && _d !== void 0 ? _d : '';
256
+ const displayIdIndex = pathParams.get('displayIdIndex') ?? '';
267
257
  pathParams.delete('display');
268
258
  pathParams.delete('displayIdIndex');
269
259
  return {
@@ -277,7 +267,7 @@ function websocketParametersFromUrl(url) {
277
267
  };
278
268
  }
279
269
  else {
280
- const serial = (_e = pathParams.get('serial')) !== null && _e !== void 0 ? _e : '';
270
+ const serial = pathParams.get('serial') ?? '';
281
271
  pathParams.delete('serial');
282
272
  return {
283
273
  path: `/client/${encodeURIComponent(serial)}`,
@@ -285,45 +275,40 @@ function websocketParametersFromUrl(url) {
285
275
  };
286
276
  }
287
277
  }
288
- class CogsConnectionOpenEvent extends Event {
278
+ export class CogsConnectionOpenEvent extends Event {
289
279
  constructor() {
290
280
  super('open');
291
281
  this._cogsConnectionEventType = 'open';
292
282
  }
293
283
  }
294
- exports.CogsConnectionOpenEvent = CogsConnectionOpenEvent;
295
- class CogsConnectionCloseEvent extends Event {
284
+ export class CogsConnectionCloseEvent extends Event {
296
285
  constructor() {
297
286
  super('close');
298
287
  this._cogsConnectionEventType = 'close';
299
288
  }
300
289
  }
301
- exports.CogsConnectionCloseEvent = CogsConnectionCloseEvent;
302
- class CogsMessageEvent extends Event {
290
+ export class CogsMessageEvent extends Event {
303
291
  constructor(message) {
304
292
  super('message');
305
293
  this.message = message;
306
294
  this._cogsConnectionEventType = 'message';
307
295
  }
308
296
  }
309
- exports.CogsMessageEvent = CogsMessageEvent;
310
- class CogsConfigChangedEvent extends Event {
297
+ export class CogsConfigChangedEvent extends Event {
311
298
  constructor(config) {
312
299
  super('config');
313
300
  this.config = config;
314
301
  this._cogsConnectionEventType = 'config';
315
302
  }
316
303
  }
317
- exports.CogsConfigChangedEvent = CogsConfigChangedEvent;
318
- class CogsStateChangedEvent extends Event {
304
+ export class CogsStateChangedEvent extends Event {
319
305
  constructor(state) {
320
306
  super('state');
321
307
  this.state = state;
322
308
  this._cogsConnectionEventType = 'state';
323
309
  }
324
310
  }
325
- exports.CogsStateChangedEvent = CogsStateChangedEvent;
326
- class CogsIncomingEvent extends Event {
311
+ export class CogsIncomingEvent extends Event {
327
312
  constructor(name, value) {
328
313
  super('event');
329
314
  this.name = name;
@@ -331,20 +316,17 @@ class CogsIncomingEvent extends Event {
331
316
  this._cogsConnectionEventType = 'event';
332
317
  }
333
318
  }
334
- exports.CogsIncomingEvent = CogsIncomingEvent;
335
- class CogsMediaConfigChangedEvent extends Event {
319
+ export class CogsMediaConfigChangedEvent extends Event {
336
320
  constructor(mediaConfig) {
337
321
  super('mediaConfig');
338
322
  this.mediaConfig = mediaConfig;
339
323
  this._cogsConnectionEventType = 'mediaConfig';
340
324
  }
341
325
  }
342
- exports.CogsMediaConfigChangedEvent = CogsMediaConfigChangedEvent;
343
- class CogsShowPhaseChangedEvent extends Event {
326
+ export class CogsShowPhaseChangedEvent extends Event {
344
327
  constructor(showPhase) {
345
328
  super('showPhase');
346
329
  this.showPhase = showPhase;
347
330
  this._cogsConnectionEventType = 'showPhase';
348
331
  }
349
332
  }
350
- exports.CogsShowPhaseChangedEvent = CogsShowPhaseChangedEvent;
package/dist/DataStore.js CHANGED
@@ -1,12 +1,9 @@
1
- "use strict";
2
1
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
2
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
5
  };
7
6
  var _DataStore_eventTarget;
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.DataStoreItemsEvent = exports.DataStoreItemEvent = void 0;
10
7
  /**
11
8
  * A simple key-value store for storing data in COGS
12
9
  *
@@ -50,8 +47,8 @@ class DataStore {
50
47
  }
51
48
  }
52
49
  _DataStore_eventTarget = new WeakMap();
53
- exports.default = DataStore;
54
- class DataStoreItemEvent extends Event {
50
+ export default DataStore;
51
+ export class DataStoreItemEvent extends Event {
55
52
  constructor(key, value) {
56
53
  super('item');
57
54
  this.key = key;
@@ -59,12 +56,10 @@ class DataStoreItemEvent extends Event {
59
56
  this._cogsConnectionEventType = 'item';
60
57
  }
61
58
  }
62
- exports.DataStoreItemEvent = DataStoreItemEvent;
63
- class DataStoreItemsEvent extends Event {
59
+ export class DataStoreItemsEvent extends Event {
64
60
  constructor(items) {
65
61
  super('items');
66
62
  this.items = items;
67
63
  this._cogsConnectionEventType = 'item';
68
64
  }
69
65
  }
70
- exports.DataStoreItemsEvent = DataStoreItemsEvent;
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const VideoState_1 = require("./types/VideoState");
1
+ import { ActiveVideoClipState } from './types/VideoState';
4
2
  const DEFAULT_PARENT_ELEMENT = document.body;
5
- class VideoPlayer {
3
+ export default class VideoPlayer {
6
4
  constructor(
7
5
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
6
  cogsConnection, parentElement = DEFAULT_PARENT_ELEMENT) {
@@ -23,7 +21,7 @@ class VideoPlayer {
23
21
  this.setGlobalVolume(message.globalVolume);
24
22
  if (message.audioOutput !== undefined) {
25
23
  const sinkId = cogsConnection.getAudioSinkId(message.audioOutput);
26
- this.setAudioSink(sinkId !== null && sinkId !== void 0 ? sinkId : '');
24
+ this.setAudioSink(sinkId ?? '');
27
25
  }
28
26
  this.updateConfig(message.files);
29
27
  break;
@@ -82,7 +80,6 @@ class VideoPlayer {
82
80
  this.notifyStateListeners();
83
81
  }
84
82
  playVideoClip(path, { playId, volume, loop, fit }) {
85
- var _a;
86
83
  if (!this.videoClipPlayers[path]) {
87
84
  this.videoClipPlayers[path] = this.createClipPlayer(path, { preload: 'none', ephemeral: true, fit });
88
85
  }
@@ -94,7 +91,7 @@ class VideoPlayer {
94
91
  });
95
92
  }
96
93
  // New pending clip is video being requested
97
- if (((_a = this.activeClip) === null || _a === void 0 ? void 0 : _a.path) !== path) {
94
+ if (this.activeClip?.path !== path) {
98
95
  this.pendingClip = { path, playId, actionOncePlaying: 'play' };
99
96
  }
100
97
  // Setup and play the pending clip's player
@@ -123,8 +120,7 @@ class VideoPlayer {
123
120
  if (this.activeClip) {
124
121
  const { playId, path } = this.activeClip;
125
122
  this.updateVideoClipPlayer(path, (clipPlayer) => {
126
- var _a;
127
- (_a = clipPlayer.videoElement) === null || _a === void 0 ? void 0 : _a.pause();
123
+ clipPlayer.videoElement?.pause();
128
124
  return clipPlayer;
129
125
  });
130
126
  this.notifyClipStateListeners(playId, path, 'paused');
@@ -141,9 +137,8 @@ class VideoPlayer {
141
137
  }
142
138
  }
143
139
  setVideoClipVolume({ volume }) {
144
- var _a, _b;
145
140
  // If there is a pending clip, this is latest to have been played so update its volume
146
- const clipToUpdate = (_b = (_a = this.pendingClip) !== null && _a !== void 0 ? _a : this.activeClip) !== null && _b !== void 0 ? _b : undefined;
141
+ const clipToUpdate = this.pendingClip ?? this.activeClip ?? undefined;
147
142
  if (!clipToUpdate) {
148
143
  return;
149
144
  }
@@ -160,9 +155,8 @@ class VideoPlayer {
160
155
  });
161
156
  }
162
157
  setVideoClipFit({ fit }) {
163
- var _a, _b;
164
158
  // If there is a pending clip, this is latest to have been played so update its fit
165
- const clipToUpdate = (_b = (_a = this.pendingClip) !== null && _a !== void 0 ? _a : this.activeClip) !== null && _b !== void 0 ? _b : undefined;
159
+ const clipToUpdate = this.pendingClip ?? this.activeClip ?? undefined;
166
160
  if (!clipToUpdate) {
167
161
  return;
168
162
  }
@@ -174,13 +168,12 @@ class VideoPlayer {
174
168
  });
175
169
  }
176
170
  handleStoppedClip(path) {
177
- var _a;
178
171
  if (!this.activeClip || this.activeClip.path !== path) {
179
172
  return;
180
173
  }
181
174
  const playId = this.activeClip.playId;
182
175
  // Once an ephemeral clip stops, cleanup and remove the player
183
- if ((_a = this.videoClipPlayers[this.activeClip.path]) === null || _a === void 0 ? void 0 : _a.config.ephemeral) {
176
+ if (this.videoClipPlayers[this.activeClip.path]?.config.ephemeral) {
184
177
  this.unloadClip(path);
185
178
  }
186
179
  this.activeClip = undefined;
@@ -217,8 +210,7 @@ class VideoPlayer {
217
210
  const clipPlayers = { ...previousClipPlayers };
218
211
  const removedClips = Object.keys(previousClipPlayers).filter((previousPath) => !(previousPath in newVideoPaths));
219
212
  removedClips.forEach((path) => {
220
- var _a, _b;
221
- if (((_a = this.activeClip) === null || _a === void 0 ? void 0 : _a.path) === path && ((_b = previousClipPlayers[path]) === null || _b === void 0 ? void 0 : _b.config.ephemeral) === false) {
213
+ if (this.activeClip?.path === path && previousClipPlayers[path]?.config.ephemeral === false) {
222
214
  this.updateVideoClipPlayer(path, (player) => {
223
215
  player.config = { ...player.config, ephemeral: true };
224
216
  return player;
@@ -252,19 +244,18 @@ class VideoPlayer {
252
244
  this.notifyStateListeners();
253
245
  }
254
246
  notifyStateListeners() {
255
- var _a, _b, _c, _d, _e, _f, _g;
256
247
  const VideoState = {
257
248
  globalVolume: this.globalVolume,
258
- isPlaying: this.activeClip ? !((_a = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _a === void 0 ? void 0 : _a.paused) : false,
249
+ isPlaying: this.activeClip ? !this.videoClipPlayers[this.activeClip.path].videoElement?.paused : false,
259
250
  clips: { ...this.videoClipPlayers },
260
251
  activeClip: this.activeClip
261
252
  ? {
262
253
  path: this.activeClip.path,
263
- state: !((_b = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _b === void 0 ? void 0 : _b.paused) ? VideoState_1.ActiveVideoClipState.Playing : VideoState_1.ActiveVideoClipState.Paused,
264
- loop: (_d = (_c = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _c === void 0 ? void 0 : _c.loop) !== null && _d !== void 0 ? _d : false,
265
- volume: ((_e = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _e === void 0 ? void 0 : _e.muted)
254
+ state: !this.videoClipPlayers[this.activeClip.path].videoElement?.paused ? ActiveVideoClipState.Playing : ActiveVideoClipState.Paused,
255
+ loop: this.videoClipPlayers[this.activeClip.path].videoElement?.loop ?? false,
256
+ volume: this.videoClipPlayers[this.activeClip.path].videoElement?.muted
266
257
  ? 0
267
- : ((_g = (_f = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _f === void 0 ? void 0 : _f.volume) !== null && _g !== void 0 ? _g : 0),
258
+ : (this.videoClipPlayers[this.activeClip.path].videoElement?.volume ?? 0),
268
259
  }
269
260
  : undefined,
270
261
  };
@@ -292,9 +283,8 @@ class VideoPlayer {
292
283
  setVideoElementVolume(videoElement, volume * this.globalVolume);
293
284
  videoElement.preload = config.preload;
294
285
  videoElement.addEventListener('playing', () => {
295
- var _a, _b;
296
286
  // If the clip is still the pending one when it actually start playing, then ensure it is in the correct state
297
- if (((_a = this.pendingClip) === null || _a === void 0 ? void 0 : _a.path) === path) {
287
+ if (this.pendingClip?.path === path) {
298
288
  switch (this.pendingClip.actionOncePlaying) {
299
289
  case 'play': {
300
290
  // Continue playing, show the video element, and notify listeners
@@ -323,7 +313,7 @@ class VideoPlayer {
323
313
  this.activeClip = this.pendingClip;
324
314
  this.pendingClip = undefined;
325
315
  }
326
- else if (((_b = this.activeClip) === null || _b === void 0 ? void 0 : _b.path) === path) {
316
+ else if (this.activeClip?.path === path) {
327
317
  // If we were the active clip then just notify listeners that we are now playing
328
318
  this.notifyClipStateListeners(this.activeClip.playId, path, 'playing');
329
319
  }
@@ -361,17 +351,15 @@ class VideoPlayer {
361
351
  return player;
362
352
  }
363
353
  unloadClip(path) {
364
- var _a, _b;
365
- if (((_a = this.activeClip) === null || _a === void 0 ? void 0 : _a.path) === path) {
354
+ if (this.activeClip?.path === path) {
366
355
  const playId = this.activeClip.playId;
367
356
  this.activeClip = undefined;
368
357
  this.notifyClipStateListeners(playId, path, 'stopped');
369
358
  }
370
- (_b = this.videoClipPlayers[path]) === null || _b === void 0 ? void 0 : _b.videoElement.remove();
359
+ this.videoClipPlayers[path]?.videoElement.remove();
371
360
  this.updateVideoClipPlayer(path, () => null);
372
361
  }
373
362
  }
374
- exports.default = VideoPlayer;
375
363
  function preloadString(preload) {
376
364
  return typeof preload === 'string' ? preload : preload ? 'auto' : 'none';
377
365
  }