@clockworkdog/cogs-client 1.5.3 → 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.
- package/README.md +4 -0
- package/dist/AudioPlayer.js +43 -9
- package/dist/browser/index.js +61 -24
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/PluginManifestJson.d.ts +116 -0
- package/dist/types/PluginManifestJson.js +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,6 +30,10 @@ yarn add @clockworkdog/cogs-client
|
|
|
30
30
|
|
|
31
31
|
## Usage
|
|
32
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
|
+
|
|
33
37
|
### Import the library
|
|
34
38
|
|
|
35
39
|
#### Browser
|
package/dist/AudioPlayer.js
CHANGED
|
@@ -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 =
|
|
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,10 +89,13 @@ 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'
|
|
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
|
-
log('Resuming paused clip',
|
|
98
|
+
log('Resuming paused clip', soundId);
|
|
96
99
|
clipPlayer.player.play(soundId);
|
|
97
100
|
});
|
|
98
101
|
// Clips with pause requested no longer need to pause, they can continue playing now
|
|
@@ -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) => {
|
|
@@ -130,6 +151,7 @@ class AudioPlayer {
|
|
|
130
151
|
loop,
|
|
131
152
|
volume,
|
|
132
153
|
};
|
|
154
|
+
log('CLIP -> play_requested', soundId);
|
|
133
155
|
// Once clip starts, check if it should actually be paused or stopped
|
|
134
156
|
// If not, then update state to 'playing'
|
|
135
157
|
clipPlayer.player.once('play', () => {
|
|
@@ -144,6 +166,7 @@ class AudioPlayer {
|
|
|
144
166
|
this.stopAudioClip(path, { fade: clipState.fade }, soundId, true);
|
|
145
167
|
}
|
|
146
168
|
else {
|
|
169
|
+
log('CLIP -> playing', soundId);
|
|
147
170
|
this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'playing' } }));
|
|
148
171
|
}
|
|
149
172
|
}, soundId);
|
|
@@ -182,21 +205,25 @@ class AudioPlayer {
|
|
|
182
205
|
// Fade then pause
|
|
183
206
|
clipPlayer.player.once('fade', (soundId) => {
|
|
184
207
|
clipPlayer.player.pause(soundId);
|
|
208
|
+
log('CLIP -> paused (after fade)', soundId);
|
|
185
209
|
this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'paused' } }));
|
|
186
210
|
this.notifyClipStateListeners(clip.playId, path, 'paused');
|
|
187
211
|
}, soundId);
|
|
188
212
|
fadeAudioPlayerVolume(clipPlayer.player, 0, fade * 1000, soundId);
|
|
213
|
+
log('CLIP -> pausing', soundId);
|
|
189
214
|
clip.state = { type: 'pausing' };
|
|
190
215
|
}
|
|
191
216
|
else {
|
|
192
217
|
// Pause now
|
|
193
218
|
clipPlayer.player.pause(soundId);
|
|
219
|
+
log('CLIP -> paused', soundId);
|
|
194
220
|
clip.state = { type: 'paused' };
|
|
195
221
|
this.notifyClipStateListeners(clip.playId, path, 'paused');
|
|
196
222
|
}
|
|
197
223
|
}
|
|
198
224
|
// Clip hasn't started playing yet, or has already had pause_requested (but fade may have changed so update here)
|
|
199
225
|
else if (clip.state.type === 'play_requested' || clip.state.type === 'pause_requested') {
|
|
226
|
+
log('CLIP -> pause_requested', soundId);
|
|
200
227
|
clip.state = { type: 'pause_requested', fade };
|
|
201
228
|
}
|
|
202
229
|
}
|
|
@@ -206,9 +233,10 @@ class AudioPlayer {
|
|
|
206
233
|
});
|
|
207
234
|
}
|
|
208
235
|
stopAudioClip(path, { fade }, onlySoundId, allowIfStopRequested) {
|
|
209
|
-
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 });
|
|
210
238
|
// No active clips to stop
|
|
211
|
-
if (Object.keys((
|
|
239
|
+
if (Object.keys((_c = (_b = this.audioClipPlayers[path]) === null || _b === void 0 ? void 0 : _b.activeClips) !== null && _c !== void 0 ? _c : {}).length === 0) {
|
|
212
240
|
return;
|
|
213
241
|
}
|
|
214
242
|
this.updateAudioClipPlayer(path, (clipPlayer) => {
|
|
@@ -227,10 +255,16 @@ class AudioPlayer {
|
|
|
227
255
|
clipPlayer.player.off('fade', soundId);
|
|
228
256
|
fadeAudioPlayerVolume(clipPlayer.player, 0, fade * 1000, soundId);
|
|
229
257
|
// Set callback after starting new fade, otherwise it will fire straight away as the previous fade is cancelled
|
|
230
|
-
clipPlayer.player.once('fade', (soundId) =>
|
|
258
|
+
clipPlayer.player.once('fade', (soundId) => {
|
|
259
|
+
clipPlayer.player.loop(false, soundId);
|
|
260
|
+
clipPlayer.player.stop(soundId), soundId;
|
|
261
|
+
});
|
|
262
|
+
log('CLIP -> stopping', soundId);
|
|
231
263
|
clip.state = { type: 'stopping' };
|
|
232
264
|
}
|
|
233
265
|
else {
|
|
266
|
+
log('Stop clip', soundId);
|
|
267
|
+
clipPlayer.player.loop(false, soundId);
|
|
234
268
|
clipPlayer.player.stop(soundId);
|
|
235
269
|
}
|
|
236
270
|
}
|
|
@@ -238,6 +272,7 @@ class AudioPlayer {
|
|
|
238
272
|
// or has pause_requested, but stop takes precedence
|
|
239
273
|
else if (clip.state.type === 'play_requested' || clip.state.type === 'pause_requested' || clip.state.type === 'stop_requested') {
|
|
240
274
|
log("Trying to stop clip which hasn't started playing yet", { path, soundId });
|
|
275
|
+
log('CLIP -> stop_requested', soundId);
|
|
241
276
|
clip.state = { type: 'stop_requested', fade };
|
|
242
277
|
}
|
|
243
278
|
}
|
|
@@ -439,9 +474,8 @@ function setAudioPlayerVolume(howl, volume, soundId) {
|
|
|
439
474
|
/**
|
|
440
475
|
* Fade to audio volume
|
|
441
476
|
*
|
|
442
|
-
* This doesn't work on iOS (volume is read-only)
|
|
477
|
+
* Note: This doesn't work on iOS (volume is read-only)
|
|
443
478
|
*/
|
|
444
479
|
function fadeAudioPlayerVolume(howl, volume, fade, soundId) {
|
|
445
|
-
howl.mute(false, soundId);
|
|
446
480
|
howl.fade(howl.volume(soundId), volume, fade, soundId);
|
|
447
481
|
}
|