@clockworkdog/cogs-client 2.5.0 → 2.8.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.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # COGS Client library
1
+ # COGS SDK - Javascript
2
2
 
3
3
  Create content for your COGS Media Master
4
4
 
5
- ## [Documentation](https://clockwork-dog.github.io/cogs-client-lib/)
5
+ ## [Documentation](https://clockwork-dog.github.io/cogs-sdk/javascript/)
6
6
 
7
7
  ## Add to your project
8
8
 
@@ -32,7 +32,7 @@ yarn add @clockworkdog/cogs-client
32
32
 
33
33
  ### Create a `cogs-plugin-manifest.js` file
34
34
 
35
- See [PluginManifestJson](https://clockwork-dog.github.io/cogs-client-lib/interfaces/PluginManifestJson.html) for details of what to include.
35
+ See [CogsPluginManifestJson](https://clockwork-dog.github.io/cogs-sdk/javascript/interfaces/CogsPluginManifestJson.html) for details of what to include.
36
36
 
37
37
  If using Typescript set `"allowJs": true` in your `tsconfig.json`.
38
38
 
@@ -107,7 +107,7 @@ import { CogsConnection, CogsAudioPlayer } from '@clockworkdog/cogs-client';
107
107
 
108
108
  ### Connect to COGS
109
109
 
110
- Initialize a [CogsConnection](https://clockwork-dog.github.io/cogs-client-lib/interfaces/CogsConnection.html) with the manifest you created above.
110
+ Initialize a [CogsConnection](https://clockwork-dog.github.io/cogs-sdk/javascript/classes/CogsConnection.html) with the manifest you created above.
111
111
 
112
112
  ```ts
113
113
  let connected = false;
@@ -152,14 +152,14 @@ You can save arbitrary data to COGS which will be restored when reconnecting wit
152
152
  ```ts
153
153
  const cogsConnection = new CogsConnection(manifest, {
154
154
  // Initial items in the store
155
- 'my-key': { foo: 0, bar: '' }
155
+ 'my-key': { foo: 0, bar: '' },
156
156
  });
157
157
 
158
158
  // Update the store
159
159
  cogsConnection.store.setItems({ 'my-key': { foo: 1, bar: 'two' } });
160
160
 
161
161
  // Get item from data store
162
- cogsConnection.store.items.getItem('my-key')
162
+ cogsConnection.store.items.getItem('my-key');
163
163
 
164
164
  // Listen for data changes
165
165
  cogsConnection.store.addEventListener('item', ({ key, value }) => {
@@ -182,7 +182,7 @@ Add `audio` to `cogs-plugin-manifest.js`:
182
182
  }
183
183
  ```
184
184
 
185
- Add [CogsAudioPlayer](https://clockwork-dog.github.io/cogs-client-lib/classes/CogsAudioPlayer.html) to your page:
185
+ Add [CogsAudioPlayer](https://clockwork-dog.github.io/cogs-sdk/javascript/classes/CogsAudioPlayer.html) to your page:
186
186
 
187
187
  ```ts
188
188
  const audioPlayer = new CogsAudioPlayer(cogsConnection);
@@ -5,6 +5,7 @@ const DEBUG = false;
5
5
  // Check an iOS-only property (See https://developer.mozilla.org/en-US/docs/Web/API/Navigator#non-standard_properties)
6
6
  const IS_IOS = typeof navigator.standalone !== 'undefined';
7
7
  class AudioPlayer {
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
9
  constructor(cogsConnection) {
9
10
  this.cogsConnection = cogsConnection;
10
11
  this.eventTarget = new EventTarget();
@@ -467,6 +468,7 @@ function setPlayerSinkId(player, sinkId) {
467
468
  * This doesn't work on iOS (volume is read-only) so at least mute it if the volume is zero
468
469
  */
469
470
  function setAudioPlayerVolume(howl, volume, soundId) {
471
+ log('Setting volume', volume, soundId);
470
472
  howl.volume(volume, soundId);
471
473
  howl.mute(volume === 0, soundId);
472
474
  }
@@ -1,5 +1,5 @@
1
1
  import ShowPhase from './types/ShowPhase';
2
- import CogsClientMessage from './types/CogsClientMessage';
2
+ import CogsClientMessage, { MediaClientConfig } from './types/CogsClientMessage';
3
3
  import MediaClipStateMessage from './types/MediaClipStateMessage';
4
4
  import AllMediaClipStatesMessage from './types/AllMediaClipStatesMessage';
5
5
  import { CogsPluginManifest, PluginManifestEventJson } from './types/CogsPluginManifest';
@@ -20,6 +20,8 @@ export default class CogsConnection<Manifest extends CogsPluginManifest, DataT e
20
20
  get showPhase(): ShowPhase;
21
21
  private _timerState;
22
22
  get timerState(): TimerState | null;
23
+ private _mediaConfig;
24
+ get mediaConfig(): MediaClientConfig | null;
23
25
  /**
24
26
  * Return asset URLs using the information about the client and server support for HTTP/2
25
27
  */
@@ -103,8 +105,18 @@ export declare class CogsIncomingEvent<CogsEvent extends DeepReadonly<PluginMani
103
105
  readonly _cogsConnectionEventType = "event";
104
106
  constructor(name: CogsEvent['name'], value: ManifestTypes.TypeFromCogsValueType<CogsEvent['value']>);
105
107
  }
108
+ export declare class CogsMediaConfigChangedEvent extends Event {
109
+ readonly mediaConfig: MediaClientConfig;
110
+ readonly _cogsConnectionEventType = "mediaConfig";
111
+ constructor(mediaConfig: MediaClientConfig);
112
+ }
113
+ export declare class CogsShowPhaseChangedEvent extends Event {
114
+ readonly showPhase: ShowPhase;
115
+ readonly _cogsConnectionEventType = "showPhase";
116
+ constructor(showPhase: ShowPhase);
117
+ }
106
118
  /**
107
119
  * Allows CogsIncomingEvent of each supported value type
108
120
  */
109
121
  export type CogsIncomingEventTypes<CogsEvent extends DeepReadonly<PluginManifestEventJson> | PluginManifestEventJson> = CogsEvent extends unknown ? CogsIncomingEvent<CogsEvent> : never;
110
- export type CogsConnectionEvent<Manifest extends CogsPluginManifest> = CogsConnectionOpenEvent | CogsConnectionCloseEvent | CogsMessageEvent | CogsConfigChangedEvent<ManifestTypes.ConfigAsObject<Manifest>> | CogsStateChangedEvent<Partial<ManifestTypes.StateAsObject<Manifest>>> | CogsIncomingEventTypes<ManifestTypes.EventFromCogs<Manifest>>;
122
+ export type CogsConnectionEvent<Manifest extends CogsPluginManifest> = CogsConnectionOpenEvent | CogsConnectionCloseEvent | CogsMessageEvent | CogsConfigChangedEvent<ManifestTypes.ConfigAsObject<Manifest>> | CogsStateChangedEvent<Partial<ManifestTypes.StateAsObject<Manifest>>> | CogsIncomingEventTypes<ManifestTypes.EventFromCogs<Manifest>> | CogsMediaConfigChangedEvent | CogsShowPhaseChangedEvent;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CogsIncomingEvent = exports.CogsStateChangedEvent = exports.CogsConfigChangedEvent = exports.CogsMessageEvent = exports.CogsConnectionCloseEvent = exports.CogsConnectionOpenEvent = void 0;
6
+ exports.CogsShowPhaseChangedEvent = exports.CogsMediaConfigChangedEvent = exports.CogsIncomingEvent = exports.CogsStateChangedEvent = exports.CogsConfigChangedEvent = exports.CogsMessageEvent = exports.CogsConnectionCloseEvent = exports.CogsConnectionOpenEvent = void 0;
7
7
  const ShowPhase_1 = __importDefault(require("./types/ShowPhase"));
8
8
  const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
9
9
  const urls_1 = require("./helpers/urls");
@@ -21,6 +21,9 @@ class CogsConnection {
21
21
  get timerState() {
22
22
  return this._timerState ? { ...this._timerState } : null;
23
23
  }
24
+ get mediaConfig() {
25
+ return this._mediaConfig ? { ...this._mediaConfig } : null;
26
+ }
24
27
  /**
25
28
  * Return asset URLs using the information about the client and server support for HTTP/2
26
29
  */
@@ -39,6 +42,7 @@ class CogsConnection {
39
42
  this.currentState = {}; // Received on open connection - TODO: set initial state from manifest?
40
43
  this._showPhase = ShowPhase_1.default.Setup;
41
44
  this._timerState = null;
45
+ this._mediaConfig = null;
42
46
  /**
43
47
  * Cached audio outputs use to look up the device/sink ID when a different device label is requested
44
48
  */
@@ -94,8 +98,10 @@ class CogsConnection {
94
98
  break;
95
99
  case 'show_phase':
96
100
  this._showPhase = message.phase;
101
+ this.dispatchEvent(new CogsShowPhaseChangedEvent(message.phase));
97
102
  break;
98
103
  case 'media_config_update':
104
+ this._mediaConfig = message;
99
105
  for (const optionName of ['preferOptimizedAudio', 'preferOptimizedVideo', 'preferOptimizedImages']) {
100
106
  const optionEnabled = message[optionName];
101
107
  if (optionEnabled) {
@@ -105,6 +111,7 @@ class CogsConnection {
105
111
  this.urlParams.delete(optionName);
106
112
  }
107
113
  }
114
+ this.dispatchEvent(new CogsMediaConfigChangedEvent(message));
108
115
  break;
109
116
  case 'data_store_items':
110
117
  this.store.handleDataStoreItemsMessage(message);
@@ -305,3 +312,19 @@ class CogsIncomingEvent extends Event {
305
312
  }
306
313
  }
307
314
  exports.CogsIncomingEvent = CogsIncomingEvent;
315
+ class CogsMediaConfigChangedEvent extends Event {
316
+ constructor(mediaConfig) {
317
+ super('mediaConfig');
318
+ this.mediaConfig = mediaConfig;
319
+ this._cogsConnectionEventType = 'mediaConfig';
320
+ }
321
+ }
322
+ exports.CogsMediaConfigChangedEvent = CogsMediaConfigChangedEvent;
323
+ class CogsShowPhaseChangedEvent extends Event {
324
+ constructor(showPhase) {
325
+ super('showPhase');
326
+ this.showPhase = showPhase;
327
+ this._cogsConnectionEventType = 'showPhase';
328
+ }
329
+ }
330
+ exports.CogsShowPhaseChangedEvent = CogsShowPhaseChangedEvent;
@@ -1,7 +1,7 @@
1
+ import { MediaObjectFit } from '.';
1
2
  import CogsConnection from './CogsConnection';
2
- import { VideoState } from './types/VideoState';
3
3
  import MediaClipStateMessage from './types/MediaClipStateMessage';
4
- import { MediaObjectFit } from '.';
4
+ import { VideoState } from './types/VideoState';
5
5
  type EventTypes = {
6
6
  state: VideoState;
7
7
  videoClipState: MediaClipStateMessage;
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const VideoState_1 = require("./types/VideoState");
4
4
  const DEFAULT_PARENT_ELEMENT = document.body;
5
5
  class VideoPlayer {
6
- constructor(cogsConnection, parentElement = DEFAULT_PARENT_ELEMENT) {
6
+ constructor(
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ cogsConnection, parentElement = DEFAULT_PARENT_ELEMENT) {
7
9
  this.cogsConnection = cogsConnection;
8
10
  this.eventTarget = new EventTarget();
9
11
  this.globalVolume = 1;
@@ -262,7 +264,7 @@ class VideoPlayer {
262
264
  loop: (_d = (_c = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _c === void 0 ? void 0 : _c.loop) !== null && _d !== void 0 ? _d : false,
263
265
  volume: ((_e = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _e === void 0 ? void 0 : _e.muted)
264
266
  ? 0
265
- : (_g = (_f = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _f === void 0 ? void 0 : _f.volume) !== null && _g !== void 0 ? _g : 0,
267
+ : ((_g = (_f = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _f === void 0 ? void 0 : _f.volume) !== null && _g !== void 0 ? _g : 0),
266
268
  }
267
269
  : undefined,
268
270
  };