@clockworkdog/cogs-client 2.10.2 → 2.11.1
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 -4
- package/dist/AudioPlayer.js +5 -3
- package/dist/CogsConnection.js +23 -3
- package/dist/browser/index.mjs +1716 -0
- package/dist/browser/index.umd.js +19 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.js +3 -9
- package/package.json +13 -7
- package/dist/RtspStreamer.d.ts +0 -27
- package/dist/RtspStreamer.js +0 -101
- package/dist/browser/index.js +0 -7565
- /package/dist/{helpers → utils}/urls.d.ts +0 -0
- /package/dist/{helpers → utils}/urls.js +0 -0
|
@@ -0,0 +1,1716 @@
|
|
|
1
|
+
var J = /* @__PURE__ */ ((u) => (u.Setup = "setup", u.Preshow = "pre-show", u.InProgress = "in progress", u.Finished = "finished", u))(J || {});
|
|
2
|
+
/*! *****************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
6
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
|
|
8
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
9
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
10
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
11
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
+
|
|
13
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
|
+
and limitations under the License.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
var N = function(u, n) {
|
|
17
|
+
return N = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(s, o) {
|
|
18
|
+
s.__proto__ = o;
|
|
19
|
+
} || function(s, o) {
|
|
20
|
+
for (var r in o) o.hasOwnProperty(r) && (s[r] = o[r]);
|
|
21
|
+
}, N(u, n);
|
|
22
|
+
};
|
|
23
|
+
function z(u, n) {
|
|
24
|
+
N(u, n);
|
|
25
|
+
function s() {
|
|
26
|
+
this.constructor = u;
|
|
27
|
+
}
|
|
28
|
+
u.prototype = n === null ? Object.create(n) : (s.prototype = n.prototype, new s());
|
|
29
|
+
}
|
|
30
|
+
function ee(u) {
|
|
31
|
+
var n = typeof Symbol == "function" && u[Symbol.iterator], s = 0;
|
|
32
|
+
return n ? n.call(u) : {
|
|
33
|
+
next: function() {
|
|
34
|
+
return u && s >= u.length && (u = void 0), { value: u && u[s++], done: !u };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function te(u, n) {
|
|
39
|
+
var s = typeof Symbol == "function" && u[Symbol.iterator];
|
|
40
|
+
if (!s) return u;
|
|
41
|
+
var o = s.call(u), r, _ = [], p;
|
|
42
|
+
try {
|
|
43
|
+
for (; (n === void 0 || n-- > 0) && !(r = o.next()).done; ) _.push(r.value);
|
|
44
|
+
} catch (v) {
|
|
45
|
+
p = { error: v };
|
|
46
|
+
} finally {
|
|
47
|
+
try {
|
|
48
|
+
r && !r.done && (s = o.return) && s.call(o);
|
|
49
|
+
} finally {
|
|
50
|
+
if (p) throw p.error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return _;
|
|
54
|
+
}
|
|
55
|
+
function ne() {
|
|
56
|
+
for (var u = [], n = 0; n < arguments.length; n++)
|
|
57
|
+
u = u.concat(te(arguments[n]));
|
|
58
|
+
return u;
|
|
59
|
+
}
|
|
60
|
+
var Y = (
|
|
61
|
+
/** @class */
|
|
62
|
+
/* @__PURE__ */ function() {
|
|
63
|
+
function u(n, s) {
|
|
64
|
+
this.target = s, this.type = n;
|
|
65
|
+
}
|
|
66
|
+
return u;
|
|
67
|
+
}()
|
|
68
|
+
), ie = (
|
|
69
|
+
/** @class */
|
|
70
|
+
function(u) {
|
|
71
|
+
z(n, u);
|
|
72
|
+
function n(s, o) {
|
|
73
|
+
var r = u.call(this, "error", o) || this;
|
|
74
|
+
return r.message = s.message, r.error = s, r;
|
|
75
|
+
}
|
|
76
|
+
return n;
|
|
77
|
+
}(Y)
|
|
78
|
+
), oe = (
|
|
79
|
+
/** @class */
|
|
80
|
+
function(u) {
|
|
81
|
+
z(n, u);
|
|
82
|
+
function n(s, o, r) {
|
|
83
|
+
s === void 0 && (s = 1e3), o === void 0 && (o = "");
|
|
84
|
+
var _ = u.call(this, "close", r) || this;
|
|
85
|
+
return _.wasClean = !0, _.code = s, _.reason = o, _;
|
|
86
|
+
}
|
|
87
|
+
return n;
|
|
88
|
+
}(Y)
|
|
89
|
+
);
|
|
90
|
+
/*!
|
|
91
|
+
* Reconnecting WebSocket
|
|
92
|
+
* by Pedro Ladaria <pedro.ladaria@gmail.com>
|
|
93
|
+
* https://github.com/pladaria/reconnecting-websocket
|
|
94
|
+
* License MIT
|
|
95
|
+
*/
|
|
96
|
+
var se = function() {
|
|
97
|
+
if (typeof WebSocket < "u")
|
|
98
|
+
return WebSocket;
|
|
99
|
+
}, re = function(u) {
|
|
100
|
+
return typeof u < "u" && !!u && u.CLOSING === 2;
|
|
101
|
+
}, A = {
|
|
102
|
+
maxReconnectionDelay: 1e4,
|
|
103
|
+
minReconnectionDelay: 1e3 + Math.random() * 4e3,
|
|
104
|
+
minUptime: 5e3,
|
|
105
|
+
reconnectionDelayGrowFactor: 1.3,
|
|
106
|
+
connectionTimeout: 4e3,
|
|
107
|
+
maxRetries: 1 / 0,
|
|
108
|
+
maxEnqueuedMessages: 1 / 0
|
|
109
|
+
}, ae = (
|
|
110
|
+
/** @class */
|
|
111
|
+
function() {
|
|
112
|
+
function u(n, s, o) {
|
|
113
|
+
var r = this;
|
|
114
|
+
o === void 0 && (o = {}), this._listeners = {
|
|
115
|
+
error: [],
|
|
116
|
+
message: [],
|
|
117
|
+
open: [],
|
|
118
|
+
close: []
|
|
119
|
+
}, this._retryCount = -1, this._shouldReconnect = !0, this._connectLock = !1, this._binaryType = "blob", this._closeCalled = !1, this._messageQueue = [], this.onclose = null, this.onerror = null, this.onmessage = null, this.onopen = null, this._handleOpen = function(_) {
|
|
120
|
+
r._debug("open event");
|
|
121
|
+
var p = r._options.minUptime, v = p === void 0 ? A.minUptime : p;
|
|
122
|
+
clearTimeout(r._connectTimeout), r._uptimeTimeout = setTimeout(function() {
|
|
123
|
+
return r._acceptOpen();
|
|
124
|
+
}, v), r._ws.binaryType = r._binaryType, r._messageQueue.forEach(function(f) {
|
|
125
|
+
return r._ws.send(f);
|
|
126
|
+
}), r._messageQueue = [], r.onopen && r.onopen(_), r._listeners.open.forEach(function(f) {
|
|
127
|
+
return r._callEventListener(_, f);
|
|
128
|
+
});
|
|
129
|
+
}, this._handleMessage = function(_) {
|
|
130
|
+
r._debug("message event"), r.onmessage && r.onmessage(_), r._listeners.message.forEach(function(p) {
|
|
131
|
+
return r._callEventListener(_, p);
|
|
132
|
+
});
|
|
133
|
+
}, this._handleError = function(_) {
|
|
134
|
+
r._debug("error event", _.message), r._disconnect(void 0, _.message === "TIMEOUT" ? "timeout" : void 0), r.onerror && r.onerror(_), r._debug("exec error listeners"), r._listeners.error.forEach(function(p) {
|
|
135
|
+
return r._callEventListener(_, p);
|
|
136
|
+
}), r._connect();
|
|
137
|
+
}, this._handleClose = function(_) {
|
|
138
|
+
r._debug("close event"), r._clearTimeouts(), r._shouldReconnect && r._connect(), r.onclose && r.onclose(_), r._listeners.close.forEach(function(p) {
|
|
139
|
+
return r._callEventListener(_, p);
|
|
140
|
+
});
|
|
141
|
+
}, this._url = n, this._protocols = s, this._options = o, this._options.startClosed && (this._shouldReconnect = !1), this._connect();
|
|
142
|
+
}
|
|
143
|
+
return Object.defineProperty(u, "CONNECTING", {
|
|
144
|
+
get: function() {
|
|
145
|
+
return 0;
|
|
146
|
+
},
|
|
147
|
+
enumerable: !0,
|
|
148
|
+
configurable: !0
|
|
149
|
+
}), Object.defineProperty(u, "OPEN", {
|
|
150
|
+
get: function() {
|
|
151
|
+
return 1;
|
|
152
|
+
},
|
|
153
|
+
enumerable: !0,
|
|
154
|
+
configurable: !0
|
|
155
|
+
}), Object.defineProperty(u, "CLOSING", {
|
|
156
|
+
get: function() {
|
|
157
|
+
return 2;
|
|
158
|
+
},
|
|
159
|
+
enumerable: !0,
|
|
160
|
+
configurable: !0
|
|
161
|
+
}), Object.defineProperty(u, "CLOSED", {
|
|
162
|
+
get: function() {
|
|
163
|
+
return 3;
|
|
164
|
+
},
|
|
165
|
+
enumerable: !0,
|
|
166
|
+
configurable: !0
|
|
167
|
+
}), Object.defineProperty(u.prototype, "CONNECTING", {
|
|
168
|
+
get: function() {
|
|
169
|
+
return u.CONNECTING;
|
|
170
|
+
},
|
|
171
|
+
enumerable: !0,
|
|
172
|
+
configurable: !0
|
|
173
|
+
}), Object.defineProperty(u.prototype, "OPEN", {
|
|
174
|
+
get: function() {
|
|
175
|
+
return u.OPEN;
|
|
176
|
+
},
|
|
177
|
+
enumerable: !0,
|
|
178
|
+
configurable: !0
|
|
179
|
+
}), Object.defineProperty(u.prototype, "CLOSING", {
|
|
180
|
+
get: function() {
|
|
181
|
+
return u.CLOSING;
|
|
182
|
+
},
|
|
183
|
+
enumerable: !0,
|
|
184
|
+
configurable: !0
|
|
185
|
+
}), Object.defineProperty(u.prototype, "CLOSED", {
|
|
186
|
+
get: function() {
|
|
187
|
+
return u.CLOSED;
|
|
188
|
+
},
|
|
189
|
+
enumerable: !0,
|
|
190
|
+
configurable: !0
|
|
191
|
+
}), Object.defineProperty(u.prototype, "binaryType", {
|
|
192
|
+
get: function() {
|
|
193
|
+
return this._ws ? this._ws.binaryType : this._binaryType;
|
|
194
|
+
},
|
|
195
|
+
set: function(n) {
|
|
196
|
+
this._binaryType = n, this._ws && (this._ws.binaryType = n);
|
|
197
|
+
},
|
|
198
|
+
enumerable: !0,
|
|
199
|
+
configurable: !0
|
|
200
|
+
}), Object.defineProperty(u.prototype, "retryCount", {
|
|
201
|
+
/**
|
|
202
|
+
* Returns the number or connection retries
|
|
203
|
+
*/
|
|
204
|
+
get: function() {
|
|
205
|
+
return Math.max(this._retryCount, 0);
|
|
206
|
+
},
|
|
207
|
+
enumerable: !0,
|
|
208
|
+
configurable: !0
|
|
209
|
+
}), Object.defineProperty(u.prototype, "bufferedAmount", {
|
|
210
|
+
/**
|
|
211
|
+
* The number of bytes of data that have been queued using calls to send() but not yet
|
|
212
|
+
* transmitted to the network. This value resets to zero once all queued data has been sent.
|
|
213
|
+
* This value does not reset to zero when the connection is closed; if you keep calling send(),
|
|
214
|
+
* this will continue to climb. Read only
|
|
215
|
+
*/
|
|
216
|
+
get: function() {
|
|
217
|
+
var n = this._messageQueue.reduce(function(s, o) {
|
|
218
|
+
return typeof o == "string" ? s += o.length : o instanceof Blob ? s += o.size : s += o.byteLength, s;
|
|
219
|
+
}, 0);
|
|
220
|
+
return n + (this._ws ? this._ws.bufferedAmount : 0);
|
|
221
|
+
},
|
|
222
|
+
enumerable: !0,
|
|
223
|
+
configurable: !0
|
|
224
|
+
}), Object.defineProperty(u.prototype, "extensions", {
|
|
225
|
+
/**
|
|
226
|
+
* The extensions selected by the server. This is currently only the empty string or a list of
|
|
227
|
+
* extensions as negotiated by the connection
|
|
228
|
+
*/
|
|
229
|
+
get: function() {
|
|
230
|
+
return this._ws ? this._ws.extensions : "";
|
|
231
|
+
},
|
|
232
|
+
enumerable: !0,
|
|
233
|
+
configurable: !0
|
|
234
|
+
}), Object.defineProperty(u.prototype, "protocol", {
|
|
235
|
+
/**
|
|
236
|
+
* A string indicating the name of the sub-protocol the server selected;
|
|
237
|
+
* this will be one of the strings specified in the protocols parameter when creating the
|
|
238
|
+
* WebSocket object
|
|
239
|
+
*/
|
|
240
|
+
get: function() {
|
|
241
|
+
return this._ws ? this._ws.protocol : "";
|
|
242
|
+
},
|
|
243
|
+
enumerable: !0,
|
|
244
|
+
configurable: !0
|
|
245
|
+
}), Object.defineProperty(u.prototype, "readyState", {
|
|
246
|
+
/**
|
|
247
|
+
* The current state of the connection; this is one of the Ready state constants
|
|
248
|
+
*/
|
|
249
|
+
get: function() {
|
|
250
|
+
return this._ws ? this._ws.readyState : this._options.startClosed ? u.CLOSED : u.CONNECTING;
|
|
251
|
+
},
|
|
252
|
+
enumerable: !0,
|
|
253
|
+
configurable: !0
|
|
254
|
+
}), Object.defineProperty(u.prototype, "url", {
|
|
255
|
+
/**
|
|
256
|
+
* The URL as resolved by the constructor
|
|
257
|
+
*/
|
|
258
|
+
get: function() {
|
|
259
|
+
return this._ws ? this._ws.url : "";
|
|
260
|
+
},
|
|
261
|
+
enumerable: !0,
|
|
262
|
+
configurable: !0
|
|
263
|
+
}), u.prototype.close = function(n, s) {
|
|
264
|
+
if (n === void 0 && (n = 1e3), this._closeCalled = !0, this._shouldReconnect = !1, this._clearTimeouts(), !this._ws) {
|
|
265
|
+
this._debug("close enqueued: no ws instance");
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (this._ws.readyState === this.CLOSED) {
|
|
269
|
+
this._debug("close: already closed");
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
this._ws.close(n, s);
|
|
273
|
+
}, u.prototype.reconnect = function(n, s) {
|
|
274
|
+
this._shouldReconnect = !0, this._closeCalled = !1, this._retryCount = -1, !this._ws || this._ws.readyState === this.CLOSED ? this._connect() : (this._disconnect(n, s), this._connect());
|
|
275
|
+
}, u.prototype.send = function(n) {
|
|
276
|
+
if (this._ws && this._ws.readyState === this.OPEN)
|
|
277
|
+
this._debug("send", n), this._ws.send(n);
|
|
278
|
+
else {
|
|
279
|
+
var s = this._options.maxEnqueuedMessages, o = s === void 0 ? A.maxEnqueuedMessages : s;
|
|
280
|
+
this._messageQueue.length < o && (this._debug("enqueue", n), this._messageQueue.push(n));
|
|
281
|
+
}
|
|
282
|
+
}, u.prototype.addEventListener = function(n, s) {
|
|
283
|
+
this._listeners[n] && this._listeners[n].push(s);
|
|
284
|
+
}, u.prototype.dispatchEvent = function(n) {
|
|
285
|
+
var s, o, r = this._listeners[n.type];
|
|
286
|
+
if (r)
|
|
287
|
+
try {
|
|
288
|
+
for (var _ = ee(r), p = _.next(); !p.done; p = _.next()) {
|
|
289
|
+
var v = p.value;
|
|
290
|
+
this._callEventListener(n, v);
|
|
291
|
+
}
|
|
292
|
+
} catch (f) {
|
|
293
|
+
s = { error: f };
|
|
294
|
+
} finally {
|
|
295
|
+
try {
|
|
296
|
+
p && !p.done && (o = _.return) && o.call(_);
|
|
297
|
+
} finally {
|
|
298
|
+
if (s) throw s.error;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return !0;
|
|
302
|
+
}, u.prototype.removeEventListener = function(n, s) {
|
|
303
|
+
this._listeners[n] && (this._listeners[n] = this._listeners[n].filter(function(o) {
|
|
304
|
+
return o !== s;
|
|
305
|
+
}));
|
|
306
|
+
}, u.prototype._debug = function() {
|
|
307
|
+
for (var n = [], s = 0; s < arguments.length; s++)
|
|
308
|
+
n[s] = arguments[s];
|
|
309
|
+
this._options.debug && console.log.apply(console, ne(["RWS>"], n));
|
|
310
|
+
}, u.prototype._getNextDelay = function() {
|
|
311
|
+
var n = this._options, s = n.reconnectionDelayGrowFactor, o = s === void 0 ? A.reconnectionDelayGrowFactor : s, r = n.minReconnectionDelay, _ = r === void 0 ? A.minReconnectionDelay : r, p = n.maxReconnectionDelay, v = p === void 0 ? A.maxReconnectionDelay : p, f = 0;
|
|
312
|
+
return this._retryCount > 0 && (f = _ * Math.pow(o, this._retryCount - 1), f > v && (f = v)), this._debug("next delay", f), f;
|
|
313
|
+
}, u.prototype._wait = function() {
|
|
314
|
+
var n = this;
|
|
315
|
+
return new Promise(function(s) {
|
|
316
|
+
setTimeout(s, n._getNextDelay());
|
|
317
|
+
});
|
|
318
|
+
}, u.prototype._getNextUrl = function(n) {
|
|
319
|
+
if (typeof n == "string")
|
|
320
|
+
return Promise.resolve(n);
|
|
321
|
+
if (typeof n == "function") {
|
|
322
|
+
var s = n();
|
|
323
|
+
if (typeof s == "string")
|
|
324
|
+
return Promise.resolve(s);
|
|
325
|
+
if (s.then)
|
|
326
|
+
return s;
|
|
327
|
+
}
|
|
328
|
+
throw Error("Invalid URL");
|
|
329
|
+
}, u.prototype._connect = function() {
|
|
330
|
+
var n = this;
|
|
331
|
+
if (!(this._connectLock || !this._shouldReconnect)) {
|
|
332
|
+
this._connectLock = !0;
|
|
333
|
+
var s = this._options, o = s.maxRetries, r = o === void 0 ? A.maxRetries : o, _ = s.connectionTimeout, p = _ === void 0 ? A.connectionTimeout : _, v = s.WebSocket, f = v === void 0 ? se() : v;
|
|
334
|
+
if (this._retryCount >= r) {
|
|
335
|
+
this._debug("max retries reached", this._retryCount, ">=", r);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (this._retryCount++, this._debug("connect", this._retryCount), this._removeListeners(), !re(f))
|
|
339
|
+
throw Error("No valid WebSocket class provided");
|
|
340
|
+
this._wait().then(function() {
|
|
341
|
+
return n._getNextUrl(n._url);
|
|
342
|
+
}).then(function(y) {
|
|
343
|
+
n._closeCalled || (n._debug("connect", { url: y, protocols: n._protocols }), n._ws = n._protocols ? new f(y, n._protocols) : new f(y), n._ws.binaryType = n._binaryType, n._connectLock = !1, n._addListeners(), n._connectTimeout = setTimeout(function() {
|
|
344
|
+
return n._handleTimeout();
|
|
345
|
+
}, p));
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}, u.prototype._handleTimeout = function() {
|
|
349
|
+
this._debug("timeout event"), this._handleError(new ie(Error("TIMEOUT"), this));
|
|
350
|
+
}, u.prototype._disconnect = function(n, s) {
|
|
351
|
+
if (n === void 0 && (n = 1e3), this._clearTimeouts(), !!this._ws) {
|
|
352
|
+
this._removeListeners();
|
|
353
|
+
try {
|
|
354
|
+
this._ws.close(n, s), this._handleClose(new oe(n, s, this));
|
|
355
|
+
} catch {
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}, u.prototype._acceptOpen = function() {
|
|
359
|
+
this._debug("accept open"), this._retryCount = 0;
|
|
360
|
+
}, u.prototype._callEventListener = function(n, s) {
|
|
361
|
+
"handleEvent" in s ? s.handleEvent(n) : s(n);
|
|
362
|
+
}, u.prototype._removeListeners = function() {
|
|
363
|
+
this._ws && (this._debug("removeListeners"), this._ws.removeEventListener("open", this._handleOpen), this._ws.removeEventListener("close", this._handleClose), this._ws.removeEventListener("message", this._handleMessage), this._ws.removeEventListener("error", this._handleError));
|
|
364
|
+
}, u.prototype._addListeners = function() {
|
|
365
|
+
this._ws && (this._debug("addListeners"), this._ws.addEventListener("open", this._handleOpen), this._ws.addEventListener("close", this._handleClose), this._ws.addEventListener("message", this._handleMessage), this._ws.addEventListener("error", this._handleError));
|
|
366
|
+
}, u.prototype._clearTimeouts = function() {
|
|
367
|
+
clearTimeout(this._connectTimeout), clearTimeout(this._uptimeTimeout);
|
|
368
|
+
}, u;
|
|
369
|
+
}()
|
|
370
|
+
);
|
|
371
|
+
const X = 12095;
|
|
372
|
+
function ue(u) {
|
|
373
|
+
const n = typeof window < "u" ? window.location : void 0, s = `/assets/${encodeURIComponent(u)}`;
|
|
374
|
+
return `${n?.protocol}//${n?.hostname}:${X}${s}`;
|
|
375
|
+
}
|
|
376
|
+
async function Le(u) {
|
|
377
|
+
const n = await fetch(u);
|
|
378
|
+
return URL.createObjectURL(new Blob([await n.arrayBuffer()]));
|
|
379
|
+
}
|
|
380
|
+
class de {
|
|
381
|
+
#e = new EventTarget();
|
|
382
|
+
constructor(n) {
|
|
383
|
+
this._items = { ...n };
|
|
384
|
+
}
|
|
385
|
+
handleDataStoreItemsMessage(n) {
|
|
386
|
+
this._items = { ...this._items, ...n.items }, Object.entries(n.items).forEach(([s, o]) => {
|
|
387
|
+
this.dispatchEvent(new F(s, o));
|
|
388
|
+
}), this.dispatchEvent(new q(n.items));
|
|
389
|
+
}
|
|
390
|
+
get items() {
|
|
391
|
+
return this._items;
|
|
392
|
+
}
|
|
393
|
+
getItem(n) {
|
|
394
|
+
return this._items[n];
|
|
395
|
+
}
|
|
396
|
+
setItems(n) {
|
|
397
|
+
return this._items = { ...this._items, ...n }, Object.entries(n).forEach(([s, o]) => {
|
|
398
|
+
this.dispatchEvent(new F(s, o));
|
|
399
|
+
}), this.dispatchEvent(new q(n)), this;
|
|
400
|
+
}
|
|
401
|
+
// Type-safe listeners
|
|
402
|
+
addEventListener(n, s, o) {
|
|
403
|
+
this.#e.addEventListener(n, s, o);
|
|
404
|
+
}
|
|
405
|
+
removeEventListener(n, s, o) {
|
|
406
|
+
this.#e.removeEventListener(n, s, o);
|
|
407
|
+
}
|
|
408
|
+
dispatchEvent(n) {
|
|
409
|
+
this.#e.dispatchEvent(n);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
class F extends Event {
|
|
413
|
+
constructor(n, s) {
|
|
414
|
+
super("item"), this.key = n, this.value = s, this._cogsConnectionEventType = "item";
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
class q extends Event {
|
|
418
|
+
constructor(n) {
|
|
419
|
+
super("items"), this.items = n, this._cogsConnectionEventType = "item";
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const k = globalThis.Date;
|
|
423
|
+
function le(u) {
|
|
424
|
+
const n = u - k.now();
|
|
425
|
+
function s(...r) {
|
|
426
|
+
return r.length === 0 ? new k(s.now()) : new k(...r);
|
|
427
|
+
}
|
|
428
|
+
const o = Object.getOwnPropertyDescriptors(k);
|
|
429
|
+
Object.defineProperties(s, o), s.now = function() {
|
|
430
|
+
return k.now() + n;
|
|
431
|
+
}, globalThis.Date = s;
|
|
432
|
+
}
|
|
433
|
+
let ce = 0;
|
|
434
|
+
function pe() {
|
|
435
|
+
return ++ce;
|
|
436
|
+
}
|
|
437
|
+
const _e = 5, fe = 1e4;
|
|
438
|
+
function he({ interval: u, send: n, onChange: s = le, syncSampleSize: o = _e, syncRequestTimeout: r = fe }) {
|
|
439
|
+
const _ = {};
|
|
440
|
+
async function p() {
|
|
441
|
+
const C = [];
|
|
442
|
+
for (let i = 0; i < o; i++) {
|
|
443
|
+
const a = new Promise((d) => {
|
|
444
|
+
const c = pe(), l = performance.now();
|
|
445
|
+
n({ timesync: { id: c } });
|
|
446
|
+
const m = (g, w) => d({ sentAt: l, receivedAt: g, serverNow: w, clientNow: Date.now() });
|
|
447
|
+
_[c] = { complete: m }, setTimeout(() => d(null), r);
|
|
448
|
+
});
|
|
449
|
+
C.push(a), await a;
|
|
450
|
+
}
|
|
451
|
+
const e = (await Promise.all(C)).filter((i) => i !== null).map((i) => {
|
|
452
|
+
const { sentAt: a, receivedAt: d, serverNow: c, clientNow: l } = i, m = (d - a) / 2;
|
|
453
|
+
return l - c + m;
|
|
454
|
+
}), t = e.reduce((i, a) => i + a, 0) / e.length;
|
|
455
|
+
isNaN(t) || s(Date.now() + t);
|
|
456
|
+
}
|
|
457
|
+
const v = (C) => {
|
|
458
|
+
const h = performance.now(), e = _[C.timesync.id];
|
|
459
|
+
e && e.complete(h, C.timesync.now);
|
|
460
|
+
};
|
|
461
|
+
p();
|
|
462
|
+
const f = setInterval(p, u);
|
|
463
|
+
return {
|
|
464
|
+
receive: v,
|
|
465
|
+
destroy: () => {
|
|
466
|
+
clearInterval(f);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
class xe {
|
|
471
|
+
constructor(n, { hostname: s = document.location.hostname, port: o = X } = {}, r, _) {
|
|
472
|
+
this.manifest = n, this.eventTarget = new EventTarget(), this.currentConfig = {}, this.currentState = {}, this._showPhase = J.Setup, this._timerState = null, this._mediaConfig = null, this.audioOutputs = void 0, this._selectedAudioOutput = "", this.currentState = { ...r }, this.store = new de(_ ?? {});
|
|
473
|
+
const { useReconnectingWebsocket: p, path: v, pathParams: f } = ve(document.location.href);
|
|
474
|
+
this.urlParams = new URLSearchParams(f), this.urlParams.set("screenWidth", window.screen.width.toString()), this.urlParams.set("screenHeight", window.screen.height.toString()), this.urlParams.set("screenPixelRatio", window.devicePixelRatio.toString());
|
|
475
|
+
const y = `ws://${s}:${o}${v}?${this.urlParams}`;
|
|
476
|
+
this.websocket = p ? new ae(y) : new WebSocket(y), this.websocket.onopen = () => {
|
|
477
|
+
this.currentConfig = {}, this.currentState = {}, this.dispatchEvent(new me()), this.setState(this.currentState);
|
|
478
|
+
};
|
|
479
|
+
const C = he({
|
|
480
|
+
interval: 6e4,
|
|
481
|
+
send: (h) => {
|
|
482
|
+
this.websocket.send(JSON.stringify(h));
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
this.websocket.addEventListener("message", ({ data: h }) => {
|
|
486
|
+
try {
|
|
487
|
+
const e = JSON.parse(h);
|
|
488
|
+
if (typeof e == "object" && e !== null && "timesync" in e) {
|
|
489
|
+
const t = e;
|
|
490
|
+
C.receive(t);
|
|
491
|
+
}
|
|
492
|
+
} catch (e) {
|
|
493
|
+
console.error(e);
|
|
494
|
+
}
|
|
495
|
+
}), this.websocket.onclose = () => {
|
|
496
|
+
C.destroy(), this.dispatchEvent(new ye());
|
|
497
|
+
}, this.websocket.addEventListener("message", ({ data: h }) => {
|
|
498
|
+
try {
|
|
499
|
+
const e = JSON.parse(h);
|
|
500
|
+
try {
|
|
501
|
+
if (e.config)
|
|
502
|
+
this.currentConfig = e.config, this.dispatchEvent(new be(this.currentConfig));
|
|
503
|
+
else if (e.updates)
|
|
504
|
+
this.currentState = { ...this.currentState, ...e.updates }, this.dispatchEvent(new Ce(e.updates));
|
|
505
|
+
else if (e.event && e.event.key)
|
|
506
|
+
this.dispatchEvent(
|
|
507
|
+
new we(e.event.key, e.event.value)
|
|
508
|
+
);
|
|
509
|
+
else if (typeof e.message == "object") {
|
|
510
|
+
const t = e.message;
|
|
511
|
+
switch (t.type) {
|
|
512
|
+
case "adjustable_timer_update":
|
|
513
|
+
this._timerState = {
|
|
514
|
+
startedAt: Date.now(),
|
|
515
|
+
durationMillis: t.durationMillis,
|
|
516
|
+
ticking: t.ticking
|
|
517
|
+
};
|
|
518
|
+
break;
|
|
519
|
+
case "show_phase":
|
|
520
|
+
this._showPhase = t.phase, this.dispatchEvent(new Se(t.phase));
|
|
521
|
+
break;
|
|
522
|
+
case "media_config_update":
|
|
523
|
+
this._mediaConfig = t;
|
|
524
|
+
for (const i of ["preferOptimizedAudio", "preferOptimizedVideo", "preferOptimizedImages"])
|
|
525
|
+
t[i] ? this.urlParams.set(i, "true") : this.urlParams.delete(i);
|
|
526
|
+
this.dispatchEvent(new Ee(t));
|
|
527
|
+
break;
|
|
528
|
+
case "data_store_items":
|
|
529
|
+
this.store.handleDataStoreItemsMessage(t);
|
|
530
|
+
break;
|
|
531
|
+
}
|
|
532
|
+
this.dispatchEvent(new ge(t));
|
|
533
|
+
}
|
|
534
|
+
} catch (t) {
|
|
535
|
+
console.warn("Error handling data", h, t);
|
|
536
|
+
}
|
|
537
|
+
} catch (e) {
|
|
538
|
+
console.error("Unable to parse incoming data from server", h, e);
|
|
539
|
+
}
|
|
540
|
+
}), this.store.addEventListener("items", (h) => {
|
|
541
|
+
this.sendDataStoreItems(h.items);
|
|
542
|
+
});
|
|
543
|
+
{
|
|
544
|
+
const h = async () => {
|
|
545
|
+
if (navigator.mediaDevices) {
|
|
546
|
+
const e = (await navigator.mediaDevices.enumerateDevices()).filter(({ kind: t }) => t === "audiooutput");
|
|
547
|
+
this.sendAudioOutputs(e), this.audioOutputs = e;
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
this.eventTarget.addEventListener("open", h), navigator.mediaDevices?.addEventListener("devicechange", h), h();
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
// Received on open connection
|
|
554
|
+
get config() {
|
|
555
|
+
return { ...this.currentConfig };
|
|
556
|
+
}
|
|
557
|
+
// Received on open connection - TODO: set initial state from manifest?
|
|
558
|
+
get state() {
|
|
559
|
+
return { ...this.currentState };
|
|
560
|
+
}
|
|
561
|
+
get showPhase() {
|
|
562
|
+
return this._showPhase;
|
|
563
|
+
}
|
|
564
|
+
get timerState() {
|
|
565
|
+
return this._timerState ? { ...this._timerState } : null;
|
|
566
|
+
}
|
|
567
|
+
get mediaConfig() {
|
|
568
|
+
return this._mediaConfig ? { ...this._mediaConfig } : null;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Return asset URLs using the information about the client and server support for HTTP/2
|
|
572
|
+
*/
|
|
573
|
+
getAssetUrl(n) {
|
|
574
|
+
return `${ue(n)}?${this.urlParams?.toString() ?? ""}`;
|
|
575
|
+
}
|
|
576
|
+
get selectedAudioOutput() {
|
|
577
|
+
return this._selectedAudioOutput;
|
|
578
|
+
}
|
|
579
|
+
get isConnected() {
|
|
580
|
+
return this.websocket.readyState === WebSocket.OPEN;
|
|
581
|
+
}
|
|
582
|
+
close() {
|
|
583
|
+
this.websocket.close();
|
|
584
|
+
}
|
|
585
|
+
sendEvent(n, ...[s]) {
|
|
586
|
+
this.isConnected && this.websocket.send(
|
|
587
|
+
JSON.stringify({
|
|
588
|
+
event: {
|
|
589
|
+
key: n,
|
|
590
|
+
value: s
|
|
591
|
+
}
|
|
592
|
+
})
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
setState(n) {
|
|
596
|
+
this.currentState = { ...this.currentState, ...n }, this.isConnected && this.websocket.send(JSON.stringify({ updates: n }));
|
|
597
|
+
}
|
|
598
|
+
getAudioSinkId(n) {
|
|
599
|
+
return n ? this.audioOutputs?.find(({ label: s }) => s === n)?.deviceId : "";
|
|
600
|
+
}
|
|
601
|
+
sendInitialMediaClipStates(n) {
|
|
602
|
+
this.isConnected && this.websocket.send(JSON.stringify({ allMediaClipStates: n }));
|
|
603
|
+
}
|
|
604
|
+
sendMediaClipState(n) {
|
|
605
|
+
this.isConnected && this.websocket.send(JSON.stringify({ mediaClipState: n }));
|
|
606
|
+
}
|
|
607
|
+
sendAudioOutputs(n) {
|
|
608
|
+
this.isConnected && this.websocket.send(JSON.stringify({ audioOutputs: n }));
|
|
609
|
+
}
|
|
610
|
+
sendDataStoreItems(n) {
|
|
611
|
+
this.isConnected && this.websocket.send(JSON.stringify({ dataStoreItems: n }));
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Show or hide the plugin window.
|
|
615
|
+
* @param visible Whether to show or hide the window
|
|
616
|
+
* This is only relevant for plugins, not for Media Master content.
|
|
617
|
+
*/
|
|
618
|
+
setPluginWindowVisible(n) {
|
|
619
|
+
this.isConnected && this.websocket.send(JSON.stringify({ window: { visible: n } }));
|
|
620
|
+
}
|
|
621
|
+
// Type-safe wrapper around EventTarget
|
|
622
|
+
addEventListener(n, s, o) {
|
|
623
|
+
this.eventTarget.addEventListener(n, s, o);
|
|
624
|
+
}
|
|
625
|
+
removeEventListener(n, s, o) {
|
|
626
|
+
this.eventTarget.removeEventListener(n, s, o);
|
|
627
|
+
}
|
|
628
|
+
dispatchEvent(n) {
|
|
629
|
+
this.eventTarget.dispatchEvent(n);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
function ve(u) {
|
|
633
|
+
const n = new URL(u), s = new URLSearchParams(n.searchParams), o = s.get("local_id"), r = s.get("simulator") === "true", _ = s.get("display") ?? "", p = n.pathname.startsWith("/plugin/") ? decodeURIComponent(n.pathname.split("/")[2]) : void 0;
|
|
634
|
+
if (o) {
|
|
635
|
+
const v = s.get("t") ?? "";
|
|
636
|
+
return s.delete("local_id"), {
|
|
637
|
+
path: `/local/${encodeURIComponent(o)}`,
|
|
638
|
+
pathParams: new URLSearchParams({ t: v }),
|
|
639
|
+
useReconnectingWebsocket: !0
|
|
640
|
+
};
|
|
641
|
+
} else if (r) {
|
|
642
|
+
const v = s.get("name") ?? "";
|
|
643
|
+
return s.delete("simulator"), s.delete("name"), {
|
|
644
|
+
path: `/simulator/${encodeURIComponent(v)}`,
|
|
645
|
+
pathParams: s,
|
|
646
|
+
useReconnectingWebsocket: !0
|
|
647
|
+
};
|
|
648
|
+
} else if (_) {
|
|
649
|
+
const v = s.get("displayIdIndex") ?? "";
|
|
650
|
+
return s.delete("display"), s.delete("displayIdIndex"), {
|
|
651
|
+
path: `/display/${encodeURIComponent(_)}/${encodeURIComponent(v)}`
|
|
652
|
+
};
|
|
653
|
+
} else {
|
|
654
|
+
if (p)
|
|
655
|
+
return {
|
|
656
|
+
path: `/plugin/${encodeURIComponent(p)}`,
|
|
657
|
+
useReconnectingWebsocket: !0
|
|
658
|
+
};
|
|
659
|
+
{
|
|
660
|
+
const v = s.get("serial") ?? "";
|
|
661
|
+
return s.delete("serial"), {
|
|
662
|
+
path: `/client/${encodeURIComponent(v)}`,
|
|
663
|
+
pathParams: s
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
class me extends Event {
|
|
669
|
+
constructor() {
|
|
670
|
+
super("open"), this._cogsConnectionEventType = "open";
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
class ye extends Event {
|
|
674
|
+
constructor() {
|
|
675
|
+
super("close"), this._cogsConnectionEventType = "close";
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
class ge extends Event {
|
|
679
|
+
constructor(n) {
|
|
680
|
+
super("message"), this.message = n, this._cogsConnectionEventType = "message";
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
class be extends Event {
|
|
684
|
+
constructor(n) {
|
|
685
|
+
super("config"), this.config = n, this._cogsConnectionEventType = "config";
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
class Ce extends Event {
|
|
689
|
+
constructor(n) {
|
|
690
|
+
super("state"), this.state = n, this._cogsConnectionEventType = "state";
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
class we extends Event {
|
|
694
|
+
constructor(n, s) {
|
|
695
|
+
super("event"), this.name = n, this.value = s, this._cogsConnectionEventType = "event";
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
class Ee extends Event {
|
|
699
|
+
constructor(n) {
|
|
700
|
+
super("mediaConfig"), this.mediaConfig = n, this._cogsConnectionEventType = "mediaConfig";
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
class Se extends Event {
|
|
704
|
+
constructor(n) {
|
|
705
|
+
super("showPhase"), this.showPhase = n, this._cogsConnectionEventType = "showPhase";
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
var j = {}, G;
|
|
709
|
+
function Ae() {
|
|
710
|
+
return G || (G = 1, function(u) {
|
|
711
|
+
var n = {};
|
|
712
|
+
/*! howler.js v2.2.1 | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */
|
|
713
|
+
(function() {
|
|
714
|
+
var s = function() {
|
|
715
|
+
this.init();
|
|
716
|
+
};
|
|
717
|
+
s.prototype = { init: function() {
|
|
718
|
+
var e = this || o;
|
|
719
|
+
return e._counter = 1e3, e._html5AudioPool = [], e.html5PoolSize = 10, e._codecs = {}, e._howls = [], e._muted = !1, e._volume = 1, e._canPlayEvent = "canplaythrough", e._navigator = typeof window < "u" && window.navigator ? window.navigator : null, e.masterGain = null, e.noAudio = !1, e.usingWebAudio = !0, e.autoSuspend = !0, e.ctx = null, e.autoUnlock = !0, e._setup(), e;
|
|
720
|
+
}, volume: function(e) {
|
|
721
|
+
var t = this || o;
|
|
722
|
+
if (e = parseFloat(e), t.ctx || h(), e !== void 0 && e >= 0 && e <= 1) {
|
|
723
|
+
if (t._volume = e, t._muted) return t;
|
|
724
|
+
t.usingWebAudio && t.masterGain.gain.setValueAtTime(e, o.ctx.currentTime);
|
|
725
|
+
for (var i = 0; i < t._howls.length; i++) if (!t._howls[i]._webAudio) for (var a = t._howls[i]._getSoundIds(), d = 0; d < a.length; d++) {
|
|
726
|
+
var c = t._howls[i]._soundById(a[d]);
|
|
727
|
+
c && c._node && (c._node.volume = c._volume * e);
|
|
728
|
+
}
|
|
729
|
+
return t;
|
|
730
|
+
}
|
|
731
|
+
return t._volume;
|
|
732
|
+
}, mute: function(e) {
|
|
733
|
+
var t = this || o;
|
|
734
|
+
t.ctx || h(), t._muted = e, t.usingWebAudio && t.masterGain.gain.setValueAtTime(e ? 0 : t._volume, o.ctx.currentTime);
|
|
735
|
+
for (var i = 0; i < t._howls.length; i++) if (!t._howls[i]._webAudio) for (var a = t._howls[i]._getSoundIds(), d = 0; d < a.length; d++) {
|
|
736
|
+
var c = t._howls[i]._soundById(a[d]);
|
|
737
|
+
c && c._node && (c._node.muted = !!e || c._muted);
|
|
738
|
+
}
|
|
739
|
+
return t;
|
|
740
|
+
}, stop: function() {
|
|
741
|
+
for (var e = this || o, t = 0; t < e._howls.length; t++) e._howls[t].stop();
|
|
742
|
+
return e;
|
|
743
|
+
}, unload: function() {
|
|
744
|
+
for (var e = this || o, t = e._howls.length - 1; t >= 0; t--) e._howls[t].unload();
|
|
745
|
+
return e.usingWebAudio && e.ctx && e.ctx.close !== void 0 && (e.ctx.close(), e.ctx = null, h()), e;
|
|
746
|
+
}, codecs: function(e) {
|
|
747
|
+
return (this || o)._codecs[e.replace(/^x-/, "")];
|
|
748
|
+
}, _setup: function() {
|
|
749
|
+
var e = this || o;
|
|
750
|
+
if (e.state = e.ctx && e.ctx.state || "suspended", e._autoSuspend(), !e.usingWebAudio) if (typeof Audio < "u") try {
|
|
751
|
+
var t = new Audio();
|
|
752
|
+
t.oncanplaythrough === void 0 && (e._canPlayEvent = "canplay");
|
|
753
|
+
} catch {
|
|
754
|
+
e.noAudio = !0;
|
|
755
|
+
}
|
|
756
|
+
else e.noAudio = !0;
|
|
757
|
+
try {
|
|
758
|
+
var t = new Audio();
|
|
759
|
+
t.muted && (e.noAudio = !0);
|
|
760
|
+
} catch {
|
|
761
|
+
}
|
|
762
|
+
return e.noAudio || e._setupCodecs(), e;
|
|
763
|
+
}, _setupCodecs: function() {
|
|
764
|
+
var e = this || o, t = null;
|
|
765
|
+
try {
|
|
766
|
+
t = typeof Audio < "u" ? new Audio() : null;
|
|
767
|
+
} catch {
|
|
768
|
+
return e;
|
|
769
|
+
}
|
|
770
|
+
if (!t || typeof t.canPlayType != "function") return e;
|
|
771
|
+
var i = t.canPlayType("audio/mpeg;").replace(/^no$/, ""), a = e._navigator && e._navigator.userAgent.match(/OPR\/([0-6].)/g), d = a && parseInt(a[0].split("/")[1], 10) < 33;
|
|
772
|
+
return e._codecs = { mp3: !(d || !i && !t.canPlayType("audio/mp3;").replace(/^no$/, "")), mpeg: !!i, opus: !!t.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, ""), ogg: !!t.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ""), oga: !!t.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ""), wav: !!(t.canPlayType('audio/wav; codecs="1"') || t.canPlayType("audio/wav")).replace(/^no$/, ""), aac: !!t.canPlayType("audio/aac;").replace(/^no$/, ""), caf: !!t.canPlayType("audio/x-caf;").replace(/^no$/, ""), m4a: !!(t.canPlayType("audio/x-m4a;") || t.canPlayType("audio/m4a;") || t.canPlayType("audio/aac;")).replace(/^no$/, ""), m4b: !!(t.canPlayType("audio/x-m4b;") || t.canPlayType("audio/m4b;") || t.canPlayType("audio/aac;")).replace(/^no$/, ""), mp4: !!(t.canPlayType("audio/x-mp4;") || t.canPlayType("audio/mp4;") || t.canPlayType("audio/aac;")).replace(/^no$/, ""), weba: !!t.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, ""), webm: !!t.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, ""), dolby: !!t.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/, ""), flac: !!(t.canPlayType("audio/x-flac;") || t.canPlayType("audio/flac;")).replace(/^no$/, "") }, e;
|
|
773
|
+
}, _unlockAudio: function() {
|
|
774
|
+
var e = this || o;
|
|
775
|
+
if (!e._audioUnlocked && e.ctx) {
|
|
776
|
+
e._audioUnlocked = !1, e.autoUnlock = !1, e._mobileUnloaded || e.ctx.sampleRate === 44100 || (e._mobileUnloaded = !0, e.unload()), e._scratchBuffer = e.ctx.createBuffer(1, 1, 22050);
|
|
777
|
+
var t = function(i) {
|
|
778
|
+
for (; e._html5AudioPool.length < e.html5PoolSize; ) try {
|
|
779
|
+
var a = new Audio();
|
|
780
|
+
a._unlocked = !0, e._releaseHtml5Audio(a);
|
|
781
|
+
} catch {
|
|
782
|
+
e.noAudio = !0;
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
for (var d = 0; d < e._howls.length; d++) if (!e._howls[d]._webAudio) for (var c = e._howls[d]._getSoundIds(), l = 0; l < c.length; l++) {
|
|
786
|
+
var m = e._howls[d]._soundById(c[l]);
|
|
787
|
+
m && m._node && !m._node._unlocked && (m._node._unlocked = !0, m._node.load());
|
|
788
|
+
}
|
|
789
|
+
e._autoResume();
|
|
790
|
+
var g = e.ctx.createBufferSource();
|
|
791
|
+
g.buffer = e._scratchBuffer, g.connect(e.ctx.destination), g.start === void 0 ? g.noteOn(0) : g.start(0), typeof e.ctx.resume == "function" && e.ctx.resume(), g.onended = function() {
|
|
792
|
+
g.disconnect(0), e._audioUnlocked = !0, document.removeEventListener("touchstart", t, !0), document.removeEventListener("touchend", t, !0), document.removeEventListener("click", t, !0);
|
|
793
|
+
for (var w = 0; w < e._howls.length; w++) e._howls[w]._emit("unlock");
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
return document.addEventListener("touchstart", t, !0), document.addEventListener("touchend", t, !0), document.addEventListener("click", t, !0), e;
|
|
797
|
+
}
|
|
798
|
+
}, _obtainHtml5Audio: function() {
|
|
799
|
+
var e = this || o;
|
|
800
|
+
if (e._html5AudioPool.length) return e._html5AudioPool.pop();
|
|
801
|
+
var t = new Audio().play();
|
|
802
|
+
return t && typeof Promise < "u" && (t instanceof Promise || typeof t.then == "function") && t.catch(function() {
|
|
803
|
+
console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.");
|
|
804
|
+
}), new Audio();
|
|
805
|
+
}, _releaseHtml5Audio: function(e) {
|
|
806
|
+
var t = this || o;
|
|
807
|
+
return e._unlocked && t._html5AudioPool.push(e), t;
|
|
808
|
+
}, _autoSuspend: function() {
|
|
809
|
+
var e = this;
|
|
810
|
+
if (e.autoSuspend && e.ctx && e.ctx.suspend !== void 0 && o.usingWebAudio) {
|
|
811
|
+
for (var t = 0; t < e._howls.length; t++) if (e._howls[t]._webAudio) {
|
|
812
|
+
for (var i = 0; i < e._howls[t]._sounds.length; i++) if (!e._howls[t]._sounds[i]._paused) return e;
|
|
813
|
+
}
|
|
814
|
+
return e._suspendTimer && clearTimeout(e._suspendTimer), e._suspendTimer = setTimeout(function() {
|
|
815
|
+
if (e.autoSuspend) {
|
|
816
|
+
e._suspendTimer = null, e.state = "suspending";
|
|
817
|
+
var a = function() {
|
|
818
|
+
e.state = "suspended", e._resumeAfterSuspend && (delete e._resumeAfterSuspend, e._autoResume());
|
|
819
|
+
};
|
|
820
|
+
e.ctx.suspend().then(a, a);
|
|
821
|
+
}
|
|
822
|
+
}, 3e4), e;
|
|
823
|
+
}
|
|
824
|
+
}, _autoResume: function() {
|
|
825
|
+
var e = this;
|
|
826
|
+
if (e.ctx && e.ctx.resume !== void 0 && o.usingWebAudio) return e.state === "running" && e.ctx.state !== "interrupted" && e._suspendTimer ? (clearTimeout(e._suspendTimer), e._suspendTimer = null) : e.state === "suspended" || e.state === "running" && e.ctx.state === "interrupted" ? (e.ctx.resume().then(function() {
|
|
827
|
+
e.state = "running";
|
|
828
|
+
for (var t = 0; t < e._howls.length; t++) e._howls[t]._emit("resume");
|
|
829
|
+
}), e._suspendTimer && (clearTimeout(e._suspendTimer), e._suspendTimer = null)) : e.state === "suspending" && (e._resumeAfterSuspend = !0), e;
|
|
830
|
+
} };
|
|
831
|
+
var o = new s(), r = function(e) {
|
|
832
|
+
var t = this;
|
|
833
|
+
if (!e.src || e.src.length === 0) return void console.error("An array of source files must be passed with any new Howl.");
|
|
834
|
+
t.init(e);
|
|
835
|
+
};
|
|
836
|
+
r.prototype = { init: function(e) {
|
|
837
|
+
var t = this;
|
|
838
|
+
return o.ctx || h(), t._autoplay = e.autoplay || !1, t._format = typeof e.format != "string" ? e.format : [e.format], t._html5 = e.html5 || !1, t._muted = e.mute || !1, t._loop = e.loop || !1, t._pool = e.pool || 5, t._preload = typeof e.preload != "boolean" && e.preload !== "metadata" || e.preload, t._rate = e.rate || 1, t._sprite = e.sprite || {}, t._src = typeof e.src != "string" ? e.src : [e.src], t._volume = e.volume !== void 0 ? e.volume : 1, t._xhr = { method: e.xhr && e.xhr.method ? e.xhr.method : "GET", headers: e.xhr && e.xhr.headers ? e.xhr.headers : null, withCredentials: !(!e.xhr || !e.xhr.withCredentials) && e.xhr.withCredentials }, t._duration = 0, t._state = "unloaded", t._sounds = [], t._endTimers = {}, t._queue = [], t._playLock = !1, t._onend = e.onend ? [{ fn: e.onend }] : [], t._onfade = e.onfade ? [{ fn: e.onfade }] : [], t._onload = e.onload ? [{ fn: e.onload }] : [], t._onloaderror = e.onloaderror ? [{ fn: e.onloaderror }] : [], t._onplayerror = e.onplayerror ? [{ fn: e.onplayerror }] : [], t._onpause = e.onpause ? [{ fn: e.onpause }] : [], t._onplay = e.onplay ? [{ fn: e.onplay }] : [], t._onstop = e.onstop ? [{ fn: e.onstop }] : [], t._onmute = e.onmute ? [{ fn: e.onmute }] : [], t._onvolume = e.onvolume ? [{ fn: e.onvolume }] : [], t._onrate = e.onrate ? [{ fn: e.onrate }] : [], t._onseek = e.onseek ? [{ fn: e.onseek }] : [], t._onunlock = e.onunlock ? [{ fn: e.onunlock }] : [], t._onresume = [], t._webAudio = o.usingWebAudio && !t._html5, o.ctx !== void 0 && o.ctx && o.autoUnlock && o._unlockAudio(), o._howls.push(t), t._autoplay && t._queue.push({ event: "play", action: function() {
|
|
839
|
+
t.play();
|
|
840
|
+
} }), t._preload && t._preload !== "none" && t.load(), t;
|
|
841
|
+
}, load: function() {
|
|
842
|
+
var e = this, t = null;
|
|
843
|
+
if (o.noAudio) return void e._emit("loaderror", null, "No audio support.");
|
|
844
|
+
typeof e._src == "string" && (e._src = [e._src]);
|
|
845
|
+
for (var i = 0; i < e._src.length; i++) {
|
|
846
|
+
var a, d;
|
|
847
|
+
if (e._format && e._format[i]) a = e._format[i];
|
|
848
|
+
else {
|
|
849
|
+
if (typeof (d = e._src[i]) != "string") {
|
|
850
|
+
e._emit("loaderror", null, "Non-string found in selected audio sources - ignoring.");
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
a = /^data:audio\/([^;,]+);/i.exec(d), a || (a = /\.([^.]+)$/.exec(d.split("?", 1)[0])), a && (a = a[1].toLowerCase());
|
|
854
|
+
}
|
|
855
|
+
if (a || console.warn('No file extension was found. Consider using the "format" property or specify an extension.'), a && o.codecs(a)) {
|
|
856
|
+
t = e._src[i];
|
|
857
|
+
break;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return t ? (e._src = t, e._state = "loading", window.location.protocol === "https:" && t.slice(0, 5) === "http:" && (e._html5 = !0, e._webAudio = !1), new _(e), e._webAudio && v(e), e) : void e._emit("loaderror", null, "No codec support for selected audio sources.");
|
|
861
|
+
}, play: function(e, t) {
|
|
862
|
+
var i = this, a = null;
|
|
863
|
+
if (typeof e == "number") a = e, e = null;
|
|
864
|
+
else {
|
|
865
|
+
if (typeof e == "string" && i._state === "loaded" && !i._sprite[e]) return null;
|
|
866
|
+
if (e === void 0 && (e = "__default", !i._playLock)) {
|
|
867
|
+
for (var d = 0, c = 0; c < i._sounds.length; c++) i._sounds[c]._paused && !i._sounds[c]._ended && (d++, a = i._sounds[c]._id);
|
|
868
|
+
d === 1 ? e = null : a = null;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
var l = a ? i._soundById(a) : i._inactiveSound();
|
|
872
|
+
if (!l) return null;
|
|
873
|
+
if (a && !e && (e = l._sprite || "__default"), i._state !== "loaded") {
|
|
874
|
+
l._sprite = e, l._ended = !1;
|
|
875
|
+
var m = l._id;
|
|
876
|
+
return i._queue.push({ event: "play", action: function() {
|
|
877
|
+
i.play(m);
|
|
878
|
+
} }), m;
|
|
879
|
+
}
|
|
880
|
+
if (a && !l._paused) return t || i._loadQueue("play"), l._id;
|
|
881
|
+
i._webAudio && o._autoResume();
|
|
882
|
+
var g = Math.max(0, l._seek > 0 ? l._seek : i._sprite[e][0] / 1e3), w = Math.max(0, (i._sprite[e][0] + i._sprite[e][1]) / 1e3 - g), E = 1e3 * w / Math.abs(l._rate), S = i._sprite[e][0] / 1e3, O = (i._sprite[e][0] + i._sprite[e][1]) / 1e3;
|
|
883
|
+
l._sprite = e, l._ended = !1;
|
|
884
|
+
var I = function() {
|
|
885
|
+
l._paused = !1, l._seek = g, l._start = S, l._stop = O, l._loop = !(!l._loop && !i._sprite[e][2]);
|
|
886
|
+
};
|
|
887
|
+
if (g >= O) return void i._ended(l);
|
|
888
|
+
var b = l._node;
|
|
889
|
+
if (i._webAudio) {
|
|
890
|
+
var U = function() {
|
|
891
|
+
i._playLock = !1, I(), i._refreshBuffer(l);
|
|
892
|
+
var T = l._muted || i._muted ? 0 : l._volume;
|
|
893
|
+
b.gain.setValueAtTime(T, o.ctx.currentTime), l._playStart = o.ctx.currentTime, b.bufferSource.start === void 0 ? l._loop ? b.bufferSource.noteGrainOn(0, g, 86400) : b.bufferSource.noteGrainOn(0, g, w) : l._loop ? b.bufferSource.start(0, g, 86400) : b.bufferSource.start(0, g, w), E !== 1 / 0 && (i._endTimers[l._id] = setTimeout(i._ended.bind(i, l), E)), t || setTimeout(function() {
|
|
894
|
+
i._emit("play", l._id), i._loadQueue();
|
|
895
|
+
}, 0);
|
|
896
|
+
};
|
|
897
|
+
o.state === "running" && o.ctx.state !== "interrupted" ? U() : (i._playLock = !0, i.once("resume", U), i._clearTimer(l._id));
|
|
898
|
+
} else {
|
|
899
|
+
var B = function() {
|
|
900
|
+
b.currentTime = g, b.muted = l._muted || i._muted || o._muted || b.muted, b.volume = l._volume * o.volume(), b.playbackRate = l._rate;
|
|
901
|
+
try {
|
|
902
|
+
var T = b.play();
|
|
903
|
+
if (T && typeof Promise < "u" && (T instanceof Promise || typeof T.then == "function") ? (i._playLock = !0, I(), T.then(function() {
|
|
904
|
+
i._playLock = !1, b._unlocked = !0, t || (i._emit("play", l._id), i._loadQueue());
|
|
905
|
+
}).catch(function() {
|
|
906
|
+
i._playLock = !1, i._emit("playerror", l._id, "Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction."), l._ended = !0, l._paused = !0;
|
|
907
|
+
})) : t || (i._playLock = !1, I(), i._emit("play", l._id), i._loadQueue()), b.playbackRate = l._rate, b.paused) return void i._emit("playerror", l._id, "Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");
|
|
908
|
+
e !== "__default" || l._loop ? i._endTimers[l._id] = setTimeout(i._ended.bind(i, l), E) : (i._endTimers[l._id] = function() {
|
|
909
|
+
i._ended(l), b.removeEventListener("ended", i._endTimers[l._id], !1);
|
|
910
|
+
}, b.addEventListener("ended", i._endTimers[l._id], !1));
|
|
911
|
+
} catch (K) {
|
|
912
|
+
i._emit("playerror", l._id, K);
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
b.src === "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA" && (b.src = i._src, b.load());
|
|
916
|
+
var Z = window && window.ejecta || !b.readyState && o._navigator.isCocoonJS;
|
|
917
|
+
if (b.readyState >= 3 || Z) B();
|
|
918
|
+
else {
|
|
919
|
+
i._playLock = !0;
|
|
920
|
+
var M = function() {
|
|
921
|
+
B(), b.removeEventListener(o._canPlayEvent, M, !1);
|
|
922
|
+
};
|
|
923
|
+
b.addEventListener(o._canPlayEvent, M, !1), i._clearTimer(l._id);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return l._id;
|
|
927
|
+
}, pause: function(e) {
|
|
928
|
+
var t = this;
|
|
929
|
+
if (t._state !== "loaded" || t._playLock) return t._queue.push({ event: "pause", action: function() {
|
|
930
|
+
t.pause(e);
|
|
931
|
+
} }), t;
|
|
932
|
+
for (var i = t._getSoundIds(e), a = 0; a < i.length; a++) {
|
|
933
|
+
t._clearTimer(i[a]);
|
|
934
|
+
var d = t._soundById(i[a]);
|
|
935
|
+
if (d && !d._paused && (d._seek = t.seek(i[a]), d._rateSeek = 0, d._paused = !0, t._stopFade(i[a]), d._node)) if (t._webAudio) {
|
|
936
|
+
if (!d._node.bufferSource) continue;
|
|
937
|
+
d._node.bufferSource.stop === void 0 ? d._node.bufferSource.noteOff(0) : d._node.bufferSource.stop(0), t._cleanBuffer(d._node);
|
|
938
|
+
} else isNaN(d._node.duration) && d._node.duration !== 1 / 0 || d._node.pause();
|
|
939
|
+
arguments[1] || t._emit("pause", d ? d._id : null);
|
|
940
|
+
}
|
|
941
|
+
return t;
|
|
942
|
+
}, stop: function(e, t) {
|
|
943
|
+
var i = this;
|
|
944
|
+
if (i._state !== "loaded" || i._playLock) return i._queue.push({ event: "stop", action: function() {
|
|
945
|
+
i.stop(e, t);
|
|
946
|
+
} }), i;
|
|
947
|
+
for (var a = i._getSoundIds(e), d = 0; d < a.length; d++) {
|
|
948
|
+
i._clearTimer(a[d]);
|
|
949
|
+
var c = i._soundById(a[d]);
|
|
950
|
+
c && (c._seek = c._start || 0, c._rateSeek = 0, c._paused = !0, c._ended = !0, i._stopFade(a[d]), c._node && (i._webAudio ? c._node.bufferSource && (c._node.bufferSource.stop === void 0 ? c._node.bufferSource.noteOff(0) : c._node.bufferSource.stop(0), i._cleanBuffer(c._node)) : isNaN(c._node.duration) && c._node.duration !== 1 / 0 || (c._node.currentTime = c._start || 0, c._node.pause(), c._node.duration === 1 / 0 && i._clearSound(c._node))), t || i._emit("stop", c._id));
|
|
951
|
+
}
|
|
952
|
+
return i;
|
|
953
|
+
}, mute: function(e, t) {
|
|
954
|
+
var i = this;
|
|
955
|
+
if (i._state !== "loaded" || i._playLock) return i._queue.push({ event: "mute", action: function() {
|
|
956
|
+
i.mute(e, t);
|
|
957
|
+
} }), i;
|
|
958
|
+
if (t === void 0) {
|
|
959
|
+
if (typeof e != "boolean") return i._muted;
|
|
960
|
+
i._muted = e;
|
|
961
|
+
}
|
|
962
|
+
for (var a = i._getSoundIds(t), d = 0; d < a.length; d++) {
|
|
963
|
+
var c = i._soundById(a[d]);
|
|
964
|
+
c && (c._muted = e, c._interval && i._stopFade(c._id), i._webAudio && c._node ? c._node.gain.setValueAtTime(e ? 0 : c._volume, o.ctx.currentTime) : c._node && (c._node.muted = !!o._muted || e), i._emit("mute", c._id));
|
|
965
|
+
}
|
|
966
|
+
return i;
|
|
967
|
+
}, volume: function() {
|
|
968
|
+
var e, t, i = this, a = arguments;
|
|
969
|
+
if (a.length === 0) return i._volume;
|
|
970
|
+
a.length === 1 || a.length === 2 && a[1] === void 0 ? i._getSoundIds().indexOf(a[0]) >= 0 ? t = parseInt(a[0], 10) : e = parseFloat(a[0]) : a.length >= 2 && (e = parseFloat(a[0]), t = parseInt(a[1], 10));
|
|
971
|
+
var d;
|
|
972
|
+
if (!(e !== void 0 && e >= 0 && e <= 1)) return d = t ? i._soundById(t) : i._sounds[0], d ? d._volume : 0;
|
|
973
|
+
if (i._state !== "loaded" || i._playLock) return i._queue.push({ event: "volume", action: function() {
|
|
974
|
+
i.volume.apply(i, a);
|
|
975
|
+
} }), i;
|
|
976
|
+
t === void 0 && (i._volume = e), t = i._getSoundIds(t);
|
|
977
|
+
for (var c = 0; c < t.length; c++) (d = i._soundById(t[c])) && (d._volume = e, a[2] || i._stopFade(t[c]), i._webAudio && d._node && !d._muted ? d._node.gain.setValueAtTime(e, o.ctx.currentTime) : d._node && !d._muted && (d._node.volume = e * o.volume()), i._emit("volume", d._id));
|
|
978
|
+
return i;
|
|
979
|
+
}, fade: function(e, t, i, a) {
|
|
980
|
+
var d = this;
|
|
981
|
+
if (d._state !== "loaded" || d._playLock) return d._queue.push({ event: "fade", action: function() {
|
|
982
|
+
d.fade(e, t, i, a);
|
|
983
|
+
} }), d;
|
|
984
|
+
e = Math.min(Math.max(0, parseFloat(e)), 1), t = Math.min(Math.max(0, parseFloat(t)), 1), i = parseFloat(i), d.volume(e, a);
|
|
985
|
+
for (var c = d._getSoundIds(a), l = 0; l < c.length; l++) {
|
|
986
|
+
var m = d._soundById(c[l]);
|
|
987
|
+
if (m) {
|
|
988
|
+
if (a || d._stopFade(c[l]), d._webAudio && !m._muted) {
|
|
989
|
+
var g = o.ctx.currentTime, w = g + i / 1e3;
|
|
990
|
+
m._volume = e, m._node.gain.setValueAtTime(e, g), m._node.gain.linearRampToValueAtTime(t, w);
|
|
991
|
+
}
|
|
992
|
+
d._startFadeInterval(m, e, t, i, c[l], a === void 0);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return d;
|
|
996
|
+
}, _startFadeInterval: function(e, t, i, a, d, c) {
|
|
997
|
+
var l = this, m = t, g = i - t, w = Math.abs(g / 0.01), E = Math.max(4, w > 0 ? a / w : a), S = Date.now();
|
|
998
|
+
e._fadeTo = i, e._interval = setInterval(function() {
|
|
999
|
+
var O = (Date.now() - S) / a;
|
|
1000
|
+
S = Date.now(), m += g * O, m = Math.round(100 * m) / 100, m = g < 0 ? Math.max(i, m) : Math.min(i, m), l._webAudio ? e._volume = m : l.volume(m, e._id, !0), c && (l._volume = m), (i < t && m <= i || i > t && m >= i) && (clearInterval(e._interval), e._interval = null, e._fadeTo = null, l.volume(i, e._id), l._emit("fade", e._id));
|
|
1001
|
+
}, E);
|
|
1002
|
+
}, _stopFade: function(e) {
|
|
1003
|
+
var t = this, i = t._soundById(e);
|
|
1004
|
+
return i && i._interval && (t._webAudio && i._node.gain.cancelScheduledValues(o.ctx.currentTime), clearInterval(i._interval), i._interval = null, t.volume(i._fadeTo, e), i._fadeTo = null, t._emit("fade", e)), t;
|
|
1005
|
+
}, loop: function() {
|
|
1006
|
+
var e, t, i, a = this, d = arguments;
|
|
1007
|
+
if (d.length === 0) return a._loop;
|
|
1008
|
+
if (d.length === 1) {
|
|
1009
|
+
if (typeof d[0] != "boolean") return !!(i = a._soundById(parseInt(d[0], 10))) && i._loop;
|
|
1010
|
+
e = d[0], a._loop = e;
|
|
1011
|
+
} else d.length === 2 && (e = d[0], t = parseInt(d[1], 10));
|
|
1012
|
+
for (var c = a._getSoundIds(t), l = 0; l < c.length; l++) (i = a._soundById(c[l])) && (i._loop = e, a._webAudio && i._node && i._node.bufferSource && (i._node.bufferSource.loop = e, e && (i._node.bufferSource.loopStart = i._start || 0, i._node.bufferSource.loopEnd = i._stop)));
|
|
1013
|
+
return a;
|
|
1014
|
+
}, rate: function() {
|
|
1015
|
+
var e, t, i = this, a = arguments;
|
|
1016
|
+
if (a.length === 0) t = i._sounds[0]._id;
|
|
1017
|
+
else if (a.length === 1) {
|
|
1018
|
+
var d = i._getSoundIds(), c = d.indexOf(a[0]);
|
|
1019
|
+
c >= 0 ? t = parseInt(a[0], 10) : e = parseFloat(a[0]);
|
|
1020
|
+
} else a.length === 2 && (e = parseFloat(a[0]), t = parseInt(a[1], 10));
|
|
1021
|
+
var l;
|
|
1022
|
+
if (typeof e != "number") return l = i._soundById(t), l ? l._rate : i._rate;
|
|
1023
|
+
if (i._state !== "loaded" || i._playLock) return i._queue.push({ event: "rate", action: function() {
|
|
1024
|
+
i.rate.apply(i, a);
|
|
1025
|
+
} }), i;
|
|
1026
|
+
t === void 0 && (i._rate = e), t = i._getSoundIds(t);
|
|
1027
|
+
for (var m = 0; m < t.length; m++) if (l = i._soundById(t[m])) {
|
|
1028
|
+
i.playing(t[m]) && (l._rateSeek = i.seek(t[m]), l._playStart = i._webAudio ? o.ctx.currentTime : l._playStart), l._rate = e, i._webAudio && l._node && l._node.bufferSource ? l._node.bufferSource.playbackRate.setValueAtTime(e, o.ctx.currentTime) : l._node && (l._node.playbackRate = e);
|
|
1029
|
+
var g = i.seek(t[m]), w = (i._sprite[l._sprite][0] + i._sprite[l._sprite][1]) / 1e3 - g, E = 1e3 * w / Math.abs(l._rate);
|
|
1030
|
+
!i._endTimers[t[m]] && l._paused || (i._clearTimer(t[m]), i._endTimers[t[m]] = setTimeout(i._ended.bind(i, l), E)), i._emit("rate", l._id);
|
|
1031
|
+
}
|
|
1032
|
+
return i;
|
|
1033
|
+
}, seek: function() {
|
|
1034
|
+
var e, t, i = this, a = arguments;
|
|
1035
|
+
if (a.length === 0) t = i._sounds[0]._id;
|
|
1036
|
+
else if (a.length === 1) {
|
|
1037
|
+
var d = i._getSoundIds(), c = d.indexOf(a[0]);
|
|
1038
|
+
c >= 0 ? t = parseInt(a[0], 10) : i._sounds.length && (t = i._sounds[0]._id, e = parseFloat(a[0]));
|
|
1039
|
+
} else a.length === 2 && (e = parseFloat(a[0]), t = parseInt(a[1], 10));
|
|
1040
|
+
if (t === void 0) return i;
|
|
1041
|
+
if (typeof e == "number" && (i._state !== "loaded" || i._playLock)) return i._queue.push({ event: "seek", action: function() {
|
|
1042
|
+
i.seek.apply(i, a);
|
|
1043
|
+
} }), i;
|
|
1044
|
+
var l = i._soundById(t);
|
|
1045
|
+
if (l) {
|
|
1046
|
+
if (!(typeof e == "number" && e >= 0)) {
|
|
1047
|
+
if (i._webAudio) {
|
|
1048
|
+
var m = i.playing(t) ? o.ctx.currentTime - l._playStart : 0, g = l._rateSeek ? l._rateSeek - l._seek : 0;
|
|
1049
|
+
return l._seek + (g + m * Math.abs(l._rate));
|
|
1050
|
+
}
|
|
1051
|
+
return l._node.currentTime;
|
|
1052
|
+
}
|
|
1053
|
+
var w = i.playing(t);
|
|
1054
|
+
w && i.pause(t, !0), l._seek = e, l._ended = !1, i._clearTimer(t), i._webAudio || !l._node || isNaN(l._node.duration) || (l._node.currentTime = e);
|
|
1055
|
+
var E = function() {
|
|
1056
|
+
i._emit("seek", t), w && i.play(t, !0);
|
|
1057
|
+
};
|
|
1058
|
+
if (w && !i._webAudio) {
|
|
1059
|
+
var S = function() {
|
|
1060
|
+
i._playLock ? setTimeout(S, 0) : E();
|
|
1061
|
+
};
|
|
1062
|
+
setTimeout(S, 0);
|
|
1063
|
+
} else E();
|
|
1064
|
+
}
|
|
1065
|
+
return i;
|
|
1066
|
+
}, playing: function(e) {
|
|
1067
|
+
var t = this;
|
|
1068
|
+
if (typeof e == "number") {
|
|
1069
|
+
var i = t._soundById(e);
|
|
1070
|
+
return !!i && !i._paused;
|
|
1071
|
+
}
|
|
1072
|
+
for (var a = 0; a < t._sounds.length; a++) if (!t._sounds[a]._paused) return !0;
|
|
1073
|
+
return !1;
|
|
1074
|
+
}, duration: function(e) {
|
|
1075
|
+
var t = this, i = t._duration, a = t._soundById(e);
|
|
1076
|
+
return a && (i = t._sprite[a._sprite][1] / 1e3), i;
|
|
1077
|
+
}, state: function() {
|
|
1078
|
+
return this._state;
|
|
1079
|
+
}, unload: function() {
|
|
1080
|
+
for (var e = this, t = e._sounds, i = 0; i < t.length; i++) t[i]._paused || e.stop(t[i]._id), e._webAudio || (e._clearSound(t[i]._node), t[i]._node.removeEventListener("error", t[i]._errorFn, !1), t[i]._node.removeEventListener(o._canPlayEvent, t[i]._loadFn, !1), t[i]._node.removeEventListener("ended", t[i]._endFn, !1), o._releaseHtml5Audio(t[i]._node)), delete t[i]._node, e._clearTimer(t[i]._id);
|
|
1081
|
+
var a = o._howls.indexOf(e);
|
|
1082
|
+
a >= 0 && o._howls.splice(a, 1);
|
|
1083
|
+
var d = !0;
|
|
1084
|
+
for (i = 0; i < o._howls.length; i++) if (o._howls[i]._src === e._src || e._src.indexOf(o._howls[i]._src) >= 0) {
|
|
1085
|
+
d = !1;
|
|
1086
|
+
break;
|
|
1087
|
+
}
|
|
1088
|
+
return p && d && delete p[e._src], o.noAudio = !1, e._state = "unloaded", e._sounds = [], e = null, null;
|
|
1089
|
+
}, on: function(e, t, i, a) {
|
|
1090
|
+
var d = this, c = d["_on" + e];
|
|
1091
|
+
return typeof t == "function" && c.push(a ? { id: i, fn: t, once: a } : { id: i, fn: t }), d;
|
|
1092
|
+
}, off: function(e, t, i) {
|
|
1093
|
+
var a = this, d = a["_on" + e], c = 0;
|
|
1094
|
+
if (typeof t == "number" && (i = t, t = null), t || i) for (c = 0; c < d.length; c++) {
|
|
1095
|
+
var l = i === d[c].id;
|
|
1096
|
+
if (t === d[c].fn && l || !t && l) {
|
|
1097
|
+
d.splice(c, 1);
|
|
1098
|
+
break;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
else if (e) a["_on" + e] = [];
|
|
1102
|
+
else {
|
|
1103
|
+
var m = Object.keys(a);
|
|
1104
|
+
for (c = 0; c < m.length; c++) m[c].indexOf("_on") === 0 && Array.isArray(a[m[c]]) && (a[m[c]] = []);
|
|
1105
|
+
}
|
|
1106
|
+
return a;
|
|
1107
|
+
}, once: function(e, t, i) {
|
|
1108
|
+
var a = this;
|
|
1109
|
+
return a.on(e, t, i, 1), a;
|
|
1110
|
+
}, _emit: function(e, t, i) {
|
|
1111
|
+
for (var a = this, d = a["_on" + e], c = d.length - 1; c >= 0; c--) d[c].id && d[c].id !== t && e !== "load" || (setTimeout((function(l) {
|
|
1112
|
+
l.call(this, t, i);
|
|
1113
|
+
}).bind(a, d[c].fn), 0), d[c].once && a.off(e, d[c].fn, d[c].id));
|
|
1114
|
+
return a._loadQueue(e), a;
|
|
1115
|
+
}, _loadQueue: function(e) {
|
|
1116
|
+
var t = this;
|
|
1117
|
+
if (t._queue.length > 0) {
|
|
1118
|
+
var i = t._queue[0];
|
|
1119
|
+
i.event === e && (t._queue.shift(), t._loadQueue()), e || i.action();
|
|
1120
|
+
}
|
|
1121
|
+
return t;
|
|
1122
|
+
}, _ended: function(e) {
|
|
1123
|
+
var t = this, i = e._sprite;
|
|
1124
|
+
if (!t._webAudio && e._node && !e._node.paused && !e._node.ended && e._node.currentTime < e._stop) return setTimeout(t._ended.bind(t, e), 100), t;
|
|
1125
|
+
var a = !(!e._loop && !t._sprite[i][2]);
|
|
1126
|
+
if (t._emit("end", e._id), !t._webAudio && a && t.stop(e._id, !0).play(e._id), t._webAudio && a) {
|
|
1127
|
+
t._emit("play", e._id), e._seek = e._start || 0, e._rateSeek = 0, e._playStart = o.ctx.currentTime;
|
|
1128
|
+
var d = 1e3 * (e._stop - e._start) / Math.abs(e._rate);
|
|
1129
|
+
t._endTimers[e._id] = setTimeout(t._ended.bind(t, e), d);
|
|
1130
|
+
}
|
|
1131
|
+
return t._webAudio && !a && (e._paused = !0, e._ended = !0, e._seek = e._start || 0, e._rateSeek = 0, t._clearTimer(e._id), t._cleanBuffer(e._node), o._autoSuspend()), t._webAudio || a || t.stop(e._id, !0), t;
|
|
1132
|
+
}, _clearTimer: function(e) {
|
|
1133
|
+
var t = this;
|
|
1134
|
+
if (t._endTimers[e]) {
|
|
1135
|
+
if (typeof t._endTimers[e] != "function") clearTimeout(t._endTimers[e]);
|
|
1136
|
+
else {
|
|
1137
|
+
var i = t._soundById(e);
|
|
1138
|
+
i && i._node && i._node.removeEventListener("ended", t._endTimers[e], !1);
|
|
1139
|
+
}
|
|
1140
|
+
delete t._endTimers[e];
|
|
1141
|
+
}
|
|
1142
|
+
return t;
|
|
1143
|
+
}, _soundById: function(e) {
|
|
1144
|
+
for (var t = this, i = 0; i < t._sounds.length; i++) if (e === t._sounds[i]._id) return t._sounds[i];
|
|
1145
|
+
return null;
|
|
1146
|
+
}, _inactiveSound: function() {
|
|
1147
|
+
var e = this;
|
|
1148
|
+
e._drain();
|
|
1149
|
+
for (var t = 0; t < e._sounds.length; t++) if (e._sounds[t]._ended) return e._sounds[t].reset();
|
|
1150
|
+
return new _(e);
|
|
1151
|
+
}, _drain: function() {
|
|
1152
|
+
var e = this, t = e._pool, i = 0, a = 0;
|
|
1153
|
+
if (!(e._sounds.length < t)) {
|
|
1154
|
+
for (a = 0; a < e._sounds.length; a++) e._sounds[a]._ended && i++;
|
|
1155
|
+
for (a = e._sounds.length - 1; a >= 0; a--) {
|
|
1156
|
+
if (i <= t) return;
|
|
1157
|
+
e._sounds[a]._ended && (e._webAudio && e._sounds[a]._node && e._sounds[a]._node.disconnect(0), e._sounds.splice(a, 1), i--);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}, _getSoundIds: function(e) {
|
|
1161
|
+
var t = this;
|
|
1162
|
+
if (e === void 0) {
|
|
1163
|
+
for (var i = [], a = 0; a < t._sounds.length; a++) i.push(t._sounds[a]._id);
|
|
1164
|
+
return i;
|
|
1165
|
+
}
|
|
1166
|
+
return [e];
|
|
1167
|
+
}, _refreshBuffer: function(e) {
|
|
1168
|
+
var t = this;
|
|
1169
|
+
return e._node.bufferSource = o.ctx.createBufferSource(), e._node.bufferSource.buffer = p[t._src], e._panner ? e._node.bufferSource.connect(e._panner) : e._node.bufferSource.connect(e._node), e._node.bufferSource.loop = e._loop, e._loop && (e._node.bufferSource.loopStart = e._start || 0, e._node.bufferSource.loopEnd = e._stop || 0), e._node.bufferSource.playbackRate.setValueAtTime(e._rate, o.ctx.currentTime), t;
|
|
1170
|
+
}, _cleanBuffer: function(e) {
|
|
1171
|
+
var t = this, i = o._navigator && o._navigator.vendor.indexOf("Apple") >= 0;
|
|
1172
|
+
if (o._scratchBuffer && e.bufferSource && (e.bufferSource.onended = null, e.bufferSource.disconnect(0), i)) try {
|
|
1173
|
+
e.bufferSource.buffer = o._scratchBuffer;
|
|
1174
|
+
} catch {
|
|
1175
|
+
}
|
|
1176
|
+
return e.bufferSource = null, t;
|
|
1177
|
+
}, _clearSound: function(e) {
|
|
1178
|
+
/MSIE |Trident\//.test(o._navigator && o._navigator.userAgent) || (e.src = "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA");
|
|
1179
|
+
} };
|
|
1180
|
+
var _ = function(e) {
|
|
1181
|
+
this._parent = e, this.init();
|
|
1182
|
+
};
|
|
1183
|
+
_.prototype = { init: function() {
|
|
1184
|
+
var e = this, t = e._parent;
|
|
1185
|
+
return e._muted = t._muted, e._loop = t._loop, e._volume = t._volume, e._rate = t._rate, e._seek = 0, e._paused = !0, e._ended = !0, e._sprite = "__default", e._id = ++o._counter, t._sounds.push(e), e.create(), e;
|
|
1186
|
+
}, create: function() {
|
|
1187
|
+
var e = this, t = e._parent, i = o._muted || e._muted || e._parent._muted ? 0 : e._volume;
|
|
1188
|
+
return t._webAudio ? (e._node = o.ctx.createGain === void 0 ? o.ctx.createGainNode() : o.ctx.createGain(), e._node.gain.setValueAtTime(i, o.ctx.currentTime), e._node.paused = !0, e._node.connect(o.masterGain)) : o.noAudio || (e._node = o._obtainHtml5Audio(), e._errorFn = e._errorListener.bind(e), e._node.addEventListener("error", e._errorFn, !1), e._loadFn = e._loadListener.bind(e), e._node.addEventListener(o._canPlayEvent, e._loadFn, !1), e._endFn = e._endListener.bind(e), e._node.addEventListener("ended", e._endFn, !1), e._node.src = t._src, e._node.preload = t._preload === !0 ? "auto" : t._preload, e._node.volume = i * o.volume(), e._node.load()), e;
|
|
1189
|
+
}, reset: function() {
|
|
1190
|
+
var e = this, t = e._parent;
|
|
1191
|
+
return e._muted = t._muted, e._loop = t._loop, e._volume = t._volume, e._rate = t._rate, e._seek = 0, e._rateSeek = 0, e._paused = !0, e._ended = !0, e._sprite = "__default", e._id = ++o._counter, e;
|
|
1192
|
+
}, _errorListener: function() {
|
|
1193
|
+
var e = this;
|
|
1194
|
+
e._parent._emit("loaderror", e._id, e._node.error ? e._node.error.code : 0), e._node.removeEventListener("error", e._errorFn, !1);
|
|
1195
|
+
}, _loadListener: function() {
|
|
1196
|
+
var e = this, t = e._parent;
|
|
1197
|
+
t._duration = Math.ceil(10 * e._node.duration) / 10, Object.keys(t._sprite).length === 0 && (t._sprite = { __default: [0, 1e3 * t._duration] }), t._state !== "loaded" && (t._state = "loaded", t._emit("load"), t._loadQueue()), e._node.removeEventListener(o._canPlayEvent, e._loadFn, !1);
|
|
1198
|
+
}, _endListener: function() {
|
|
1199
|
+
var e = this, t = e._parent;
|
|
1200
|
+
t._duration === 1 / 0 && (t._duration = Math.ceil(10 * e._node.duration) / 10, t._sprite.__default[1] === 1 / 0 && (t._sprite.__default[1] = 1e3 * t._duration), t._ended(e)), e._node.removeEventListener("ended", e._endFn, !1);
|
|
1201
|
+
} };
|
|
1202
|
+
var p = {}, v = function(e) {
|
|
1203
|
+
var t = e._src;
|
|
1204
|
+
if (p[t]) return e._duration = p[t].duration, void C(e);
|
|
1205
|
+
if (/^data:[^;]+;base64,/.test(t)) {
|
|
1206
|
+
for (var i = atob(t.split(",")[1]), a = new Uint8Array(i.length), d = 0; d < i.length; ++d) a[d] = i.charCodeAt(d);
|
|
1207
|
+
y(a.buffer, e);
|
|
1208
|
+
} else {
|
|
1209
|
+
var c = new XMLHttpRequest();
|
|
1210
|
+
c.open(e._xhr.method, t, !0), c.withCredentials = e._xhr.withCredentials, c.responseType = "arraybuffer", e._xhr.headers && Object.keys(e._xhr.headers).forEach(function(l) {
|
|
1211
|
+
c.setRequestHeader(l, e._xhr.headers[l]);
|
|
1212
|
+
}), c.onload = function() {
|
|
1213
|
+
var l = (c.status + "")[0];
|
|
1214
|
+
if (l !== "0" && l !== "2" && l !== "3") return void e._emit("loaderror", null, "Failed loading audio file with status: " + c.status + ".");
|
|
1215
|
+
y(c.response, e);
|
|
1216
|
+
}, c.onerror = function() {
|
|
1217
|
+
e._webAudio && (e._html5 = !0, e._webAudio = !1, e._sounds = [], delete p[t], e.load());
|
|
1218
|
+
}, f(c);
|
|
1219
|
+
}
|
|
1220
|
+
}, f = function(e) {
|
|
1221
|
+
try {
|
|
1222
|
+
e.send();
|
|
1223
|
+
} catch {
|
|
1224
|
+
e.onerror();
|
|
1225
|
+
}
|
|
1226
|
+
}, y = function(e, t) {
|
|
1227
|
+
var i = function() {
|
|
1228
|
+
t._emit("loaderror", null, "Decoding audio data failed.");
|
|
1229
|
+
}, a = function(d) {
|
|
1230
|
+
d && t._sounds.length > 0 ? (p[t._src] = d, C(t, d)) : i();
|
|
1231
|
+
};
|
|
1232
|
+
typeof Promise < "u" && o.ctx.decodeAudioData.length === 1 ? o.ctx.decodeAudioData(e).then(a).catch(i) : o.ctx.decodeAudioData(e, a, i);
|
|
1233
|
+
}, C = function(e, t) {
|
|
1234
|
+
t && !e._duration && (e._duration = t.duration), Object.keys(e._sprite).length === 0 && (e._sprite = { __default: [0, 1e3 * e._duration] }), e._state !== "loaded" && (e._state = "loaded", e._emit("load"), e._loadQueue());
|
|
1235
|
+
}, h = function() {
|
|
1236
|
+
if (o.usingWebAudio) {
|
|
1237
|
+
try {
|
|
1238
|
+
typeof AudioContext < "u" ? o.ctx = new AudioContext() : typeof webkitAudioContext < "u" ? o.ctx = new webkitAudioContext() : o.usingWebAudio = !1;
|
|
1239
|
+
} catch {
|
|
1240
|
+
o.usingWebAudio = !1;
|
|
1241
|
+
}
|
|
1242
|
+
o.ctx || (o.usingWebAudio = !1);
|
|
1243
|
+
var e = /iP(hone|od|ad)/.test(o._navigator && o._navigator.platform), t = o._navigator && o._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/), i = t ? parseInt(t[1], 10) : null;
|
|
1244
|
+
if (e && i && i < 9) {
|
|
1245
|
+
var a = /safari/.test(o._navigator && o._navigator.userAgent.toLowerCase());
|
|
1246
|
+
o._navigator && !a && (o.usingWebAudio = !1);
|
|
1247
|
+
}
|
|
1248
|
+
o.usingWebAudio && (o.masterGain = o.ctx.createGain === void 0 ? o.ctx.createGainNode() : o.ctx.createGain(), o.masterGain.gain.setValueAtTime(o._muted ? 0 : o._volume, o.ctx.currentTime), o.masterGain.connect(o.ctx.destination)), o._setup();
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
u.Howler = o, u.Howl = r, typeof n < "u" ? (n.HowlerGlobal = s, n.Howler = o, n.Howl = r, n.Sound = _) : typeof window < "u" && (window.HowlerGlobal = s, window.Howler = o, window.Howl = r, window.Sound = _);
|
|
1252
|
+
})();
|
|
1253
|
+
}(j)), j;
|
|
1254
|
+
}
|
|
1255
|
+
var $ = Ae();
|
|
1256
|
+
const Te = typeof navigator.standalone < "u";
|
|
1257
|
+
class Oe {
|
|
1258
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1259
|
+
constructor(n) {
|
|
1260
|
+
this.cogsConnection = n, this.eventTarget = new EventTarget(), this.globalVolume = 1, this.audioClipPlayers = {}, this.sinkId = "", this.addEventListener("audioClipState", ({ detail: o }) => {
|
|
1261
|
+
n.sendMediaClipState(o);
|
|
1262
|
+
}), n.addEventListener("message", ({ message: o }) => {
|
|
1263
|
+
switch (o.type) {
|
|
1264
|
+
case "media_config_update":
|
|
1265
|
+
if (this.globalVolume !== o.globalVolume && this.setGlobalVolume(o.globalVolume), o.audioOutput !== void 0) {
|
|
1266
|
+
const r = n.getAudioSinkId(o.audioOutput);
|
|
1267
|
+
this.setAudioSink(r ?? "");
|
|
1268
|
+
}
|
|
1269
|
+
this.updateConfig(o.files);
|
|
1270
|
+
break;
|
|
1271
|
+
case "audio_play":
|
|
1272
|
+
this.playAudioClip(o.file, {
|
|
1273
|
+
playId: o.playId,
|
|
1274
|
+
volume: o.volume,
|
|
1275
|
+
loop: !!o.loop,
|
|
1276
|
+
fade: o.fade
|
|
1277
|
+
});
|
|
1278
|
+
break;
|
|
1279
|
+
case "audio_pause":
|
|
1280
|
+
this.pauseAudioClip(o.file, { fade: o.fade });
|
|
1281
|
+
break;
|
|
1282
|
+
case "audio_stop":
|
|
1283
|
+
o.file ? this.stopAudioClip(o.file, { fade: o.fade }) : this.stopAllAudioClips({ fade: o.fade });
|
|
1284
|
+
break;
|
|
1285
|
+
case "audio_set_clip_volume":
|
|
1286
|
+
this.setAudioClipVolume(o.file, { volume: o.volume, fade: o.fade });
|
|
1287
|
+
break;
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
const s = () => {
|
|
1291
|
+
const o = Object.entries(this.audioClipPlayers).map(([r, _]) => {
|
|
1292
|
+
const p = Object.values(_.activeClips), v = p.some(
|
|
1293
|
+
({ state: f }) => f.type === "playing" || f.type === "pausing" || f.type === "stopping" || f.type === "play_requested" || f.type === "pause_requested" || f.type === "stop_requested"
|
|
1294
|
+
) ? "playing" : p.some(({ state: f }) => f.type === "paused") ? "paused" : "stopped";
|
|
1295
|
+
return [r, v];
|
|
1296
|
+
});
|
|
1297
|
+
n.sendInitialMediaClipStates({ mediaType: "audio", files: o });
|
|
1298
|
+
};
|
|
1299
|
+
n.addEventListener("open", s), s();
|
|
1300
|
+
}
|
|
1301
|
+
setGlobalVolume(n) {
|
|
1302
|
+
this.globalVolume = n, $.Howler.volume(n), this.notifyStateListeners();
|
|
1303
|
+
}
|
|
1304
|
+
playAudioClip(n, { playId: s, volume: o, fade: r, loop: _ }) {
|
|
1305
|
+
n in this.audioClipPlayers || (this.audioClipPlayers[n] = this.createClip(n, { preload: !1, ephemeral: !0 })), this.updateAudioClipPlayer(n, (p) => {
|
|
1306
|
+
const v = Object.entries(p.activeClips).filter(([, { state: h }]) => h.type === "paused").map(([h]) => parseInt(h)), f = Object.entries(p.activeClips).filter(([, { state: h }]) => h.type === "pausing").map(([h]) => parseInt(h));
|
|
1307
|
+
v.forEach((h) => {
|
|
1308
|
+
p.player.play(h);
|
|
1309
|
+
});
|
|
1310
|
+
const y = Object.entries(p.activeClips).filter(([, { state: h }]) => h.type === "pause_requested").map(([h]) => parseInt(h)), C = v.length > 0 || f.length > 0 || y.length > 0 ? [] : [p.player.play()];
|
|
1311
|
+
return f.forEach((h) => {
|
|
1312
|
+
p.player.off("fade", void 0, h), p.player.loop(_, h), this.updateActiveAudioClip(n, h, (e) => ({ ...e, state: { type: "playing" } })), L(r) ? x(p.player, o, r * 1e3, h) : R(p.player, o, h);
|
|
1313
|
+
}), [...v, ...y, ...C].forEach((h) => {
|
|
1314
|
+
p.player.loop(_, h), p.player.off("play", void 0, h), p.player.off("pause", void 0, h), p.player.off("fade", void 0, h), p.player.off("end", void 0, h), p.player.off("stop", void 0, h), p.player.once("play", () => {
|
|
1315
|
+
V(p.player, this.sinkId);
|
|
1316
|
+
}), p.player.once("stop", () => this.handleStoppedClip(n, s, h), h), p.player.on(
|
|
1317
|
+
"end",
|
|
1318
|
+
() => {
|
|
1319
|
+
p.activeClips[h]?.loop || this.handleStoppedClip(n, s, h);
|
|
1320
|
+
},
|
|
1321
|
+
h
|
|
1322
|
+
);
|
|
1323
|
+
const e = {
|
|
1324
|
+
playId: s,
|
|
1325
|
+
state: { type: "play_requested" },
|
|
1326
|
+
loop: _,
|
|
1327
|
+
volume: o
|
|
1328
|
+
};
|
|
1329
|
+
p.player.once(
|
|
1330
|
+
"play",
|
|
1331
|
+
() => {
|
|
1332
|
+
const t = p.activeClips[h]?.state;
|
|
1333
|
+
t?.type === "pause_requested" ? this.pauseAudioClip(n, { fade: t.fade }, h, !0) : t?.type === "stop_requested" ? this.stopAudioClip(n, { fade: t.fade }, h, !0) : this.updateActiveAudioClip(n, h, (i) => ({ ...i, state: { type: "playing" } }));
|
|
1334
|
+
},
|
|
1335
|
+
h
|
|
1336
|
+
), L(r) ? (p.player.volume(0, h), p.player.mute(!1, h), p.player.once(
|
|
1337
|
+
"play",
|
|
1338
|
+
() => {
|
|
1339
|
+
x(p.player, o, r * 1e3, h);
|
|
1340
|
+
},
|
|
1341
|
+
h
|
|
1342
|
+
)) : R(p.player, o, h), p.activeClips = { ...p.activeClips, [h]: e };
|
|
1343
|
+
}), p;
|
|
1344
|
+
}), this.notifyClipStateListeners(s, n, "playing");
|
|
1345
|
+
}
|
|
1346
|
+
pauseAudioClip(n, { fade: s }, o, r) {
|
|
1347
|
+
Object.keys(this.audioClipPlayers[n]?.activeClips ?? {}).length !== 0 && this.updateAudioClipPlayer(n, (_) => (_.activeClips = Object.fromEntries(
|
|
1348
|
+
Object.entries(_.activeClips).map(([p, v]) => {
|
|
1349
|
+
const f = parseInt(p);
|
|
1350
|
+
return (o === void 0 || o === f) && (r && v.state.type === "pause_requested" || v.state.type === "playing" || v.state.type === "pausing" ? L(s) ? (_.player.once(
|
|
1351
|
+
"fade",
|
|
1352
|
+
(y) => {
|
|
1353
|
+
_.player.pause(y), this.updateActiveAudioClip(n, y, (C) => ({ ...C, state: { type: "paused" } })), this.notifyClipStateListeners(v.playId, n, "paused");
|
|
1354
|
+
},
|
|
1355
|
+
f
|
|
1356
|
+
), x(_.player, 0, s * 1e3, f), v.state = { type: "pausing" }) : (_.player.pause(f), v.state = { type: "paused" }, this.notifyClipStateListeners(v.playId, n, "paused")) : (v.state.type === "play_requested" || v.state.type === "pause_requested") && (v.state = { type: "pause_requested", fade: s })), [p, v];
|
|
1357
|
+
})
|
|
1358
|
+
), _));
|
|
1359
|
+
}
|
|
1360
|
+
stopAudioClip(n, { fade: s }, o, r) {
|
|
1361
|
+
ke("Stop audio clip", { activeClips: this.audioClipPlayers[n]?.activeClips }), Object.keys(this.audioClipPlayers[n]?.activeClips ?? {}).length !== 0 && this.updateAudioClipPlayer(n, (_) => (_.activeClips = Object.fromEntries(
|
|
1362
|
+
Object.entries(_.activeClips).map(([p, v]) => {
|
|
1363
|
+
const f = parseInt(p);
|
|
1364
|
+
return (o === void 0 || o === f) && (r && v.state.type === "stop_requested" || v.state.type === "playing" || v.state.type === "pausing" || v.state.type === "paused" || v.state.type === "stopping" ? L(s) && v.state.type !== "paused" ? (_.player.off("fade", f), x(_.player, 0, s * 1e3, f), _.player.once(
|
|
1365
|
+
"fade",
|
|
1366
|
+
(y) => {
|
|
1367
|
+
_.player.loop(!1, y), _.player.stop(y);
|
|
1368
|
+
},
|
|
1369
|
+
f
|
|
1370
|
+
), v.state = { type: "stopping" }) : (_.player.loop(!1, f), _.player.stop(f)) : (v.state.type === "play_requested" || v.state.type === "pause_requested" || v.state.type === "stop_requested") && (v.state = { type: "stop_requested", fade: s })), [p, v];
|
|
1371
|
+
})
|
|
1372
|
+
), _));
|
|
1373
|
+
}
|
|
1374
|
+
stopAllAudioClips(n) {
|
|
1375
|
+
Object.keys(this.audioClipPlayers).forEach((s) => {
|
|
1376
|
+
this.stopAudioClip(s, n);
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
setAudioClipVolume(n, { volume: s, fade: o }) {
|
|
1380
|
+
if (!(s >= 0 && s <= 1)) {
|
|
1381
|
+
console.warn("Invalid volume", s);
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
Object.keys(this.audioClipPlayers[n]?.activeClips ?? {}).length !== 0 && this.updateAudioClipPlayer(n, (r) => (r.activeClips = Object.fromEntries(
|
|
1385
|
+
Object.entries(r.activeClips).map(([_, p]) => {
|
|
1386
|
+
if (p.state.type !== "pausing" && p.state.type !== "stopping") {
|
|
1387
|
+
const v = parseInt(_);
|
|
1388
|
+
return L(o) ? x(r.player, s, o * 1e3, v) : R(r.player, s, v), [_, { ...p, volume: s }];
|
|
1389
|
+
} else
|
|
1390
|
+
return [_, p];
|
|
1391
|
+
})
|
|
1392
|
+
), r));
|
|
1393
|
+
}
|
|
1394
|
+
handleStoppedClip(n, s, o) {
|
|
1395
|
+
this.updateAudioClipPlayer(n, (r) => (delete r.activeClips[o], r)), this.notifyClipStateListeners(s, n, "stopped");
|
|
1396
|
+
}
|
|
1397
|
+
updateActiveAudioClip(n, s, o) {
|
|
1398
|
+
this.updateAudioClipPlayer(
|
|
1399
|
+
n,
|
|
1400
|
+
(r) => s in r.activeClips ? { ...r, activeClips: { ...r.activeClips, [s]: o(r.activeClips[s]) } } : r
|
|
1401
|
+
);
|
|
1402
|
+
}
|
|
1403
|
+
updateAudioClipPlayer(n, s) {
|
|
1404
|
+
n in this.audioClipPlayers && (this.audioClipPlayers = { ...this.audioClipPlayers, [n]: s(this.audioClipPlayers[n]) });
|
|
1405
|
+
const o = this.audioClipPlayers[n];
|
|
1406
|
+
o && Object.keys(o.activeClips ?? {}).length === 0 && o.config.ephemeral && (o.player.unload(), delete this.audioClipPlayers[n]), this.notifyStateListeners();
|
|
1407
|
+
}
|
|
1408
|
+
setAudioSink(n) {
|
|
1409
|
+
for (const s of Object.values(this.audioClipPlayers))
|
|
1410
|
+
V(s.player, n);
|
|
1411
|
+
this.sinkId = n;
|
|
1412
|
+
}
|
|
1413
|
+
updateConfig(n) {
|
|
1414
|
+
const s = Object.fromEntries(
|
|
1415
|
+
Object.entries(n).filter((r) => {
|
|
1416
|
+
const _ = r[1].type;
|
|
1417
|
+
return _ === "audio" || !_;
|
|
1418
|
+
})
|
|
1419
|
+
), o = this.audioClipPlayers;
|
|
1420
|
+
this.audioClipPlayers = (() => {
|
|
1421
|
+
const r = { ...o };
|
|
1422
|
+
return Object.keys(o).filter(
|
|
1423
|
+
(f) => !(f in s) && !o[f].config.ephemeral
|
|
1424
|
+
).forEach((f) => {
|
|
1425
|
+
o[f].player.unload(), delete r[f];
|
|
1426
|
+
}), Object.entries(s).filter(([f]) => !o[f]).forEach(([f, y]) => {
|
|
1427
|
+
r[f] = this.createClip(f, { ...y, ephemeral: !1 });
|
|
1428
|
+
}), Object.keys(o).filter((f) => f in s).forEach((f) => {
|
|
1429
|
+
r[f] = this.updatedClip(f, r[f], { ...s[f], ephemeral: !1 });
|
|
1430
|
+
}), r;
|
|
1431
|
+
})(), this.notifyStateListeners();
|
|
1432
|
+
}
|
|
1433
|
+
notifyStateListeners() {
|
|
1434
|
+
const n = Object.entries(this.audioClipPlayers).reduce(
|
|
1435
|
+
(r, [_, p]) => (r[_] = {
|
|
1436
|
+
config: { preload: p.config.preload, ephemeral: p.config.ephemeral },
|
|
1437
|
+
activeClips: p.activeClips
|
|
1438
|
+
}, r),
|
|
1439
|
+
{}
|
|
1440
|
+
), s = Object.values(this.audioClipPlayers).some(
|
|
1441
|
+
({ activeClips: r }) => Object.values(r).some((_) => _.state.type === "playing" || _.state.type === "pausing" || _.state.type === "stopping")
|
|
1442
|
+
), o = {
|
|
1443
|
+
globalVolume: this.globalVolume,
|
|
1444
|
+
isPlaying: s,
|
|
1445
|
+
clips: n
|
|
1446
|
+
};
|
|
1447
|
+
this.dispatchEvent("state", o);
|
|
1448
|
+
}
|
|
1449
|
+
notifyClipStateListeners(n, s, o) {
|
|
1450
|
+
this.dispatchEvent("audioClipState", { mediaType: "audio", playId: n, file: s, status: o });
|
|
1451
|
+
}
|
|
1452
|
+
// Type-safe wrapper around EventTarget
|
|
1453
|
+
addEventListener(n, s, o) {
|
|
1454
|
+
this.eventTarget.addEventListener(n, s, o);
|
|
1455
|
+
}
|
|
1456
|
+
removeEventListener(n, s, o) {
|
|
1457
|
+
this.eventTarget.removeEventListener(n, s, o);
|
|
1458
|
+
}
|
|
1459
|
+
dispatchEvent(n, s) {
|
|
1460
|
+
this.eventTarget.dispatchEvent(new CustomEvent(n, { detail: s }));
|
|
1461
|
+
}
|
|
1462
|
+
createPlayer(n, s) {
|
|
1463
|
+
const o = new $.Howl({
|
|
1464
|
+
src: this.cogsConnection.getAssetUrl(n),
|
|
1465
|
+
autoplay: !1,
|
|
1466
|
+
loop: !1,
|
|
1467
|
+
volume: 1,
|
|
1468
|
+
html5: !0,
|
|
1469
|
+
preload: s.preload
|
|
1470
|
+
});
|
|
1471
|
+
return V(o, this.sinkId), o;
|
|
1472
|
+
}
|
|
1473
|
+
createClip(n, s) {
|
|
1474
|
+
return {
|
|
1475
|
+
config: s,
|
|
1476
|
+
player: this.createPlayer(n, s),
|
|
1477
|
+
activeClips: {}
|
|
1478
|
+
};
|
|
1479
|
+
}
|
|
1480
|
+
updatedClip(n, s, o) {
|
|
1481
|
+
const r = { ...s, config: o };
|
|
1482
|
+
return s.config.preload !== o.preload && (r.player.unload(), r.player = this.createPlayer(n, o)), r;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
function ke(...u) {
|
|
1486
|
+
}
|
|
1487
|
+
function L(u) {
|
|
1488
|
+
return !Te && typeof u == "number" && !isNaN(u) && u > 0;
|
|
1489
|
+
}
|
|
1490
|
+
function V(u, n) {
|
|
1491
|
+
n !== void 0 && (u._html5 ? u._sounds?.forEach((s) => {
|
|
1492
|
+
s._node?.setSinkId?.(n);
|
|
1493
|
+
}) : console.warn("Cannot set sink ID: web audio not supported", u));
|
|
1494
|
+
}
|
|
1495
|
+
function R(u, n, s) {
|
|
1496
|
+
u.volume(n, s), u.mute(n === 0, s);
|
|
1497
|
+
}
|
|
1498
|
+
function x(u, n, s, o) {
|
|
1499
|
+
u.fade(u.volume(o), n, s, o);
|
|
1500
|
+
}
|
|
1501
|
+
var D = /* @__PURE__ */ ((u) => (u.Paused = "paused", u.Playing = "playing", u))(D || {});
|
|
1502
|
+
const W = document.body;
|
|
1503
|
+
class Pe {
|
|
1504
|
+
constructor(n, s = W) {
|
|
1505
|
+
this.cogsConnection = n, this.eventTarget = new EventTarget(), this.globalVolume = 1, this.videoClipPlayers = {}, this.sinkId = "", this.parentElement = s, this.addEventListener("videoClipState", ({ detail: r }) => {
|
|
1506
|
+
n.sendMediaClipState(r);
|
|
1507
|
+
}), n.addEventListener("message", ({ message: r }) => {
|
|
1508
|
+
switch (r.type) {
|
|
1509
|
+
case "media_config_update":
|
|
1510
|
+
if (this.setGlobalVolume(r.globalVolume), r.audioOutput !== void 0) {
|
|
1511
|
+
const _ = n.getAudioSinkId(r.audioOutput);
|
|
1512
|
+
this.setAudioSink(_ ?? "");
|
|
1513
|
+
}
|
|
1514
|
+
this.updateConfig(r.files);
|
|
1515
|
+
break;
|
|
1516
|
+
case "video_play":
|
|
1517
|
+
this.playVideoClip(r.file, {
|
|
1518
|
+
playId: r.playId,
|
|
1519
|
+
volume: r.volume,
|
|
1520
|
+
loop: !!r.loop,
|
|
1521
|
+
fit: r.fit
|
|
1522
|
+
});
|
|
1523
|
+
break;
|
|
1524
|
+
case "video_pause":
|
|
1525
|
+
this.pauseVideoClip();
|
|
1526
|
+
break;
|
|
1527
|
+
case "video_stop":
|
|
1528
|
+
this.stopVideoClip();
|
|
1529
|
+
break;
|
|
1530
|
+
case "video_set_volume":
|
|
1531
|
+
this.setVideoClipVolume({ volume: r.volume });
|
|
1532
|
+
break;
|
|
1533
|
+
case "video_set_fit":
|
|
1534
|
+
this.setVideoClipFit({ fit: r.fit });
|
|
1535
|
+
break;
|
|
1536
|
+
}
|
|
1537
|
+
});
|
|
1538
|
+
const o = () => {
|
|
1539
|
+
const r = Object.entries(this.videoClipPlayers).map(([_, p]) => {
|
|
1540
|
+
const v = p.videoElement.paused ? p.videoElement.currentTime === 0 || p.videoElement.currentTime === p.videoElement.duration ? "paused" : "stopped" : "playing";
|
|
1541
|
+
return [_, v];
|
|
1542
|
+
});
|
|
1543
|
+
n.sendInitialMediaClipStates({ mediaType: "video", files: r });
|
|
1544
|
+
};
|
|
1545
|
+
n.addEventListener("open", o), o();
|
|
1546
|
+
}
|
|
1547
|
+
setParentElement(n) {
|
|
1548
|
+
this.parentElement = n, Object.values(this.videoClipPlayers).forEach((s) => {
|
|
1549
|
+
n.appendChild(s.videoElement);
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
resetParentElement() {
|
|
1553
|
+
this.setParentElement(W);
|
|
1554
|
+
}
|
|
1555
|
+
setGlobalVolume(n) {
|
|
1556
|
+
Object.values(this.videoClipPlayers).forEach((s) => {
|
|
1557
|
+
P(s.videoElement, s.volume * n);
|
|
1558
|
+
}), this.globalVolume = n, this.notifyStateListeners();
|
|
1559
|
+
}
|
|
1560
|
+
playVideoClip(n, { playId: s, volume: o, loop: r, fit: _ }) {
|
|
1561
|
+
this.videoClipPlayers[n] || (this.videoClipPlayers[n] = this.createClipPlayer(n, { preload: "none", ephemeral: !0, fit: _ })), this.pendingClip && this.updateVideoClipPlayer(this.pendingClip.path, (p) => (p.videoElement.load(), p)), this.activeClip?.path !== n && (this.pendingClip = { path: n, playId: s, actionOncePlaying: "play" }), this.updateVideoClipPlayer(n, (p) => (p.volume = o, P(p.videoElement, o * this.globalVolume), p.videoElement.loop = r, p.videoElement.style.objectFit = _, p.videoElement.currentTime === p.videoElement.duration && (p.videoElement.currentTime = 0), p.videoElement.play(), this.activeClip || (p.videoElement.style.display = "block"), p));
|
|
1562
|
+
}
|
|
1563
|
+
pauseVideoClip() {
|
|
1564
|
+
if (this.pendingClip && (this.pendingClip.actionOncePlaying = "pause"), this.activeClip) {
|
|
1565
|
+
const { playId: n, path: s } = this.activeClip;
|
|
1566
|
+
this.updateVideoClipPlayer(s, (o) => (o.videoElement?.pause(), o)), this.notifyClipStateListeners(n, s, "paused");
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
stopVideoClip() {
|
|
1570
|
+
this.pendingClip && (this.pendingClip.actionOncePlaying = "stop"), this.activeClip && this.handleStoppedClip(this.activeClip.path);
|
|
1571
|
+
}
|
|
1572
|
+
setVideoClipVolume({ volume: n }) {
|
|
1573
|
+
const s = this.pendingClip ?? this.activeClip ?? void 0;
|
|
1574
|
+
if (s) {
|
|
1575
|
+
if (!(n >= 0 && n <= 1)) {
|
|
1576
|
+
console.warn("Invalid volume", n);
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
this.updateVideoClipPlayer(s.path, (o) => (o.videoElement && (o.volume = n, P(o.videoElement, n * this.globalVolume)), o));
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
setVideoClipFit({ fit: n }) {
|
|
1583
|
+
const s = this.pendingClip ?? this.activeClip ?? void 0;
|
|
1584
|
+
s && this.updateVideoClipPlayer(s.path, (o) => (o.videoElement && (o.videoElement.style.objectFit = n), o));
|
|
1585
|
+
}
|
|
1586
|
+
handleStoppedClip(n) {
|
|
1587
|
+
if (!this.activeClip || this.activeClip.path !== n)
|
|
1588
|
+
return;
|
|
1589
|
+
const s = this.activeClip.playId;
|
|
1590
|
+
this.videoClipPlayers[this.activeClip.path]?.config.ephemeral && this.unloadClip(n), this.activeClip = void 0, this.updateVideoClipPlayer(n, (o) => (o.videoElement.pause(), o.videoElement.currentTime = 0, o.videoElement.style.display = "none", o)), this.notifyClipStateListeners(s, n, "stopped");
|
|
1591
|
+
}
|
|
1592
|
+
updateVideoClipPlayer(n, s) {
|
|
1593
|
+
if (this.videoClipPlayers[n]) {
|
|
1594
|
+
const o = s(this.videoClipPlayers[n]);
|
|
1595
|
+
o ? this.videoClipPlayers[n] = o : delete this.videoClipPlayers[n], this.notifyStateListeners();
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
setAudioSink(n) {
|
|
1599
|
+
for (const s of Object.values(this.videoClipPlayers))
|
|
1600
|
+
Q(s, n);
|
|
1601
|
+
this.sinkId = n;
|
|
1602
|
+
}
|
|
1603
|
+
updateConfig(n) {
|
|
1604
|
+
const s = Object.fromEntries(Object.entries(n).filter(([, { type: r }]) => r === "video" || !r)), o = this.videoClipPlayers;
|
|
1605
|
+
this.videoClipPlayers = (() => {
|
|
1606
|
+
const r = { ...o };
|
|
1607
|
+
return Object.keys(o).filter((f) => !(f in s)).forEach((f) => {
|
|
1608
|
+
this.activeClip?.path === f && o[f]?.config.ephemeral === !1 ? this.updateVideoClipPlayer(f, (y) => (y.config = { ...y.config, ephemeral: !0 }, y)) : (this.unloadClip(f), delete r[f]);
|
|
1609
|
+
}), Object.entries(s).filter(([f]) => !o[f]).forEach(([f, y]) => {
|
|
1610
|
+
r[f] = this.createClipPlayer(f, { ...y, preload: H(y.preload), ephemeral: !1, fit: "contain" });
|
|
1611
|
+
}), Object.entries(o).filter(([f]) => f in s).forEach(([f, y]) => {
|
|
1612
|
+
y.config.preload !== s[f].preload && this.updateVideoClipPlayer(f, (C) => (C.config = {
|
|
1613
|
+
...C.config,
|
|
1614
|
+
preload: H(s[f].preload),
|
|
1615
|
+
ephemeral: !1
|
|
1616
|
+
}, C.videoElement.preload = C.config.preload, C));
|
|
1617
|
+
}), r;
|
|
1618
|
+
})(), this.notifyStateListeners();
|
|
1619
|
+
}
|
|
1620
|
+
notifyStateListeners() {
|
|
1621
|
+
const n = {
|
|
1622
|
+
globalVolume: this.globalVolume,
|
|
1623
|
+
isPlaying: this.activeClip ? !this.videoClipPlayers[this.activeClip.path].videoElement?.paused : !1,
|
|
1624
|
+
clips: { ...this.videoClipPlayers },
|
|
1625
|
+
activeClip: this.activeClip ? {
|
|
1626
|
+
path: this.activeClip.path,
|
|
1627
|
+
state: this.videoClipPlayers[this.activeClip.path].videoElement?.paused ? D.Paused : D.Playing,
|
|
1628
|
+
loop: this.videoClipPlayers[this.activeClip.path].videoElement?.loop ?? !1,
|
|
1629
|
+
volume: this.videoClipPlayers[this.activeClip.path].videoElement?.muted ? 0 : this.videoClipPlayers[this.activeClip.path].videoElement?.volume ?? 0
|
|
1630
|
+
} : void 0
|
|
1631
|
+
};
|
|
1632
|
+
this.dispatchEvent("state", n);
|
|
1633
|
+
}
|
|
1634
|
+
notifyClipStateListeners(n, s, o) {
|
|
1635
|
+
this.dispatchEvent("videoClipState", { playId: n, mediaType: "video", file: s, status: o });
|
|
1636
|
+
}
|
|
1637
|
+
// Type-safe wrapper around EventTarget
|
|
1638
|
+
addEventListener(n, s, o) {
|
|
1639
|
+
this.eventTarget.addEventListener(n, s, o);
|
|
1640
|
+
}
|
|
1641
|
+
removeEventListener(n, s, o) {
|
|
1642
|
+
this.eventTarget.removeEventListener(n, s, o);
|
|
1643
|
+
}
|
|
1644
|
+
dispatchEvent(n, s) {
|
|
1645
|
+
this.eventTarget.dispatchEvent(new CustomEvent(n, { detail: s }));
|
|
1646
|
+
}
|
|
1647
|
+
createVideoElement(n, s, { volume: o }) {
|
|
1648
|
+
const r = document.createElement("video");
|
|
1649
|
+
return r.playsInline = !0, r.src = this.cogsConnection.getAssetUrl(n), r.autoplay = !1, r.loop = !1, P(r, o * this.globalVolume), r.preload = s.preload, r.addEventListener("playing", () => {
|
|
1650
|
+
if (this.pendingClip?.path === n) {
|
|
1651
|
+
switch (this.pendingClip.actionOncePlaying) {
|
|
1652
|
+
case "play": {
|
|
1653
|
+
r.style.display = "block", this.notifyClipStateListeners(this.pendingClip.playId, n, "playing");
|
|
1654
|
+
break;
|
|
1655
|
+
}
|
|
1656
|
+
case "pause": {
|
|
1657
|
+
r.style.display = "block", r.pause(), this.notifyClipStateListeners(this.pendingClip.playId, n, "paused");
|
|
1658
|
+
break;
|
|
1659
|
+
}
|
|
1660
|
+
case "stop": {
|
|
1661
|
+
r.pause(), this.notifyClipStateListeners(this.pendingClip.playId, n, "stopped");
|
|
1662
|
+
break;
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
this.activeClip && this.handleStoppedClip(this.activeClip.path), this.activeClip = this.pendingClip, this.pendingClip = void 0;
|
|
1666
|
+
} else this.activeClip?.path === n ? this.notifyClipStateListeners(this.activeClip.playId, n, "playing") : r.pause();
|
|
1667
|
+
}), r.addEventListener("ended", () => {
|
|
1668
|
+
!this.pendingClip && !r.loop && this.handleStoppedClip(n);
|
|
1669
|
+
}), r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.width = "100%", r.style.height = "100%", r.style.objectFit = s.fit, r.style.display = "none", this.parentElement.appendChild(r), r;
|
|
1670
|
+
}
|
|
1671
|
+
createClipPlayer(n, s) {
|
|
1672
|
+
const r = {
|
|
1673
|
+
config: s,
|
|
1674
|
+
videoElement: this.createVideoElement(n, s, { volume: 1 }),
|
|
1675
|
+
volume: 1
|
|
1676
|
+
};
|
|
1677
|
+
return Q(r, this.sinkId), r;
|
|
1678
|
+
}
|
|
1679
|
+
unloadClip(n) {
|
|
1680
|
+
if (this.activeClip?.path === n) {
|
|
1681
|
+
const s = this.activeClip.playId;
|
|
1682
|
+
this.activeClip = void 0, this.notifyClipStateListeners(s, n, "stopped");
|
|
1683
|
+
}
|
|
1684
|
+
this.videoClipPlayers[n]?.videoElement.remove(), this.updateVideoClipPlayer(n, () => null);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
function H(u) {
|
|
1688
|
+
return typeof u == "string" ? u : u ? "auto" : "none";
|
|
1689
|
+
}
|
|
1690
|
+
function Q(u, n) {
|
|
1691
|
+
n !== void 0 && typeof u.videoElement.setSinkId == "function" && u.videoElement.setSinkId(n);
|
|
1692
|
+
}
|
|
1693
|
+
function P(u, n) {
|
|
1694
|
+
u.volume = n, u.muted = n === 0;
|
|
1695
|
+
}
|
|
1696
|
+
const Ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1697
|
+
__proto__: null
|
|
1698
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1699
|
+
export {
|
|
1700
|
+
Oe as CogsAudioPlayer,
|
|
1701
|
+
be as CogsConfigChangedEvent,
|
|
1702
|
+
xe as CogsConnection,
|
|
1703
|
+
ye as CogsConnectionCloseEvent,
|
|
1704
|
+
me as CogsConnectionOpenEvent,
|
|
1705
|
+
we as CogsIncomingEvent,
|
|
1706
|
+
Ee as CogsMediaConfigChangedEvent,
|
|
1707
|
+
ge as CogsMessageEvent,
|
|
1708
|
+
Se as CogsShowPhaseChangedEvent,
|
|
1709
|
+
Ce as CogsStateChangedEvent,
|
|
1710
|
+
Pe as CogsVideoPlayer,
|
|
1711
|
+
F as DataStoreItemEvent,
|
|
1712
|
+
q as DataStoreItemsEvent,
|
|
1713
|
+
Ie as ManifestTypes,
|
|
1714
|
+
ue as assetUrl,
|
|
1715
|
+
Le as preloadUrl
|
|
1716
|
+
};
|