@clockworkdog/cogs-client 1.5.2 → 1.5.5

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
@@ -20,14 +20,6 @@ Include the script in your HTML page:
20
20
 
21
21
  ### NPM / Yarn
22
22
 
23
- If you haven't yet created a web project we recommend using Vite with Typescript:
24
-
25
- ```shell
26
- yarn create vite my-custom-content --template vanilla-ts
27
- cd my-custom-content
28
- yarn
29
- ```
30
-
31
23
  Then add `cogs-client` with NPM or Yarn:
32
24
 
33
25
  ```shell
@@ -38,6 +30,10 @@ yarn add @clockworkdog/cogs-client
38
30
 
39
31
  ## Usage
40
32
 
33
+ ### Create a `cogs-plugin-manifest.json` file
34
+
35
+ See [PluginManifestJson](https://clockwork-dog.github.io/cogs-client-lib/interfaces/PluginManifestJson.html) for details of what to include.
36
+
41
37
  ### Import the library
42
38
 
43
39
  #### Browser
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const howler_1 = require("howler");
4
4
  const urls_1 = require("./helpers/urls");
5
- const DEBUG = true;
5
+ const DEBUG = false;
6
6
  // Check an iOS-only property (See https://developer.mozilla.org/en-US/docs/Web/API/Navigator#non-standard_properties)
7
7
  const IS_IOS = typeof navigator.standalone !== 'undefined';
8
8
  class AudioPlayer {
@@ -89,7 +89,10 @@ class AudioPlayer {
89
89
  this.updateAudioClipPlayer(path, (clipPlayer) => {
90
90
  // Paused clips need to be played again
91
91
  const pausedSoundIds = Object.entries(clipPlayer.activeClips)
92
- .filter(([, { state }]) => state.type === 'paused' || state.type === 'pausing')
92
+ .filter(([, { state }]) => state.type === 'paused')
93
+ .map(([id]) => parseInt(id));
94
+ const pausingSoundIds = Object.entries(clipPlayer.activeClips)
95
+ .filter(([, { state }]) => state.type === 'pausing')
93
96
  .map(([id]) => parseInt(id));
94
97
  pausedSoundIds.forEach((soundId) => {
95
98
  log('Resuming paused clip', { soundId });
@@ -100,7 +103,25 @@ class AudioPlayer {
100
103
  .filter(([, { state }]) => state.type === 'pause_requested')
101
104
  .map(([id]) => parseInt(id));
102
105
  // If no currently paused/pausing/pause_requested clips, play a new clip
103
- const newSoundIds = pausedSoundIds.length > 0 || pauseRequestedSoundIds.length > 0 ? [] : [clipPlayer.player.play()];
106
+ const newSoundIds = pausedSoundIds.length > 0 || pausingSoundIds.length > 0 || pauseRequestedSoundIds.length > 0 ? [] : [clipPlayer.player.play()];
107
+ // Pausing clips are technically currently playing as far as Howler is concerned
108
+ pausingSoundIds.forEach((soundId) => {
109
+ log('Stopping fade and resuming pausing clip', { soundId });
110
+ // Stop the fade callback
111
+ clipPlayer.player.off('fade', undefined, soundId);
112
+ // Set loop property
113
+ clipPlayer.player.loop(loop, soundId);
114
+ // Update state to 'playing'
115
+ this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'playing' } }));
116
+ // Set volume, or start a new fade
117
+ if (isFadeValid(fade)) {
118
+ // Start fade when clip starts
119
+ fadeAudioPlayerVolume(clipPlayer.player, volume, fade * 1000, soundId);
120
+ }
121
+ else {
122
+ setAudioPlayerVolume(clipPlayer.player, volume, soundId);
123
+ }
124
+ });
104
125
  // paused and pause_requested clips treated the same, they should have their properties
105
126
  // updated with the latest play action's properties
106
127
  [...pausedSoundIds, ...pauseRequestedSoundIds, ...newSoundIds].forEach((soundId) => {
@@ -114,6 +135,7 @@ class AudioPlayer {
114
135
  // Non-preloaded clips don't yet have an HTML audio node
115
136
  // so we need to set the audio output when it's playing
116
137
  clipPlayer.player.once('play', () => {
138
+ log('play() callback - setPlayerSinkId', { soundId });
117
139
  setPlayerSinkId(clipPlayer.player, this.sinkId);
118
140
  });
119
141
  clipPlayer.player.once('stop', () => this.handleStoppedClip(path, playId, soundId), soundId);
@@ -130,19 +152,23 @@ class AudioPlayer {
130
152
  loop,
131
153
  volume,
132
154
  };
155
+ log('CLIP -> play_requested');
133
156
  // Once clip starts, check if it should actually be paused or stopped
134
157
  // If not, then update state to 'playing'
135
158
  clipPlayer.player.once('play', () => {
136
- const clipState = clipPlayer.activeClips[soundId].state;
137
- if (clipState.type === 'pause_requested') {
159
+ var _a;
160
+ log('play() callback - update state', { soundId });
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') {
138
163
  log('Clip started playing but should be paused', { path, soundId });
139
164
  this.pauseAudioClip(path, { fade: clipState.fade }, soundId, true);
140
165
  }
141
- else if (clipState.type === 'stop_requested') {
166
+ else if ((clipState === null || clipState === void 0 ? void 0 : clipState.type) === 'stop_requested') {
142
167
  log('Clip started playing but should be stopped', { path, soundId });
143
168
  this.stopAudioClip(path, { fade: clipState.fade }, soundId, true);
144
169
  }
145
170
  else {
171
+ log('CLIP -> playing');
146
172
  this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'playing' } }));
147
173
  }
148
174
  }, soundId);
@@ -152,6 +178,7 @@ class AudioPlayer {
152
178
  clipPlayer.player.volume(0, soundId);
153
179
  clipPlayer.player.mute(false, soundId);
154
180
  clipPlayer.player.once('play', () => {
181
+ log('play() callback - fade volume', { soundId });
155
182
  fadeAudioPlayerVolume(clipPlayer.player, volume, fade * 1000, soundId);
156
183
  }, soundId);
157
184
  }
@@ -181,21 +208,25 @@ class AudioPlayer {
181
208
  // Fade then pause
182
209
  clipPlayer.player.once('fade', (soundId) => {
183
210
  clipPlayer.player.pause(soundId);
211
+ log('CLIP -> paused (after fade)');
184
212
  this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'paused' } }));
185
213
  this.notifyClipStateListeners(clip.playId, path, 'paused');
186
214
  }, soundId);
187
215
  fadeAudioPlayerVolume(clipPlayer.player, 0, fade * 1000, soundId);
216
+ log('CLIP -> pausing');
188
217
  clip.state = { type: 'pausing' };
189
218
  }
190
219
  else {
191
220
  // Pause now
192
221
  clipPlayer.player.pause(soundId);
222
+ log('CLIP -> paused');
193
223
  clip.state = { type: 'paused' };
194
224
  this.notifyClipStateListeners(clip.playId, path, 'paused');
195
225
  }
196
226
  }
197
227
  // Clip hasn't started playing yet, or has already had pause_requested (but fade may have changed so update here)
198
228
  else if (clip.state.type === 'play_requested' || clip.state.type === 'pause_requested') {
229
+ log('CLIP -> pause_requested');
199
230
  clip.state = { type: 'pause_requested', fade };
200
231
  }
201
232
  }
@@ -227,6 +258,7 @@ class AudioPlayer {
227
258
  fadeAudioPlayerVolume(clipPlayer.player, 0, fade * 1000, soundId);
228
259
  // Set callback after starting new fade, otherwise it will fire straight away as the previous fade is cancelled
229
260
  clipPlayer.player.once('fade', (soundId) => clipPlayer.player.stop(soundId), soundId);
261
+ log('CLIP -> stopping');
230
262
  clip.state = { type: 'stopping' };
231
263
  }
232
264
  else {
@@ -237,6 +269,7 @@ class AudioPlayer {
237
269
  // or has pause_requested, but stop takes precedence
238
270
  else if (clip.state.type === 'play_requested' || clip.state.type === 'pause_requested' || clip.state.type === 'stop_requested') {
239
271
  log("Trying to stop clip which hasn't started playing yet", { path, soundId });
272
+ log('CLIP -> stop_requested');
240
273
  clip.state = { type: 'stop_requested', fade };
241
274
  }
242
275
  }