@clockworkdog/cogs-client 1.5.5 → 1.5.6

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.
@@ -95,7 +95,7 @@ class AudioPlayer {
95
95
  .filter(([, { state }]) => state.type === 'pausing')
96
96
  .map(([id]) => parseInt(id));
97
97
  pausedSoundIds.forEach((soundId) => {
98
- log('Resuming paused clip', { soundId });
98
+ log('Resuming paused clip', soundId);
99
99
  clipPlayer.player.play(soundId);
100
100
  });
101
101
  // Clips with pause requested no longer need to pause, they can continue playing now
@@ -106,7 +106,7 @@ class AudioPlayer {
106
106
  const newSoundIds = pausedSoundIds.length > 0 || pausingSoundIds.length > 0 || pauseRequestedSoundIds.length > 0 ? [] : [clipPlayer.player.play()];
107
107
  // Pausing clips are technically currently playing as far as Howler is concerned
108
108
  pausingSoundIds.forEach((soundId) => {
109
- log('Stopping fade and resuming pausing clip', { soundId });
109
+ log('Stopping fade and resuming pausing clip', soundId);
110
110
  // Stop the fade callback
111
111
  clipPlayer.player.off('fade', undefined, soundId);
112
112
  // Set loop property
@@ -135,7 +135,6 @@ class AudioPlayer {
135
135
  // Non-preloaded clips don't yet have an HTML audio node
136
136
  // so we need to set the audio output when it's playing
137
137
  clipPlayer.player.once('play', () => {
138
- log('play() callback - setPlayerSinkId', { soundId });
139
138
  setPlayerSinkId(clipPlayer.player, this.sinkId);
140
139
  });
141
140
  clipPlayer.player.once('stop', () => this.handleStoppedClip(path, playId, soundId), soundId);
@@ -152,12 +151,11 @@ class AudioPlayer {
152
151
  loop,
153
152
  volume,
154
153
  };
155
- log('CLIP -> play_requested');
154
+ log('CLIP -> play_requested', soundId);
156
155
  // Once clip starts, check if it should actually be paused or stopped
157
156
  // If not, then update state to 'playing'
158
157
  clipPlayer.player.once('play', () => {
159
158
  var _a;
160
- log('play() callback - update state', { soundId });
161
159
  const clipState = (_a = clipPlayer.activeClips[soundId]) === null || _a === void 0 ? void 0 : _a.state;
162
160
  if ((clipState === null || clipState === void 0 ? void 0 : clipState.type) === 'pause_requested') {
163
161
  log('Clip started playing but should be paused', { path, soundId });
@@ -168,7 +166,7 @@ class AudioPlayer {
168
166
  this.stopAudioClip(path, { fade: clipState.fade }, soundId, true);
169
167
  }
170
168
  else {
171
- log('CLIP -> playing');
169
+ log('CLIP -> playing', soundId);
172
170
  this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'playing' } }));
173
171
  }
174
172
  }, soundId);
@@ -178,7 +176,6 @@ class AudioPlayer {
178
176
  clipPlayer.player.volume(0, soundId);
179
177
  clipPlayer.player.mute(false, soundId);
180
178
  clipPlayer.player.once('play', () => {
181
- log('play() callback - fade volume', { soundId });
182
179
  fadeAudioPlayerVolume(clipPlayer.player, volume, fade * 1000, soundId);
183
180
  }, soundId);
184
181
  }
@@ -208,25 +205,25 @@ class AudioPlayer {
208
205
  // Fade then pause
209
206
  clipPlayer.player.once('fade', (soundId) => {
210
207
  clipPlayer.player.pause(soundId);
211
- log('CLIP -> paused (after fade)');
208
+ log('CLIP -> paused (after fade)', soundId);
212
209
  this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'paused' } }));
213
210
  this.notifyClipStateListeners(clip.playId, path, 'paused');
214
211
  }, soundId);
215
212
  fadeAudioPlayerVolume(clipPlayer.player, 0, fade * 1000, soundId);
216
- log('CLIP -> pausing');
213
+ log('CLIP -> pausing', soundId);
217
214
  clip.state = { type: 'pausing' };
218
215
  }
219
216
  else {
220
217
  // Pause now
221
218
  clipPlayer.player.pause(soundId);
222
- log('CLIP -> paused');
219
+ log('CLIP -> paused', soundId);
223
220
  clip.state = { type: 'paused' };
224
221
  this.notifyClipStateListeners(clip.playId, path, 'paused');
225
222
  }
226
223
  }
227
224
  // Clip hasn't started playing yet, or has already had pause_requested (but fade may have changed so update here)
228
225
  else if (clip.state.type === 'play_requested' || clip.state.type === 'pause_requested') {
229
- log('CLIP -> pause_requested');
226
+ log('CLIP -> pause_requested', soundId);
230
227
  clip.state = { type: 'pause_requested', fade };
231
228
  }
232
229
  }
@@ -236,9 +233,10 @@ class AudioPlayer {
236
233
  });
237
234
  }
238
235
  stopAudioClip(path, { fade }, onlySoundId, allowIfStopRequested) {
239
- var _a, _b;
236
+ var _a, _b, _c;
237
+ log('Stop audio clip', { activeClips: (_a = this.audioClipPlayers[path]) === null || _a === void 0 ? void 0 : _a.activeClips });
240
238
  // No active clips to stop
241
- if (Object.keys((_b = (_a = this.audioClipPlayers[path]) === null || _a === void 0 ? void 0 : _a.activeClips) !== null && _b !== void 0 ? _b : {}).length === 0) {
239
+ if (Object.keys((_c = (_b = this.audioClipPlayers[path]) === null || _b === void 0 ? void 0 : _b.activeClips) !== null && _c !== void 0 ? _c : {}).length === 0) {
242
240
  return;
243
241
  }
244
242
  this.updateAudioClipPlayer(path, (clipPlayer) => {
@@ -257,11 +255,16 @@ class AudioPlayer {
257
255
  clipPlayer.player.off('fade', soundId);
258
256
  fadeAudioPlayerVolume(clipPlayer.player, 0, fade * 1000, soundId);
259
257
  // Set callback after starting new fade, otherwise it will fire straight away as the previous fade is cancelled
260
- clipPlayer.player.once('fade', (soundId) => clipPlayer.player.stop(soundId), soundId);
261
- log('CLIP -> stopping');
258
+ clipPlayer.player.once('fade', (soundId) => {
259
+ clipPlayer.player.loop(false, soundId);
260
+ clipPlayer.player.stop(soundId), soundId;
261
+ });
262
+ log('CLIP -> stopping', soundId);
262
263
  clip.state = { type: 'stopping' };
263
264
  }
264
265
  else {
266
+ log('Stop clip', soundId);
267
+ clipPlayer.player.loop(false, soundId);
265
268
  clipPlayer.player.stop(soundId);
266
269
  }
267
270
  }
@@ -269,7 +272,7 @@ class AudioPlayer {
269
272
  // or has pause_requested, but stop takes precedence
270
273
  else if (clip.state.type === 'play_requested' || clip.state.type === 'pause_requested' || clip.state.type === 'stop_requested') {
271
274
  log("Trying to stop clip which hasn't started playing yet", { path, soundId });
272
- log('CLIP -> stop_requested');
275
+ log('CLIP -> stop_requested', soundId);
273
276
  clip.state = { type: 'stop_requested', fade };
274
277
  }
275
278
  }
@@ -471,9 +474,8 @@ function setAudioPlayerVolume(howl, volume, soundId) {
471
474
  /**
472
475
  * Fade to audio volume
473
476
  *
474
- * This doesn't work on iOS (volume is read-only) so at least mute it if the volume is zero
477
+ * Note: This doesn't work on iOS (volume is read-only)
475
478
  */
476
479
  function fadeAudioPlayerVolume(howl, volume, fade, soundId) {
477
- howl.mute(false, soundId);
478
480
  howl.fade(howl.volume(soundId), volume, fade, soundId);
479
481
  }