@clockworkdog/cogs-client 2.10.2 → 2.11.0
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 +12 -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,19 @@
|
|
|
1
|
+
(function(C,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(C=typeof globalThis<"u"?globalThis:C||self,k(C.COGS={}))})(this,function(C){"use strict";var k=(u=>(u.Setup="setup",u.Preshow="pre-show",u.InProgress="in progress",u.Finished="finished",u))(k||{});/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
8
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
9
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
11
|
+
|
|
12
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
|
+
and limitations under the License.
|
|
14
|
+
***************************************************************************** */var V=function(u,n){return V=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,o){s.__proto__=o}||function(s,o){for(var r in o)o.hasOwnProperty(r)&&(s[r]=o[r])},V(u,n)};function q(u,n){V(u,n);function s(){this.constructor=u}u.prototype=n===null?Object.create(n):(s.prototype=n.prototype,new s)}function ue(u){var n=typeof Symbol=="function"&&u[Symbol.iterator],s=0;return n?n.call(u):{next:function(){return u&&s>=u.length&&(u=void 0),{value:u&&u[s++],done:!u}}}}function de(u,n){var s=typeof Symbol=="function"&&u[Symbol.iterator];if(!s)return u;var o=s.call(u),r,_=[],p;try{for(;(n===void 0||n-- >0)&&!(r=o.next()).done;)_.push(r.value)}catch(v){p={error:v}}finally{try{r&&!r.done&&(s=o.return)&&s.call(o)}finally{if(p)throw p.error}}return _}function le(){for(var u=[],n=0;n<arguments.length;n++)u=u.concat(de(arguments[n]));return u}var G=function(){function u(n,s){this.target=s,this.type=n}return u}(),ce=function(u){q(n,u);function n(s,o){var r=u.call(this,"error",o)||this;return r.message=s.message,r.error=s,r}return n}(G),pe=function(u){q(n,u);function n(s,o,r){s===void 0&&(s=1e3),o===void 0&&(o="");var _=u.call(this,"close",r)||this;return _.wasClean=!0,_.code=s,_.reason=o,_}return n}(G);/*!
|
|
15
|
+
* Reconnecting WebSocket
|
|
16
|
+
* by Pedro Ladaria <pedro.ladaria@gmail.com>
|
|
17
|
+
* https://github.com/pladaria/reconnecting-websocket
|
|
18
|
+
* License MIT
|
|
19
|
+
*/var _e=function(){if(typeof WebSocket<"u")return WebSocket},fe=function(u){return typeof u<"u"&&!!u&&u.CLOSING===2},A={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0},he=function(){function u(n,s,o){var r=this;o===void 0&&(o={}),this._listeners={error:[],message:[],open:[],close:[]},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(_){r._debug("open event");var p=r._options.minUptime,v=p===void 0?A.minUptime:p;clearTimeout(r._connectTimeout),r._uptimeTimeout=setTimeout(function(){return r._acceptOpen()},v),r._ws.binaryType=r._binaryType,r._messageQueue.forEach(function(f){return r._ws.send(f)}),r._messageQueue=[],r.onopen&&r.onopen(_),r._listeners.open.forEach(function(f){return r._callEventListener(_,f)})},this._handleMessage=function(_){r._debug("message event"),r.onmessage&&r.onmessage(_),r._listeners.message.forEach(function(p){return r._callEventListener(_,p)})},this._handleError=function(_){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){return r._callEventListener(_,p)}),r._connect()},this._handleClose=function(_){r._debug("close event"),r._clearTimeouts(),r._shouldReconnect&&r._connect(),r.onclose&&r.onclose(_),r._listeners.close.forEach(function(p){return r._callEventListener(_,p)})},this._url=n,this._protocols=s,this._options=o,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(u,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(u,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(u,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(u,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"CONNECTING",{get:function(){return u.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"OPEN",{get:function(){return u.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"CLOSING",{get:function(){return u.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"CLOSED",{get:function(){return u.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(n){this._binaryType=n,this._ws&&(this._ws.binaryType=n)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"bufferedAmount",{get:function(){var n=this._messageQueue.reduce(function(s,o){return typeof o=="string"?s+=o.length:o instanceof Blob?s+=o.size:s+=o.byteLength,s},0);return n+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?u.CLOSED:u.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),u.prototype.close=function(n,s){if(n===void 0&&(n=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug("close enqueued: no ws instance");return}if(this._ws.readyState===this.CLOSED){this._debug("close: already closed");return}this._ws.close(n,s)},u.prototype.reconnect=function(n,s){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED?this._connect():(this._disconnect(n,s),this._connect())},u.prototype.send=function(n){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",n),this._ws.send(n);else{var s=this._options.maxEnqueuedMessages,o=s===void 0?A.maxEnqueuedMessages:s;this._messageQueue.length<o&&(this._debug("enqueue",n),this._messageQueue.push(n))}},u.prototype.addEventListener=function(n,s){this._listeners[n]&&this._listeners[n].push(s)},u.prototype.dispatchEvent=function(n){var s,o,r=this._listeners[n.type];if(r)try{for(var _=ue(r),p=_.next();!p.done;p=_.next()){var v=p.value;this._callEventListener(n,v)}}catch(f){s={error:f}}finally{try{p&&!p.done&&(o=_.return)&&o.call(_)}finally{if(s)throw s.error}}return!0},u.prototype.removeEventListener=function(n,s){this._listeners[n]&&(this._listeners[n]=this._listeners[n].filter(function(o){return o!==s}))},u.prototype._debug=function(){for(var n=[],s=0;s<arguments.length;s++)n[s]=arguments[s];this._options.debug&&console.log.apply(console,le(["RWS>"],n))},u.prototype._getNextDelay=function(){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;return this._retryCount>0&&(f=_*Math.pow(o,this._retryCount-1),f>v&&(f=v)),this._debug("next delay",f),f},u.prototype._wait=function(){var n=this;return new Promise(function(s){setTimeout(s,n._getNextDelay())})},u.prototype._getNextUrl=function(n){if(typeof n=="string")return Promise.resolve(n);if(typeof n=="function"){var s=n();if(typeof s=="string")return Promise.resolve(s);if(s.then)return s}throw Error("Invalid URL")},u.prototype._connect=function(){var n=this;if(!(this._connectLock||!this._shouldReconnect)){this._connectLock=!0;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?_e():v;if(this._retryCount>=r){this._debug("max retries reached",this._retryCount,">=",r);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!fe(f))throw Error("No valid WebSocket class provided");this._wait().then(function(){return n._getNextUrl(n._url)}).then(function(y){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(){return n._handleTimeout()},p))})}},u.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new ce(Error("TIMEOUT"),this))},u.prototype._disconnect=function(n,s){if(n===void 0&&(n=1e3),this._clearTimeouts(),!!this._ws){this._removeListeners();try{this._ws.close(n,s),this._handleClose(new pe(n,s,this))}catch{}}},u.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},u.prototype._callEventListener=function(n,s){"handleEvent"in s?s.handleEvent(n):s(n)},u.prototype._removeListeners=function(){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))},u.prototype._addListeners=function(){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))},u.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},u}();const $=12095;function W(u){const n=typeof window<"u"?window.location:void 0,s=`/assets/${encodeURIComponent(u)}`;return`${n?.protocol}//${n?.hostname}:${$}${s}`}async function ve(u){const n=await fetch(u);return URL.createObjectURL(new Blob([await n.arrayBuffer()]))}class me{#e=new EventTarget;constructor(n){this._items={...n}}handleDataStoreItemsMessage(n){this._items={...this._items,...n.items},Object.entries(n.items).forEach(([s,o])=>{this.dispatchEvent(new R(s,o))}),this.dispatchEvent(new N(n.items))}get items(){return this._items}getItem(n){return this._items[n]}setItems(n){return this._items={...this._items,...n},Object.entries(n).forEach(([s,o])=>{this.dispatchEvent(new R(s,o))}),this.dispatchEvent(new N(n)),this}addEventListener(n,s,o){this.#e.addEventListener(n,s,o)}removeEventListener(n,s,o){this.#e.removeEventListener(n,s,o)}dispatchEvent(n){this.#e.dispatchEvent(n)}}class R extends Event{constructor(n,s){super("item"),this.key=n,this.value=s,this._cogsConnectionEventType="item"}}class N extends Event{constructor(n){super("items"),this.items=n,this._cogsConnectionEventType="item"}}const O=globalThis.Date;function ye(u){const n=u-O.now();function s(...r){return r.length===0?new O(s.now()):new O(...r)}const o=Object.getOwnPropertyDescriptors(O);Object.defineProperties(s,o),s.now=function(){return O.now()+n},globalThis.Date=s}let ge=0;function be(){return++ge}const Ce=5,we=1e4;function Ee({interval:u,send:n,onChange:s=ye,syncSampleSize:o=Ce,syncRequestTimeout:r=we}){const _={};async function p(){const w=[];for(let i=0;i<o;i++){const a=new Promise(d=>{const c=be(),l=performance.now();n({timesync:{id:c}});const m=(g,E)=>d({sentAt:l,receivedAt:g,serverNow:E,clientNow:Date.now()});_[c]={complete:m},setTimeout(()=>d(null),r)});w.push(a),await a}const e=(await Promise.all(w)).filter(i=>i!==null).map(i=>{const{sentAt:a,receivedAt:d,serverNow:c,clientNow:l}=i,m=(d-a)/2;return l-c+m}),t=e.reduce((i,a)=>i+a,0)/e.length;isNaN(t)||s(Date.now()+t)}const v=w=>{const h=performance.now(),e=_[w.timesync.id];e&&e.complete(h,w.timesync.now)};p();const f=setInterval(p,u);return{receive:v,destroy:()=>{clearInterval(f)}}}class Se{constructor(n,{hostname:s=document.location.hostname,port:o=$}={},r,_){this.manifest=n,this.eventTarget=new EventTarget,this.currentConfig={},this.currentState={},this._showPhase=k.Setup,this._timerState=null,this._mediaConfig=null,this.audioOutputs=void 0,this._selectedAudioOutput="",this.currentState={...r},this.store=new me(_??{});const{useReconnectingWebsocket:p,path:v,pathParams:f}=Ae(document.location.href);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());const y=`ws://${s}:${o}${v}?${this.urlParams}`;this.websocket=p?new he(y):new WebSocket(y),this.websocket.onopen=()=>{this.currentConfig={},this.currentState={},this.dispatchEvent(new H),this.setState(this.currentState)};const w=Ee({interval:6e4,send:h=>{this.websocket.send(JSON.stringify(h))}});this.websocket.addEventListener("message",({data:h})=>{try{const e=JSON.parse(h);if(typeof e=="object"&&e!==null&&"timesync"in e){const t=e;w.receive(t)}}catch(e){console.error(e)}}),this.websocket.onclose=()=>{w.destroy(),this.dispatchEvent(new Q)},this.websocket.addEventListener("message",({data:h})=>{try{const e=JSON.parse(h);try{if(e.config)this.currentConfig=e.config,this.dispatchEvent(new z(this.currentConfig));else if(e.updates)this.currentState={...this.currentState,...e.updates},this.dispatchEvent(new Y(e.updates));else if(e.event&&e.event.key)this.dispatchEvent(new X(e.event.key,e.event.value));else if(typeof e.message=="object"){const t=e.message;switch(t.type){case"adjustable_timer_update":this._timerState={startedAt:Date.now(),durationMillis:t.durationMillis,ticking:t.ticking};break;case"show_phase":this._showPhase=t.phase,this.dispatchEvent(new K(t.phase));break;case"media_config_update":this._mediaConfig=t;for(const i of["preferOptimizedAudio","preferOptimizedVideo","preferOptimizedImages"])t[i]?this.urlParams.set(i,"true"):this.urlParams.delete(i);this.dispatchEvent(new Z(t));break;case"data_store_items":this.store.handleDataStoreItemsMessage(t);break}this.dispatchEvent(new J(t))}}catch(t){console.warn("Error handling data",h,t)}}catch(e){console.error("Unable to parse incoming data from server",h,e)}}),this.store.addEventListener("items",h=>{this.sendDataStoreItems(h.items)});{const h=async()=>{if(navigator.mediaDevices){const e=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:t})=>t==="audiooutput");this.sendAudioOutputs(e),this.audioOutputs=e}};this.eventTarget.addEventListener("open",h),navigator.mediaDevices?.addEventListener("devicechange",h),h()}}get config(){return{...this.currentConfig}}get state(){return{...this.currentState}}get showPhase(){return this._showPhase}get timerState(){return this._timerState?{...this._timerState}:null}get mediaConfig(){return this._mediaConfig?{...this._mediaConfig}:null}getAssetUrl(n){return`${W(n)}?${this.urlParams?.toString()??""}`}get selectedAudioOutput(){return this._selectedAudioOutput}get isConnected(){return this.websocket.readyState===WebSocket.OPEN}close(){this.websocket.close()}sendEvent(n,...[s]){this.isConnected&&this.websocket.send(JSON.stringify({event:{key:n,value:s}}))}setState(n){this.currentState={...this.currentState,...n},this.isConnected&&this.websocket.send(JSON.stringify({updates:n}))}getAudioSinkId(n){return n?this.audioOutputs?.find(({label:s})=>s===n)?.deviceId:""}sendInitialMediaClipStates(n){this.isConnected&&this.websocket.send(JSON.stringify({allMediaClipStates:n}))}sendMediaClipState(n){this.isConnected&&this.websocket.send(JSON.stringify({mediaClipState:n}))}sendAudioOutputs(n){this.isConnected&&this.websocket.send(JSON.stringify({audioOutputs:n}))}sendDataStoreItems(n){this.isConnected&&this.websocket.send(JSON.stringify({dataStoreItems:n}))}setPluginWindowVisible(n){this.isConnected&&this.websocket.send(JSON.stringify({window:{visible:n}}))}addEventListener(n,s,o){this.eventTarget.addEventListener(n,s,o)}removeEventListener(n,s,o){this.eventTarget.removeEventListener(n,s,o)}dispatchEvent(n){this.eventTarget.dispatchEvent(n)}}function Ae(u){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;if(o){const v=s.get("t")??"";return s.delete("local_id"),{path:`/local/${encodeURIComponent(o)}`,pathParams:new URLSearchParams({t:v}),useReconnectingWebsocket:!0}}else if(r){const v=s.get("name")??"";return s.delete("simulator"),s.delete("name"),{path:`/simulator/${encodeURIComponent(v)}`,pathParams:s,useReconnectingWebsocket:!0}}else if(_){const v=s.get("displayIdIndex")??"";return s.delete("display"),s.delete("displayIdIndex"),{path:`/display/${encodeURIComponent(_)}/${encodeURIComponent(v)}`}}else{if(p)return{path:`/plugin/${encodeURIComponent(p)}`,useReconnectingWebsocket:!0};{const v=s.get("serial")??"";return s.delete("serial"),{path:`/client/${encodeURIComponent(v)}`,pathParams:s}}}}class H extends Event{constructor(){super("open"),this._cogsConnectionEventType="open"}}class Q extends Event{constructor(){super("close"),this._cogsConnectionEventType="close"}}class J extends Event{constructor(n){super("message"),this.message=n,this._cogsConnectionEventType="message"}}class z extends Event{constructor(n){super("config"),this.config=n,this._cogsConnectionEventType="config"}}class Y extends Event{constructor(n){super("state"),this.state=n,this._cogsConnectionEventType="state"}}class X extends Event{constructor(n,s){super("event"),this.name=n,this.value=s,this._cogsConnectionEventType="event"}}class Z extends Event{constructor(n){super("mediaConfig"),this.mediaConfig=n,this._cogsConnectionEventType="mediaConfig"}}class K extends Event{constructor(n){super("showPhase"),this.showPhase=n,this._cogsConnectionEventType="showPhase"}}var D={},ee;function Te(){return ee||(ee=1,function(u){var n={};/*! howler.js v2.2.1 | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */(function(){var s=function(){this.init()};s.prototype={init:function(){var e=this||o;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},volume:function(e){var t=this||o;if(e=parseFloat(e),t.ctx||h(),e!==void 0&&e>=0&&e<=1){if(t._volume=e,t._muted)return t;t.usingWebAudio&&t.masterGain.gain.setValueAtTime(e,o.ctx.currentTime);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++){var c=t._howls[i]._soundById(a[d]);c&&c._node&&(c._node.volume=c._volume*e)}return t}return t._volume},mute:function(e){var t=this||o;t.ctx||h(),t._muted=e,t.usingWebAudio&&t.masterGain.gain.setValueAtTime(e?0:t._volume,o.ctx.currentTime);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++){var c=t._howls[i]._soundById(a[d]);c&&c._node&&(c._node.muted=!!e||c._muted)}return t},stop:function(){for(var e=this||o,t=0;t<e._howls.length;t++)e._howls[t].stop();return e},unload:function(){for(var e=this||o,t=e._howls.length-1;t>=0;t--)e._howls[t].unload();return e.usingWebAudio&&e.ctx&&e.ctx.close!==void 0&&(e.ctx.close(),e.ctx=null,h()),e},codecs:function(e){return(this||o)._codecs[e.replace(/^x-/,"")]},_setup:function(){var e=this||o;if(e.state=e.ctx&&e.ctx.state||"suspended",e._autoSuspend(),!e.usingWebAudio)if(typeof Audio<"u")try{var t=new Audio;t.oncanplaythrough===void 0&&(e._canPlayEvent="canplay")}catch{e.noAudio=!0}else e.noAudio=!0;try{var t=new Audio;t.muted&&(e.noAudio=!0)}catch{}return e.noAudio||e._setupCodecs(),e},_setupCodecs:function(){var e=this||o,t=null;try{t=typeof Audio<"u"?new Audio:null}catch{return e}if(!t||typeof t.canPlayType!="function")return e;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;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},_unlockAudio:function(){var e=this||o;if(!e._audioUnlocked&&e.ctx){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);var t=function(i){for(;e._html5AudioPool.length<e.html5PoolSize;)try{var a=new Audio;a._unlocked=!0,e._releaseHtml5Audio(a)}catch{e.noAudio=!0;break}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++){var m=e._howls[d]._soundById(c[l]);m&&m._node&&!m._node._unlocked&&(m._node._unlocked=!0,m._node.load())}e._autoResume();var g=e.ctx.createBufferSource();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(){g.disconnect(0),e._audioUnlocked=!0,document.removeEventListener("touchstart",t,!0),document.removeEventListener("touchend",t,!0),document.removeEventListener("click",t,!0);for(var E=0;E<e._howls.length;E++)e._howls[E]._emit("unlock")}};return document.addEventListener("touchstart",t,!0),document.addEventListener("touchend",t,!0),document.addEventListener("click",t,!0),e}},_obtainHtml5Audio:function(){var e=this||o;if(e._html5AudioPool.length)return e._html5AudioPool.pop();var t=new Audio().play();return t&&typeof Promise<"u"&&(t instanceof Promise||typeof t.then=="function")&&t.catch(function(){console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.")}),new Audio},_releaseHtml5Audio:function(e){var t=this||o;return e._unlocked&&t._html5AudioPool.push(e),t},_autoSuspend:function(){var e=this;if(e.autoSuspend&&e.ctx&&e.ctx.suspend!==void 0&&o.usingWebAudio){for(var t=0;t<e._howls.length;t++)if(e._howls[t]._webAudio){for(var i=0;i<e._howls[t]._sounds.length;i++)if(!e._howls[t]._sounds[i]._paused)return e}return e._suspendTimer&&clearTimeout(e._suspendTimer),e._suspendTimer=setTimeout(function(){if(e.autoSuspend){e._suspendTimer=null,e.state="suspending";var a=function(){e.state="suspended",e._resumeAfterSuspend&&(delete e._resumeAfterSuspend,e._autoResume())};e.ctx.suspend().then(a,a)}},3e4),e}},_autoResume:function(){var e=this;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(){e.state="running";for(var t=0;t<e._howls.length;t++)e._howls[t]._emit("resume")}),e._suspendTimer&&(clearTimeout(e._suspendTimer),e._suspendTimer=null)):e.state==="suspending"&&(e._resumeAfterSuspend=!0),e}};var o=new s,r=function(e){var t=this;if(!e.src||e.src.length===0)return void console.error("An array of source files must be passed with any new Howl.");t.init(e)};r.prototype={init:function(e){var t=this;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(){t.play()}}),t._preload&&t._preload!=="none"&&t.load(),t},load:function(){var e=this,t=null;if(o.noAudio)return void e._emit("loaderror",null,"No audio support.");typeof e._src=="string"&&(e._src=[e._src]);for(var i=0;i<e._src.length;i++){var a,d;if(e._format&&e._format[i])a=e._format[i];else{if(typeof(d=e._src[i])!="string"){e._emit("loaderror",null,"Non-string found in selected audio sources - ignoring.");continue}a=/^data:audio\/([^;,]+);/i.exec(d),a||(a=/\.([^.]+)$/.exec(d.split("?",1)[0])),a&&(a=a[1].toLowerCase())}if(a||console.warn('No file extension was found. Consider using the "format" property or specify an extension.'),a&&o.codecs(a)){t=e._src[i];break}}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.")},play:function(e,t){var i=this,a=null;if(typeof e=="number")a=e,e=null;else{if(typeof e=="string"&&i._state==="loaded"&&!i._sprite[e])return null;if(e===void 0&&(e="__default",!i._playLock)){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);d===1?e=null:a=null}}var l=a?i._soundById(a):i._inactiveSound();if(!l)return null;if(a&&!e&&(e=l._sprite||"__default"),i._state!=="loaded"){l._sprite=e,l._ended=!1;var m=l._id;return i._queue.push({event:"play",action:function(){i.play(m)}}),m}if(a&&!l._paused)return t||i._loadQueue("play"),l._id;i._webAudio&&o._autoResume();var g=Math.max(0,l._seek>0?l._seek:i._sprite[e][0]/1e3),E=Math.max(0,(i._sprite[e][0]+i._sprite[e][1])/1e3-g),S=1e3*E/Math.abs(l._rate),T=i._sprite[e][0]/1e3,j=(i._sprite[e][0]+i._sprite[e][1])/1e3;l._sprite=e,l._ended=!1;var F=function(){l._paused=!1,l._seek=g,l._start=T,l._stop=j,l._loop=!(!l._loop&&!i._sprite[e][2])};if(g>=j)return void i._ended(l);var b=l._node;if(i._webAudio){var se=function(){i._playLock=!1,F(),i._refreshBuffer(l);var L=l._muted||i._muted?0:l._volume;b.gain.setValueAtTime(L,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,E):l._loop?b.bufferSource.start(0,g,86400):b.bufferSource.start(0,g,E),S!==1/0&&(i._endTimers[l._id]=setTimeout(i._ended.bind(i,l),S)),t||setTimeout(function(){i._emit("play",l._id),i._loadQueue()},0)};o.state==="running"&&o.ctx.state!=="interrupted"?se():(i._playLock=!0,i.once("resume",se),i._clearTimer(l._id))}else{var re=function(){b.currentTime=g,b.muted=l._muted||i._muted||o._muted||b.muted,b.volume=l._volume*o.volume(),b.playbackRate=l._rate;try{var L=b.play();if(L&&typeof Promise<"u"&&(L instanceof Promise||typeof L.then=="function")?(i._playLock=!0,F(),L.then(function(){i._playLock=!1,b._unlocked=!0,t||(i._emit("play",l._id),i._loadQueue())}).catch(function(){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})):t||(i._playLock=!1,F(),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.");e!=="__default"||l._loop?i._endTimers[l._id]=setTimeout(i._ended.bind(i,l),S):(i._endTimers[l._id]=function(){i._ended(l),b.removeEventListener("ended",i._endTimers[l._id],!1)},b.addEventListener("ended",i._endTimers[l._id],!1))}catch(je){i._emit("playerror",l._id,je)}};b.src==="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"&&(b.src=i._src,b.load());var Ie=window&&window.ejecta||!b.readyState&&o._navigator.isCocoonJS;if(b.readyState>=3||Ie)re();else{i._playLock=!0;var ae=function(){re(),b.removeEventListener(o._canPlayEvent,ae,!1)};b.addEventListener(o._canPlayEvent,ae,!1),i._clearTimer(l._id)}}return l._id},pause:function(e){var t=this;if(t._state!=="loaded"||t._playLock)return t._queue.push({event:"pause",action:function(){t.pause(e)}}),t;for(var i=t._getSoundIds(e),a=0;a<i.length;a++){t._clearTimer(i[a]);var d=t._soundById(i[a]);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){if(!d._node.bufferSource)continue;d._node.bufferSource.stop===void 0?d._node.bufferSource.noteOff(0):d._node.bufferSource.stop(0),t._cleanBuffer(d._node)}else isNaN(d._node.duration)&&d._node.duration!==1/0||d._node.pause();arguments[1]||t._emit("pause",d?d._id:null)}return t},stop:function(e,t){var i=this;if(i._state!=="loaded"||i._playLock)return i._queue.push({event:"stop",action:function(){i.stop(e,t)}}),i;for(var a=i._getSoundIds(e),d=0;d<a.length;d++){i._clearTimer(a[d]);var c=i._soundById(a[d]);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))}return i},mute:function(e,t){var i=this;if(i._state!=="loaded"||i._playLock)return i._queue.push({event:"mute",action:function(){i.mute(e,t)}}),i;if(t===void 0){if(typeof e!="boolean")return i._muted;i._muted=e}for(var a=i._getSoundIds(t),d=0;d<a.length;d++){var c=i._soundById(a[d]);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))}return i},volume:function(){var e,t,i=this,a=arguments;if(a.length===0)return i._volume;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));var d;if(!(e!==void 0&&e>=0&&e<=1))return d=t?i._soundById(t):i._sounds[0],d?d._volume:0;if(i._state!=="loaded"||i._playLock)return i._queue.push({event:"volume",action:function(){i.volume.apply(i,a)}}),i;t===void 0&&(i._volume=e),t=i._getSoundIds(t);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));return i},fade:function(e,t,i,a){var d=this;if(d._state!=="loaded"||d._playLock)return d._queue.push({event:"fade",action:function(){d.fade(e,t,i,a)}}),d;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);for(var c=d._getSoundIds(a),l=0;l<c.length;l++){var m=d._soundById(c[l]);if(m){if(a||d._stopFade(c[l]),d._webAudio&&!m._muted){var g=o.ctx.currentTime,E=g+i/1e3;m._volume=e,m._node.gain.setValueAtTime(e,g),m._node.gain.linearRampToValueAtTime(t,E)}d._startFadeInterval(m,e,t,i,c[l],a===void 0)}}return d},_startFadeInterval:function(e,t,i,a,d,c){var l=this,m=t,g=i-t,E=Math.abs(g/.01),S=Math.max(4,E>0?a/E:a),T=Date.now();e._fadeTo=i,e._interval=setInterval(function(){var j=(Date.now()-T)/a;T=Date.now(),m+=g*j,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))},S)},_stopFade:function(e){var t=this,i=t._soundById(e);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},loop:function(){var e,t,i,a=this,d=arguments;if(d.length===0)return a._loop;if(d.length===1){if(typeof d[0]!="boolean")return!!(i=a._soundById(parseInt(d[0],10)))&&i._loop;e=d[0],a._loop=e}else d.length===2&&(e=d[0],t=parseInt(d[1],10));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)));return a},rate:function(){var e,t,i=this,a=arguments;if(a.length===0)t=i._sounds[0]._id;else if(a.length===1){var d=i._getSoundIds(),c=d.indexOf(a[0]);c>=0?t=parseInt(a[0],10):e=parseFloat(a[0])}else a.length===2&&(e=parseFloat(a[0]),t=parseInt(a[1],10));var l;if(typeof e!="number")return l=i._soundById(t),l?l._rate:i._rate;if(i._state!=="loaded"||i._playLock)return i._queue.push({event:"rate",action:function(){i.rate.apply(i,a)}}),i;t===void 0&&(i._rate=e),t=i._getSoundIds(t);for(var m=0;m<t.length;m++)if(l=i._soundById(t[m])){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);var g=i.seek(t[m]),E=(i._sprite[l._sprite][0]+i._sprite[l._sprite][1])/1e3-g,S=1e3*E/Math.abs(l._rate);!i._endTimers[t[m]]&&l._paused||(i._clearTimer(t[m]),i._endTimers[t[m]]=setTimeout(i._ended.bind(i,l),S)),i._emit("rate",l._id)}return i},seek:function(){var e,t,i=this,a=arguments;if(a.length===0)t=i._sounds[0]._id;else if(a.length===1){var d=i._getSoundIds(),c=d.indexOf(a[0]);c>=0?t=parseInt(a[0],10):i._sounds.length&&(t=i._sounds[0]._id,e=parseFloat(a[0]))}else a.length===2&&(e=parseFloat(a[0]),t=parseInt(a[1],10));if(t===void 0)return i;if(typeof e=="number"&&(i._state!=="loaded"||i._playLock))return i._queue.push({event:"seek",action:function(){i.seek.apply(i,a)}}),i;var l=i._soundById(t);if(l){if(!(typeof e=="number"&&e>=0)){if(i._webAudio){var m=i.playing(t)?o.ctx.currentTime-l._playStart:0,g=l._rateSeek?l._rateSeek-l._seek:0;return l._seek+(g+m*Math.abs(l._rate))}return l._node.currentTime}var E=i.playing(t);E&&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);var S=function(){i._emit("seek",t),E&&i.play(t,!0)};if(E&&!i._webAudio){var T=function(){i._playLock?setTimeout(T,0):S()};setTimeout(T,0)}else S()}return i},playing:function(e){var t=this;if(typeof e=="number"){var i=t._soundById(e);return!!i&&!i._paused}for(var a=0;a<t._sounds.length;a++)if(!t._sounds[a]._paused)return!0;return!1},duration:function(e){var t=this,i=t._duration,a=t._soundById(e);return a&&(i=t._sprite[a._sprite][1]/1e3),i},state:function(){return this._state},unload:function(){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);var a=o._howls.indexOf(e);a>=0&&o._howls.splice(a,1);var d=!0;for(i=0;i<o._howls.length;i++)if(o._howls[i]._src===e._src||e._src.indexOf(o._howls[i]._src)>=0){d=!1;break}return p&&d&&delete p[e._src],o.noAudio=!1,e._state="unloaded",e._sounds=[],e=null,null},on:function(e,t,i,a){var d=this,c=d["_on"+e];return typeof t=="function"&&c.push(a?{id:i,fn:t,once:a}:{id:i,fn:t}),d},off:function(e,t,i){var a=this,d=a["_on"+e],c=0;if(typeof t=="number"&&(i=t,t=null),t||i)for(c=0;c<d.length;c++){var l=i===d[c].id;if(t===d[c].fn&&l||!t&&l){d.splice(c,1);break}}else if(e)a["_on"+e]=[];else{var m=Object.keys(a);for(c=0;c<m.length;c++)m[c].indexOf("_on")===0&&Array.isArray(a[m[c]])&&(a[m[c]]=[])}return a},once:function(e,t,i){var a=this;return a.on(e,t,i,1),a},_emit:function(e,t,i){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){l.call(this,t,i)}).bind(a,d[c].fn),0),d[c].once&&a.off(e,d[c].fn,d[c].id));return a._loadQueue(e),a},_loadQueue:function(e){var t=this;if(t._queue.length>0){var i=t._queue[0];i.event===e&&(t._queue.shift(),t._loadQueue()),e||i.action()}return t},_ended:function(e){var t=this,i=e._sprite;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;var a=!(!e._loop&&!t._sprite[i][2]);if(t._emit("end",e._id),!t._webAudio&&a&&t.stop(e._id,!0).play(e._id),t._webAudio&&a){t._emit("play",e._id),e._seek=e._start||0,e._rateSeek=0,e._playStart=o.ctx.currentTime;var d=1e3*(e._stop-e._start)/Math.abs(e._rate);t._endTimers[e._id]=setTimeout(t._ended.bind(t,e),d)}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},_clearTimer:function(e){var t=this;if(t._endTimers[e]){if(typeof t._endTimers[e]!="function")clearTimeout(t._endTimers[e]);else{var i=t._soundById(e);i&&i._node&&i._node.removeEventListener("ended",t._endTimers[e],!1)}delete t._endTimers[e]}return t},_soundById:function(e){for(var t=this,i=0;i<t._sounds.length;i++)if(e===t._sounds[i]._id)return t._sounds[i];return null},_inactiveSound:function(){var e=this;e._drain();for(var t=0;t<e._sounds.length;t++)if(e._sounds[t]._ended)return e._sounds[t].reset();return new _(e)},_drain:function(){var e=this,t=e._pool,i=0,a=0;if(!(e._sounds.length<t)){for(a=0;a<e._sounds.length;a++)e._sounds[a]._ended&&i++;for(a=e._sounds.length-1;a>=0;a--){if(i<=t)return;e._sounds[a]._ended&&(e._webAudio&&e._sounds[a]._node&&e._sounds[a]._node.disconnect(0),e._sounds.splice(a,1),i--)}}},_getSoundIds:function(e){var t=this;if(e===void 0){for(var i=[],a=0;a<t._sounds.length;a++)i.push(t._sounds[a]._id);return i}return[e]},_refreshBuffer:function(e){var t=this;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},_cleanBuffer:function(e){var t=this,i=o._navigator&&o._navigator.vendor.indexOf("Apple")>=0;if(o._scratchBuffer&&e.bufferSource&&(e.bufferSource.onended=null,e.bufferSource.disconnect(0),i))try{e.bufferSource.buffer=o._scratchBuffer}catch{}return e.bufferSource=null,t},_clearSound:function(e){/MSIE |Trident\//.test(o._navigator&&o._navigator.userAgent)||(e.src="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA")}};var _=function(e){this._parent=e,this.init()};_.prototype={init:function(){var e=this,t=e._parent;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},create:function(){var e=this,t=e._parent,i=o._muted||e._muted||e._parent._muted?0:e._volume;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},reset:function(){var e=this,t=e._parent;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},_errorListener:function(){var e=this;e._parent._emit("loaderror",e._id,e._node.error?e._node.error.code:0),e._node.removeEventListener("error",e._errorFn,!1)},_loadListener:function(){var e=this,t=e._parent;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)},_endListener:function(){var e=this,t=e._parent;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)}};var p={},v=function(e){var t=e._src;if(p[t])return e._duration=p[t].duration,void w(e);if(/^data:[^;]+;base64,/.test(t)){for(var i=atob(t.split(",")[1]),a=new Uint8Array(i.length),d=0;d<i.length;++d)a[d]=i.charCodeAt(d);y(a.buffer,e)}else{var c=new XMLHttpRequest;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){c.setRequestHeader(l,e._xhr.headers[l])}),c.onload=function(){var l=(c.status+"")[0];if(l!=="0"&&l!=="2"&&l!=="3")return void e._emit("loaderror",null,"Failed loading audio file with status: "+c.status+".");y(c.response,e)},c.onerror=function(){e._webAudio&&(e._html5=!0,e._webAudio=!1,e._sounds=[],delete p[t],e.load())},f(c)}},f=function(e){try{e.send()}catch{e.onerror()}},y=function(e,t){var i=function(){t._emit("loaderror",null,"Decoding audio data failed.")},a=function(d){d&&t._sounds.length>0?(p[t._src]=d,w(t,d)):i()};typeof Promise<"u"&&o.ctx.decodeAudioData.length===1?o.ctx.decodeAudioData(e).then(a).catch(i):o.ctx.decodeAudioData(e,a,i)},w=function(e,t){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())},h=function(){if(o.usingWebAudio){try{typeof AudioContext<"u"?o.ctx=new AudioContext:typeof webkitAudioContext<"u"?o.ctx=new webkitAudioContext:o.usingWebAudio=!1}catch{o.usingWebAudio=!1}o.ctx||(o.usingWebAudio=!1);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;if(e&&i&&i<9){var a=/safari/.test(o._navigator&&o._navigator.userAgent.toLowerCase());o._navigator&&!a&&(o.usingWebAudio=!1)}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()}};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=_)})()}(D)),D}var te=Te();const ke=typeof navigator.standalone<"u";class Le{constructor(n){this.cogsConnection=n,this.eventTarget=new EventTarget,this.globalVolume=1,this.audioClipPlayers={},this.sinkId="",this.addEventListener("audioClipState",({detail:o})=>{n.sendMediaClipState(o)}),n.addEventListener("message",({message:o})=>{switch(o.type){case"media_config_update":if(this.globalVolume!==o.globalVolume&&this.setGlobalVolume(o.globalVolume),o.audioOutput!==void 0){const r=n.getAudioSinkId(o.audioOutput);this.setAudioSink(r??"")}this.updateConfig(o.files);break;case"audio_play":this.playAudioClip(o.file,{playId:o.playId,volume:o.volume,loop:!!o.loop,fade:o.fade});break;case"audio_pause":this.pauseAudioClip(o.file,{fade:o.fade});break;case"audio_stop":o.file?this.stopAudioClip(o.file,{fade:o.fade}):this.stopAllAudioClips({fade:o.fade});break;case"audio_set_clip_volume":this.setAudioClipVolume(o.file,{volume:o.volume,fade:o.fade});break}});const s=()=>{const o=Object.entries(this.audioClipPlayers).map(([r,_])=>{const p=Object.values(_.activeClips),v=p.some(({state:f})=>f.type==="playing"||f.type==="pausing"||f.type==="stopping"||f.type==="play_requested"||f.type==="pause_requested"||f.type==="stop_requested")?"playing":p.some(({state:f})=>f.type==="paused")?"paused":"stopped";return[r,v]});n.sendInitialMediaClipStates({mediaType:"audio",files:o})};n.addEventListener("open",s),s()}setGlobalVolume(n){this.globalVolume=n,te.Howler.volume(n),this.notifyStateListeners()}playAudioClip(n,{playId:s,volume:o,fade:r,loop:_}){n in this.audioClipPlayers||(this.audioClipPlayers[n]=this.createClip(n,{preload:!1,ephemeral:!0})),this.updateAudioClipPlayer(n,p=>{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));v.forEach(h=>{p.player.play(h)});const y=Object.entries(p.activeClips).filter(([,{state:h}])=>h.type==="pause_requested").map(([h])=>parseInt(h)),w=v.length>0||f.length>0||y.length>0?[]:[p.player.play()];return f.forEach(h=>{p.player.off("fade",void 0,h),p.player.loop(_,h),this.updateActiveAudioClip(n,h,e=>({...e,state:{type:"playing"}})),x(r)?P(p.player,o,r*1e3,h):U(p.player,o,h)}),[...v,...y,...w].forEach(h=>{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",()=>{M(p.player,this.sinkId)}),p.player.once("stop",()=>this.handleStoppedClip(n,s,h),h),p.player.on("end",()=>{p.activeClips[h]?.loop||this.handleStoppedClip(n,s,h)},h);const e={playId:s,state:{type:"play_requested"},loop:_,volume:o};p.player.once("play",()=>{const t=p.activeClips[h]?.state;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"}}))},h),x(r)?(p.player.volume(0,h),p.player.mute(!1,h),p.player.once("play",()=>{P(p.player,o,r*1e3,h)},h)):U(p.player,o,h),p.activeClips={...p.activeClips,[h]:e}}),p}),this.notifyClipStateListeners(s,n,"playing")}pauseAudioClip(n,{fade:s},o,r){Object.keys(this.audioClipPlayers[n]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(n,_=>(_.activeClips=Object.fromEntries(Object.entries(_.activeClips).map(([p,v])=>{const f=parseInt(p);return(o===void 0||o===f)&&(r&&v.state.type==="pause_requested"||v.state.type==="playing"||v.state.type==="pausing"?x(s)?(_.player.once("fade",y=>{_.player.pause(y),this.updateActiveAudioClip(n,y,w=>({...w,state:{type:"paused"}})),this.notifyClipStateListeners(v.playId,n,"paused")},f),P(_.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]})),_))}stopAudioClip(n,{fade:s},o,r){Oe("Stop audio clip",{activeClips:this.audioClipPlayers[n]?.activeClips}),Object.keys(this.audioClipPlayers[n]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(n,_=>(_.activeClips=Object.fromEntries(Object.entries(_.activeClips).map(([p,v])=>{const f=parseInt(p);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"?x(s)&&v.state.type!=="paused"?(_.player.off("fade",f),P(_.player,0,s*1e3,f),_.player.once("fade",y=>{_.player.loop(!1,y),_.player.stop(y)},f),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]})),_))}stopAllAudioClips(n){Object.keys(this.audioClipPlayers).forEach(s=>{this.stopAudioClip(s,n)})}setAudioClipVolume(n,{volume:s,fade:o}){if(!(s>=0&&s<=1)){console.warn("Invalid volume",s);return}Object.keys(this.audioClipPlayers[n]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(n,r=>(r.activeClips=Object.fromEntries(Object.entries(r.activeClips).map(([_,p])=>{if(p.state.type!=="pausing"&&p.state.type!=="stopping"){const v=parseInt(_);return x(o)?P(r.player,s,o*1e3,v):U(r.player,s,v),[_,{...p,volume:s}]}else return[_,p]})),r))}handleStoppedClip(n,s,o){this.updateAudioClipPlayer(n,r=>(delete r.activeClips[o],r)),this.notifyClipStateListeners(s,n,"stopped")}updateActiveAudioClip(n,s,o){this.updateAudioClipPlayer(n,r=>s in r.activeClips?{...r,activeClips:{...r.activeClips,[s]:o(r.activeClips[s])}}:r)}updateAudioClipPlayer(n,s){n in this.audioClipPlayers&&(this.audioClipPlayers={...this.audioClipPlayers,[n]:s(this.audioClipPlayers[n])});const o=this.audioClipPlayers[n];o&&Object.keys(o.activeClips??{}).length===0&&o.config.ephemeral&&(o.player.unload(),delete this.audioClipPlayers[n]),this.notifyStateListeners()}setAudioSink(n){for(const s of Object.values(this.audioClipPlayers))M(s.player,n);this.sinkId=n}updateConfig(n){const s=Object.fromEntries(Object.entries(n).filter(r=>{const _=r[1].type;return _==="audio"||!_})),o=this.audioClipPlayers;this.audioClipPlayers=(()=>{const r={...o};return Object.keys(o).filter(f=>!(f in s)&&!o[f].config.ephemeral).forEach(f=>{o[f].player.unload(),delete r[f]}),Object.entries(s).filter(([f])=>!o[f]).forEach(([f,y])=>{r[f]=this.createClip(f,{...y,ephemeral:!1})}),Object.keys(o).filter(f=>f in s).forEach(f=>{r[f]=this.updatedClip(f,r[f],{...s[f],ephemeral:!1})}),r})(),this.notifyStateListeners()}notifyStateListeners(){const n=Object.entries(this.audioClipPlayers).reduce((r,[_,p])=>(r[_]={config:{preload:p.config.preload,ephemeral:p.config.ephemeral},activeClips:p.activeClips},r),{}),s=Object.values(this.audioClipPlayers).some(({activeClips:r})=>Object.values(r).some(_=>_.state.type==="playing"||_.state.type==="pausing"||_.state.type==="stopping")),o={globalVolume:this.globalVolume,isPlaying:s,clips:n};this.dispatchEvent("state",o)}notifyClipStateListeners(n,s,o){this.dispatchEvent("audioClipState",{mediaType:"audio",playId:n,file:s,status:o})}addEventListener(n,s,o){this.eventTarget.addEventListener(n,s,o)}removeEventListener(n,s,o){this.eventTarget.removeEventListener(n,s,o)}dispatchEvent(n,s){this.eventTarget.dispatchEvent(new CustomEvent(n,{detail:s}))}createPlayer(n,s){const o=new te.Howl({src:this.cogsConnection.getAssetUrl(n),autoplay:!1,loop:!1,volume:1,html5:!0,preload:s.preload});return M(o,this.sinkId),o}createClip(n,s){return{config:s,player:this.createPlayer(n,s),activeClips:{}}}updatedClip(n,s,o){const r={...s,config:o};return s.config.preload!==o.preload&&(r.player.unload(),r.player=this.createPlayer(n,o)),r}}function Oe(...u){}function x(u){return!ke&&typeof u=="number"&&!isNaN(u)&&u>0}function M(u,n){n!==void 0&&(u._html5?u._sounds?.forEach(s=>{s._node?.setSinkId?.(n)}):console.warn("Cannot set sink ID: web audio not supported",u))}function U(u,n,s){u.volume(n,s),u.mute(n===0,s)}function P(u,n,s,o){u.fade(u.volume(o),n,s,o)}var B=(u=>(u.Paused="paused",u.Playing="playing",u))(B||{});const ne=document.body;class xe{constructor(n,s=ne){this.cogsConnection=n,this.eventTarget=new EventTarget,this.globalVolume=1,this.videoClipPlayers={},this.sinkId="",this.parentElement=s,this.addEventListener("videoClipState",({detail:r})=>{n.sendMediaClipState(r)}),n.addEventListener("message",({message:r})=>{switch(r.type){case"media_config_update":if(this.setGlobalVolume(r.globalVolume),r.audioOutput!==void 0){const _=n.getAudioSinkId(r.audioOutput);this.setAudioSink(_??"")}this.updateConfig(r.files);break;case"video_play":this.playVideoClip(r.file,{playId:r.playId,volume:r.volume,loop:!!r.loop,fit:r.fit});break;case"video_pause":this.pauseVideoClip();break;case"video_stop":this.stopVideoClip();break;case"video_set_volume":this.setVideoClipVolume({volume:r.volume});break;case"video_set_fit":this.setVideoClipFit({fit:r.fit});break}});const o=()=>{const r=Object.entries(this.videoClipPlayers).map(([_,p])=>{const v=p.videoElement.paused?p.videoElement.currentTime===0||p.videoElement.currentTime===p.videoElement.duration?"paused":"stopped":"playing";return[_,v]});n.sendInitialMediaClipStates({mediaType:"video",files:r})};n.addEventListener("open",o),o()}setParentElement(n){this.parentElement=n,Object.values(this.videoClipPlayers).forEach(s=>{n.appendChild(s.videoElement)})}resetParentElement(){this.setParentElement(ne)}setGlobalVolume(n){Object.values(this.videoClipPlayers).forEach(s=>{I(s.videoElement,s.volume*n)}),this.globalVolume=n,this.notifyStateListeners()}playVideoClip(n,{playId:s,volume:o,loop:r,fit:_}){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,I(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))}pauseVideoClip(){if(this.pendingClip&&(this.pendingClip.actionOncePlaying="pause"),this.activeClip){const{playId:n,path:s}=this.activeClip;this.updateVideoClipPlayer(s,o=>(o.videoElement?.pause(),o)),this.notifyClipStateListeners(n,s,"paused")}}stopVideoClip(){this.pendingClip&&(this.pendingClip.actionOncePlaying="stop"),this.activeClip&&this.handleStoppedClip(this.activeClip.path)}setVideoClipVolume({volume:n}){const s=this.pendingClip??this.activeClip??void 0;if(s){if(!(n>=0&&n<=1)){console.warn("Invalid volume",n);return}this.updateVideoClipPlayer(s.path,o=>(o.videoElement&&(o.volume=n,I(o.videoElement,n*this.globalVolume)),o))}}setVideoClipFit({fit:n}){const s=this.pendingClip??this.activeClip??void 0;s&&this.updateVideoClipPlayer(s.path,o=>(o.videoElement&&(o.videoElement.style.objectFit=n),o))}handleStoppedClip(n){if(!this.activeClip||this.activeClip.path!==n)return;const s=this.activeClip.playId;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")}updateVideoClipPlayer(n,s){if(this.videoClipPlayers[n]){const o=s(this.videoClipPlayers[n]);o?this.videoClipPlayers[n]=o:delete this.videoClipPlayers[n],this.notifyStateListeners()}}setAudioSink(n){for(const s of Object.values(this.videoClipPlayers))oe(s,n);this.sinkId=n}updateConfig(n){const s=Object.fromEntries(Object.entries(n).filter(([,{type:r}])=>r==="video"||!r)),o=this.videoClipPlayers;this.videoClipPlayers=(()=>{const r={...o};return Object.keys(o).filter(f=>!(f in s)).forEach(f=>{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])}),Object.entries(s).filter(([f])=>!o[f]).forEach(([f,y])=>{r[f]=this.createClipPlayer(f,{...y,preload:ie(y.preload),ephemeral:!1,fit:"contain"})}),Object.entries(o).filter(([f])=>f in s).forEach(([f,y])=>{y.config.preload!==s[f].preload&&this.updateVideoClipPlayer(f,w=>(w.config={...w.config,preload:ie(s[f].preload),ephemeral:!1},w.videoElement.preload=w.config.preload,w))}),r})(),this.notifyStateListeners()}notifyStateListeners(){const n={globalVolume:this.globalVolume,isPlaying:this.activeClip?!this.videoClipPlayers[this.activeClip.path].videoElement?.paused:!1,clips:{...this.videoClipPlayers},activeClip:this.activeClip?{path:this.activeClip.path,state:this.videoClipPlayers[this.activeClip.path].videoElement?.paused?B.Paused:B.Playing,loop:this.videoClipPlayers[this.activeClip.path].videoElement?.loop??!1,volume:this.videoClipPlayers[this.activeClip.path].videoElement?.muted?0:this.videoClipPlayers[this.activeClip.path].videoElement?.volume??0}:void 0};this.dispatchEvent("state",n)}notifyClipStateListeners(n,s,o){this.dispatchEvent("videoClipState",{playId:n,mediaType:"video",file:s,status:o})}addEventListener(n,s,o){this.eventTarget.addEventListener(n,s,o)}removeEventListener(n,s,o){this.eventTarget.removeEventListener(n,s,o)}dispatchEvent(n,s){this.eventTarget.dispatchEvent(new CustomEvent(n,{detail:s}))}createVideoElement(n,s,{volume:o}){const r=document.createElement("video");return r.playsInline=!0,r.src=this.cogsConnection.getAssetUrl(n),r.autoplay=!1,r.loop=!1,I(r,o*this.globalVolume),r.preload=s.preload,r.addEventListener("playing",()=>{if(this.pendingClip?.path===n){switch(this.pendingClip.actionOncePlaying){case"play":{r.style.display="block",this.notifyClipStateListeners(this.pendingClip.playId,n,"playing");break}case"pause":{r.style.display="block",r.pause(),this.notifyClipStateListeners(this.pendingClip.playId,n,"paused");break}case"stop":{r.pause(),this.notifyClipStateListeners(this.pendingClip.playId,n,"stopped");break}}this.activeClip&&this.handleStoppedClip(this.activeClip.path),this.activeClip=this.pendingClip,this.pendingClip=void 0}else this.activeClip?.path===n?this.notifyClipStateListeners(this.activeClip.playId,n,"playing"):r.pause()}),r.addEventListener("ended",()=>{!this.pendingClip&&!r.loop&&this.handleStoppedClip(n)}),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}createClipPlayer(n,s){const r={config:s,videoElement:this.createVideoElement(n,s,{volume:1}),volume:1};return oe(r,this.sinkId),r}unloadClip(n){if(this.activeClip?.path===n){const s=this.activeClip.playId;this.activeClip=void 0,this.notifyClipStateListeners(s,n,"stopped")}this.videoClipPlayers[n]?.videoElement.remove(),this.updateVideoClipPlayer(n,()=>null)}}function ie(u){return typeof u=="string"?u:u?"auto":"none"}function oe(u,n){n!==void 0&&typeof u.videoElement.setSinkId=="function"&&u.videoElement.setSinkId(n)}function I(u,n){u.volume=n,u.muted=n===0}const Pe=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));C.CogsAudioPlayer=Le,C.CogsConfigChangedEvent=z,C.CogsConnection=Se,C.CogsConnectionCloseEvent=Q,C.CogsConnectionOpenEvent=H,C.CogsIncomingEvent=X,C.CogsMediaConfigChangedEvent=Z,C.CogsMessageEvent=J,C.CogsShowPhaseChangedEvent=K,C.CogsStateChangedEvent=Y,C.CogsVideoPlayer=xe,C.DataStoreItemEvent=R,C.DataStoreItemsEvent=N,C.ManifestTypes=Pe,C.assetUrl=W,C.preloadUrl=ve,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
export { default as CogsConnection } from './CogsConnection';
|
|
2
2
|
export * from './CogsConnection';
|
|
3
|
-
export { default as CogsClientMessage, MediaClientConfig } from './types/CogsClientMessage';
|
|
4
|
-
export { default as MediaClipStateMessage } from './types/MediaClipStateMessage';
|
|
5
|
-
export { default as ShowPhase } from './types/ShowPhase';
|
|
6
|
-
export { default as MediaObjectFit } from './types/MediaObjectFit';
|
|
3
|
+
export type { default as CogsClientMessage, MediaClientConfig } from './types/CogsClientMessage';
|
|
4
|
+
export type { default as MediaClipStateMessage } from './types/MediaClipStateMessage';
|
|
5
|
+
export type { default as ShowPhase } from './types/ShowPhase';
|
|
6
|
+
export type { default as MediaObjectFit } from './types/MediaObjectFit';
|
|
7
7
|
export { default as CogsAudioPlayer } from './AudioPlayer';
|
|
8
|
-
export { default as CogsRtspStreamer, LIVE_VIDEO_PLAYBACK_RATE } from './RtspStreamer';
|
|
9
8
|
export { default as CogsVideoPlayer } from './VideoPlayer';
|
|
10
9
|
export * from './types/AudioState';
|
|
11
|
-
export { assetUrl } from './
|
|
12
|
-
export { preloadUrl } from './helpers/urls';
|
|
10
|
+
export { assetUrl, preloadUrl } from './utils/urls';
|
|
13
11
|
export * from './types/CogsPluginManifest';
|
|
14
12
|
export * as ManifestTypes from './types/ManifestTypes';
|
|
15
13
|
export * from './DataStore';
|
package/dist/index.js
CHANGED
|
@@ -39,24 +39,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.ManifestTypes = exports.preloadUrl = exports.assetUrl = exports.CogsVideoPlayer = exports.
|
|
42
|
+
exports.ManifestTypes = exports.preloadUrl = exports.assetUrl = exports.CogsVideoPlayer = exports.CogsAudioPlayer = exports.CogsConnection = void 0;
|
|
43
43
|
var CogsConnection_1 = require("./CogsConnection");
|
|
44
44
|
Object.defineProperty(exports, "CogsConnection", { enumerable: true, get: function () { return __importDefault(CogsConnection_1).default; } });
|
|
45
45
|
__exportStar(require("./CogsConnection"), exports);
|
|
46
|
-
var ShowPhase_1 = require("./types/ShowPhase");
|
|
47
|
-
Object.defineProperty(exports, "ShowPhase", { enumerable: true, get: function () { return __importDefault(ShowPhase_1).default; } });
|
|
48
46
|
var AudioPlayer_1 = require("./AudioPlayer");
|
|
49
47
|
Object.defineProperty(exports, "CogsAudioPlayer", { enumerable: true, get: function () { return __importDefault(AudioPlayer_1).default; } });
|
|
50
|
-
var RtspStreamer_1 = require("./RtspStreamer");
|
|
51
|
-
Object.defineProperty(exports, "CogsRtspStreamer", { enumerable: true, get: function () { return __importDefault(RtspStreamer_1).default; } });
|
|
52
|
-
Object.defineProperty(exports, "LIVE_VIDEO_PLAYBACK_RATE", { enumerable: true, get: function () { return RtspStreamer_1.LIVE_VIDEO_PLAYBACK_RATE; } });
|
|
53
48
|
var VideoPlayer_1 = require("./VideoPlayer");
|
|
54
49
|
Object.defineProperty(exports, "CogsVideoPlayer", { enumerable: true, get: function () { return __importDefault(VideoPlayer_1).default; } });
|
|
55
50
|
__exportStar(require("./types/AudioState"), exports);
|
|
56
|
-
var urls_1 = require("./
|
|
51
|
+
var urls_1 = require("./utils/urls");
|
|
57
52
|
Object.defineProperty(exports, "assetUrl", { enumerable: true, get: function () { return urls_1.assetUrl; } });
|
|
58
|
-
|
|
59
|
-
Object.defineProperty(exports, "preloadUrl", { enumerable: true, get: function () { return urls_2.preloadUrl; } });
|
|
53
|
+
Object.defineProperty(exports, "preloadUrl", { enumerable: true, get: function () { return urls_1.preloadUrl; } });
|
|
60
54
|
__exportStar(require("./types/CogsPluginManifest"), exports);
|
|
61
55
|
exports.ManifestTypes = __importStar(require("./types/ManifestTypes"));
|
|
62
56
|
__exportStar(require("./DataStore"), exports);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Connect to COGS to build a custom Media Master",
|
|
4
4
|
"author": "Clockwork Dog <info@clockwork.dog>",
|
|
5
5
|
"homepage": "https://github.com/clockwork-dog/cogs-sdk/tree/main/packages/javascript",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.11.0",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
@@ -17,34 +17,39 @@
|
|
|
17
17
|
"dist/**/*"
|
|
18
18
|
],
|
|
19
19
|
"main": "dist/index.js",
|
|
20
|
-
"
|
|
20
|
+
"exports": {
|
|
21
|
+
"default": "./dist/browser/index.umd.js"
|
|
22
|
+
},
|
|
21
23
|
"scripts": {
|
|
22
|
-
"test": "yarn types && yarn lint",
|
|
24
|
+
"test": "yarn types && yarn lint && vitest",
|
|
23
25
|
"types": "tsc --noEmit",
|
|
24
26
|
"lint": "eslint .",
|
|
25
27
|
"build": "yarn build:ts && yarn build:browser",
|
|
26
28
|
"build:ts": "tsc",
|
|
27
|
-
"build:browser": "
|
|
29
|
+
"build:browser": "vite build",
|
|
28
30
|
"watch-build": "tsc -w",
|
|
29
31
|
"build-docs": "typedoc --out ../../docs/javascript --name @clockworkdog/cogs-client src/index.ts",
|
|
30
32
|
"release": "yarn npm publish --access public"
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"@clockworkdog/
|
|
35
|
+
"@clockworkdog/timesync": "^2.11.0",
|
|
34
36
|
"howler": "clockwork-dog/howler.js#fix-looping-clips",
|
|
35
37
|
"reconnecting-websocket": "^4.4.0"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
40
|
"@eslint/js": "^9.17.0",
|
|
39
41
|
"@types/howler": "2.2.12",
|
|
42
|
+
"@types/jsdom": "^27",
|
|
40
43
|
"@types/node": "^22.10.2",
|
|
41
|
-
"browserify": "^17.0.1",
|
|
42
44
|
"eslint": "^9.17.0",
|
|
43
45
|
"eslint-config-prettier": "^9.1.0",
|
|
44
46
|
"eslint-plugin-prettier": "^5.2.1",
|
|
47
|
+
"jsdom": "^27.1.0",
|
|
45
48
|
"prettier": "^3.4.2",
|
|
46
49
|
"typedoc": "^0.27.5",
|
|
47
50
|
"typescript": "~5.7.2",
|
|
48
|
-
"typescript-eslint": "^8.18.1"
|
|
51
|
+
"typescript-eslint": "^8.18.1",
|
|
52
|
+
"vite": "^7.1.12",
|
|
53
|
+
"vitest": "^4.0.6"
|
|
49
54
|
}
|
|
50
55
|
}
|
package/dist/RtspStreamer.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export declare const LIVE_VIDEO_PLAYBACK_RATE = 1.1;
|
|
2
|
-
/**
|
|
3
|
-
* Manages a websocket connection to the COGS TCP relay which can be used to send RTSP video
|
|
4
|
-
* feeds to the web.
|
|
5
|
-
*
|
|
6
|
-
* @deprecated
|
|
7
|
-
*/
|
|
8
|
-
export default class RtspStreamer {
|
|
9
|
-
private _websocketUri;
|
|
10
|
-
constructor({ hostname, port, path, }?: {
|
|
11
|
-
hostname?: string;
|
|
12
|
-
port?: number;
|
|
13
|
-
path?: string;
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Start an RTSP video stream on with the given URI on the given video element.
|
|
17
|
-
* @returns An object with a function to close the pipeline
|
|
18
|
-
*/
|
|
19
|
-
play(params: {
|
|
20
|
-
uri: string;
|
|
21
|
-
videoElement: HTMLVideoElement;
|
|
22
|
-
playbackRate?: number;
|
|
23
|
-
restartIfStopped?: boolean;
|
|
24
|
-
}): {
|
|
25
|
-
close: () => void;
|
|
26
|
-
};
|
|
27
|
-
}
|
package/dist/RtspStreamer.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LIVE_VIDEO_PLAYBACK_RATE = void 0;
|
|
4
|
-
const media_stream_library_browser_1 = require("@clockworkdog/media-stream-library-browser");
|
|
5
|
-
const urls_1 = require("./helpers/urls");
|
|
6
|
-
const DEFAULT_VIDEO_PLAYBACK_RATE = 1;
|
|
7
|
-
// Use a faster-than-realtime playback rate by default
|
|
8
|
-
// so that it keeps up with a realtime stream in case of video buffering
|
|
9
|
-
exports.LIVE_VIDEO_PLAYBACK_RATE = 1.1;
|
|
10
|
-
/**
|
|
11
|
-
* Manages a websocket connection to the COGS TCP relay which can be used to send RTSP video
|
|
12
|
-
* feeds to the web.
|
|
13
|
-
*
|
|
14
|
-
* @deprecated
|
|
15
|
-
*/
|
|
16
|
-
class RtspStreamer {
|
|
17
|
-
constructor({ hostname = document.location.hostname, port = urls_1.COGS_SERVER_PORT, path = '/tcp-proxy', } = {}) {
|
|
18
|
-
this._websocketUri = `ws://${hostname}:${port}${path}`;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Start an RTSP video stream on with the given URI on the given video element.
|
|
22
|
-
* @returns An object with a function to close the pipeline
|
|
23
|
-
*/
|
|
24
|
-
play(params) {
|
|
25
|
-
var _a;
|
|
26
|
-
const { uri, videoElement } = params;
|
|
27
|
-
videoElement.playsInline = true; // Required for iOS
|
|
28
|
-
let pipeline;
|
|
29
|
-
const startPipeline = () => {
|
|
30
|
-
pipeline === null || pipeline === void 0 ? void 0 : pipeline.close();
|
|
31
|
-
pipeline = new media_stream_library_browser_1.Html5VideoPipeline({
|
|
32
|
-
ws: { uri: this._websocketUri },
|
|
33
|
-
rtsp: { uri: uri },
|
|
34
|
-
mediaElement: videoElement,
|
|
35
|
-
});
|
|
36
|
-
// Restart stream on RTCP BYE (stream ended)
|
|
37
|
-
pipeline.rtsp.onRtcp = (rtcp) => {
|
|
38
|
-
if ((0, media_stream_library_browser_1.isRtcpBye)(rtcp)) {
|
|
39
|
-
console.log('Video stream ended. Restarting.');
|
|
40
|
-
videoElement.pause();
|
|
41
|
-
setTimeout(startPipeline, 0);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
// Start playback when ready
|
|
45
|
-
pipeline.ready.then(() => {
|
|
46
|
-
pipeline.rtsp.play();
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
startPipeline();
|
|
50
|
-
if (params.playbackRate) {
|
|
51
|
-
const playbackRate = (_a = params.playbackRate) !== null && _a !== void 0 ? _a : DEFAULT_VIDEO_PLAYBACK_RATE;
|
|
52
|
-
videoElement.playbackRate = playbackRate;
|
|
53
|
-
videoElement.addEventListener('play', () => {
|
|
54
|
-
videoElement.playbackRate = playbackRate;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
let removeRestartListeners = null;
|
|
58
|
-
if (params.restartIfStopped) {
|
|
59
|
-
let playing = false;
|
|
60
|
-
let interval = null;
|
|
61
|
-
const handleTimeUpdate = () => {
|
|
62
|
-
playing = true;
|
|
63
|
-
};
|
|
64
|
-
const handlePlay = () => {
|
|
65
|
-
playing = true;
|
|
66
|
-
videoElement.addEventListener('timeupdate', handleTimeUpdate);
|
|
67
|
-
if (!interval) {
|
|
68
|
-
interval = setInterval(() => {
|
|
69
|
-
if (!playing) {
|
|
70
|
-
console.log('Video stopped playing. Restarting.');
|
|
71
|
-
videoElement.pause();
|
|
72
|
-
setTimeout(startPipeline, 0);
|
|
73
|
-
}
|
|
74
|
-
playing = false;
|
|
75
|
-
}, 2000);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const handlePause = () => {
|
|
79
|
-
videoElement.removeEventListener('timeupdate', handleTimeUpdate);
|
|
80
|
-
if (interval) {
|
|
81
|
-
clearInterval(interval);
|
|
82
|
-
interval = null;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
videoElement.addEventListener('play', handlePlay);
|
|
86
|
-
videoElement.addEventListener('pause', handlePause);
|
|
87
|
-
removeRestartListeners = () => {
|
|
88
|
-
handlePause();
|
|
89
|
-
videoElement.removeEventListener('play', handlePlay);
|
|
90
|
-
videoElement.removeEventListener('pause', handlePause);
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
close: () => {
|
|
95
|
-
pipeline === null || pipeline === void 0 ? void 0 : pipeline.close();
|
|
96
|
-
removeRestartListeners === null || removeRestartListeners === void 0 ? void 0 : removeRestartListeners();
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.default = RtspStreamer;
|