@clockworkdog/cogs-client 1.5.3 → 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 +4 -0
- package/dist/AudioPlayer.js +35 -3
- package/dist/browser/index.js +52 -17
- 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 +1 -1
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,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'
|
|
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,10 +152,12 @@ 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
159
|
var _a;
|
|
160
|
+
log('play() callback - update state', { soundId });
|
|
137
161
|
const clipState = (_a = clipPlayer.activeClips[soundId]) === null || _a === void 0 ? void 0 : _a.state;
|
|
138
162
|
if ((clipState === null || clipState === void 0 ? void 0 : clipState.type) === 'pause_requested') {
|
|
139
163
|
log('Clip started playing but should be paused', { path, soundId });
|
|
@@ -144,6 +168,7 @@ class AudioPlayer {
|
|
|
144
168
|
this.stopAudioClip(path, { fade: clipState.fade }, soundId, true);
|
|
145
169
|
}
|
|
146
170
|
else {
|
|
171
|
+
log('CLIP -> playing');
|
|
147
172
|
this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'playing' } }));
|
|
148
173
|
}
|
|
149
174
|
}, soundId);
|
|
@@ -153,6 +178,7 @@ class AudioPlayer {
|
|
|
153
178
|
clipPlayer.player.volume(0, soundId);
|
|
154
179
|
clipPlayer.player.mute(false, soundId);
|
|
155
180
|
clipPlayer.player.once('play', () => {
|
|
181
|
+
log('play() callback - fade volume', { soundId });
|
|
156
182
|
fadeAudioPlayerVolume(clipPlayer.player, volume, fade * 1000, soundId);
|
|
157
183
|
}, soundId);
|
|
158
184
|
}
|
|
@@ -182,21 +208,25 @@ class AudioPlayer {
|
|
|
182
208
|
// Fade then pause
|
|
183
209
|
clipPlayer.player.once('fade', (soundId) => {
|
|
184
210
|
clipPlayer.player.pause(soundId);
|
|
211
|
+
log('CLIP -> paused (after fade)');
|
|
185
212
|
this.updateActiveAudioClip(path, soundId, (clip) => ({ ...clip, state: { type: 'paused' } }));
|
|
186
213
|
this.notifyClipStateListeners(clip.playId, path, 'paused');
|
|
187
214
|
}, soundId);
|
|
188
215
|
fadeAudioPlayerVolume(clipPlayer.player, 0, fade * 1000, soundId);
|
|
216
|
+
log('CLIP -> pausing');
|
|
189
217
|
clip.state = { type: 'pausing' };
|
|
190
218
|
}
|
|
191
219
|
else {
|
|
192
220
|
// Pause now
|
|
193
221
|
clipPlayer.player.pause(soundId);
|
|
222
|
+
log('CLIP -> paused');
|
|
194
223
|
clip.state = { type: 'paused' };
|
|
195
224
|
this.notifyClipStateListeners(clip.playId, path, 'paused');
|
|
196
225
|
}
|
|
197
226
|
}
|
|
198
227
|
// Clip hasn't started playing yet, or has already had pause_requested (but fade may have changed so update here)
|
|
199
228
|
else if (clip.state.type === 'play_requested' || clip.state.type === 'pause_requested') {
|
|
229
|
+
log('CLIP -> pause_requested');
|
|
200
230
|
clip.state = { type: 'pause_requested', fade };
|
|
201
231
|
}
|
|
202
232
|
}
|
|
@@ -228,6 +258,7 @@ class AudioPlayer {
|
|
|
228
258
|
fadeAudioPlayerVolume(clipPlayer.player, 0, fade * 1000, soundId);
|
|
229
259
|
// Set callback after starting new fade, otherwise it will fire straight away as the previous fade is cancelled
|
|
230
260
|
clipPlayer.player.once('fade', (soundId) => clipPlayer.player.stop(soundId), soundId);
|
|
261
|
+
log('CLIP -> stopping');
|
|
231
262
|
clip.state = { type: 'stopping' };
|
|
232
263
|
}
|
|
233
264
|
else {
|
|
@@ -238,6 +269,7 @@ class AudioPlayer {
|
|
|
238
269
|
// or has pause_requested, but stop takes precedence
|
|
239
270
|
else if (clip.state.type === 'play_requested' || clip.state.type === 'pause_requested' || clip.state.type === 'stop_requested') {
|
|
240
271
|
log("Trying to stop clip which hasn't started playing yet", { path, soundId });
|
|
272
|
+
log('CLIP -> stop_requested');
|
|
241
273
|
clip.state = { type: 'stop_requested', fade };
|
|
242
274
|
}
|
|
243
275
|
}
|