@charisma-ai/sdk
Version:
Charisma.ai SDK for Javascript (browser)
1 lines • 125 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).CharismaSDK={})}(this,function(e){function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var i={__proto__:null,default:function(e,t){return t=t||{},new Promise(function(n,r){var o=new XMLHttpRequest,i=[],s=[],a={},u=function(){return{ok:2==(o.status/100|0),statusText:o.statusText,status:o.status,url:o.responseURL,text:function(){return Promise.resolve(o.responseText)},json:function(){return Promise.resolve(o.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([o.response]))},clone:u,headers:{keys:function(){return i},entries:function(){return s},get:function(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var c in o.open(t.method||"get",e,!0),o.onload=function(){o.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,n){i.push(t=t.toLowerCase()),s.push([t,n]),a[t]=a[t]?a[t]+","+n:n}),n(u())},o.onerror=r,o.withCredentials="include"==t.credentials,t.headers)o.setRequestHeader(c,t.headers[c]);o.send(t.body||null)})}},s=self.fetch||(self.fetch=i.default||i),a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function u(e){var t={exports:{}};return e(t,t.exports),t.exports}var c="%[a-f0-9]{2}",f=new RegExp(c,"gi"),h=new RegExp("("+c+")+","gi");function l(e,t){try{return decodeURIComponent(e.join(""))}catch(e){}if(1===e.length)return e;var n=e.slice(0,t=t||1),r=e.slice(t);return Array.prototype.concat.call([],l(n),l(r))}function d(e){try{return decodeURIComponent(e)}catch(r){for(var t=e.match(f),n=1;n<t.length;n++)t=(e=l(t,n).join("")).match(f);return e}}var p=function(e){if("string"!=typeof e)throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof e+"`");try{return e=e.replace(/\+/g," "),decodeURIComponent(e)}catch(t){return function(e){for(var t={"%FE%FF":"��","%FF%FE":"��"},n=h.exec(e);n;){try{t[n[0]]=decodeURIComponent(n[0])}catch(e){var r=d(n[0]);r!==n[0]&&(t[n[0]]=r)}n=h.exec(e)}t["%C2"]="�";for(var o=Object.keys(t),i=0;i<o.length;i++){var s=o[i];e=e.replace(new RegExp(s,"g"),t[s])}return e}(e)}},v=(e,t)=>{if("string"!=typeof e||"string"!=typeof t)throw new TypeError("Expected the arguments to be of type `string`");if(""===t)return[e];const n=e.indexOf(t);return-1===n?[e]:[e.slice(0,n),e.slice(n+t.length)]},y=function(e,t){for(var n={},r=Object.keys(e),o=Array.isArray(t),i=0;i<r.length;i++){var s=r[i],a=e[s];(o?-1!==t.indexOf(s):t(s,a,e))&&(n[s]=a)}return n},g=u(function(e,t){function n(e){if("string"!=typeof e||1!==e.length)throw new TypeError("arrayFormatSeparator must be single character string")}function r(e,t){return t.encode?t.strict?encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`):encodeURIComponent(e):e}function o(e,t){return t.decode?p(e):e}function i(e){return Array.isArray(e)?e.sort():"object"==typeof e?i(Object.keys(e)).sort((e,t)=>Number(e)-Number(t)).map(t=>e[t]):e}function s(e){const t=e.indexOf("#");return-1!==t&&(e=e.slice(0,t)),e}function a(e){const t=(e=s(e)).indexOf("?");return-1===t?"":e.slice(t+1)}function u(e,t){return t.parseNumbers&&!Number.isNaN(Number(e))&&"string"==typeof e&&""!==e.trim()?e=Number(e):!t.parseBooleans||null===e||"true"!==e.toLowerCase()&&"false"!==e.toLowerCase()||(e="true"===e.toLowerCase()),e}function c(e,t){n((t=Object.assign({decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1},t)).arrayFormatSeparator);const r=function(e){let t;switch(e.arrayFormat){case"index":return(e,n,r)=>{t=/\[(\d*)\]$/.exec(e),e=e.replace(/\[\d*\]$/,""),t?(void 0===r[e]&&(r[e]={}),r[e][t[1]]=n):r[e]=n};case"bracket":return(e,n,r)=>{t=/(\[\])$/.exec(e),r[e=e.replace(/\[\]$/,"")]=t?void 0!==r[e]?[].concat(r[e],n):[n]:n};case"comma":case"separator":return(t,n,r)=>{const i="string"==typeof n&&n.includes(e.arrayFormatSeparator),s="string"==typeof n&&!i&&o(n,e).includes(e.arrayFormatSeparator);n=s?o(n,e):n;const a=i||s?n.split(e.arrayFormatSeparator).map(t=>o(t,e)):null===n?n:o(n,e);r[t]=a};case"bracket-separator":return(t,n,r)=>{const i=/(\[\])$/.test(t);if(t=t.replace(/\[\]$/,""),!i)return void(r[t]=n?o(n,e):n);const s=null===n?[]:n.split(e.arrayFormatSeparator).map(t=>o(t,e));r[t]=void 0!==r[t]?[].concat(r[t],s):s};default:return(e,t,n)=>{n[e]=void 0!==n[e]?[].concat(n[e],t):t}}}(t),s=Object.create(null);if("string"!=typeof e)return s;if(!(e=e.trim().replace(/^[?#&]/,"")))return s;for(const n of e.split("&")){if(""===n)continue;let[e,i]=v(t.decode?n.replace(/\+/g," "):n,"=");i=void 0===i?null:["comma","separator","bracket-separator"].includes(t.arrayFormat)?i:o(i,t),r(o(e,t),i,s)}for(const e of Object.keys(s)){const n=s[e];if("object"==typeof n&&null!==n)for(const e of Object.keys(n))n[e]=u(n[e],t);else s[e]=u(n,t)}return!1===t.sort?s:(!0===t.sort?Object.keys(s).sort():Object.keys(s).sort(t.sort)).reduce((e,t)=>{const n=s[t];return e[t]=Boolean(n)&&"object"==typeof n&&!Array.isArray(n)?i(n):n,e},Object.create(null))}t.extract=a,t.parse=c,t.stringify=(e,t)=>{if(!e)return"";n((t=Object.assign({encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:","},t)).arrayFormatSeparator);const o=n=>t.skipNull&&null==e[n]||t.skipEmptyString&&""===e[n],i=function(e){switch(e.arrayFormat){case"index":return t=>(n,o)=>{const i=n.length;return void 0===o||e.skipNull&&null===o||e.skipEmptyString&&""===o?n:null===o?[...n,[r(t,e),"[",i,"]"].join("")]:[...n,[r(t,e),"[",r(i,e),"]=",r(o,e)].join("")]};case"bracket":return t=>(n,o)=>void 0===o||e.skipNull&&null===o||e.skipEmptyString&&""===o?n:null===o?[...n,[r(t,e),"[]"].join("")]:[...n,[r(t,e),"[]=",r(o,e)].join("")];case"comma":case"separator":case"bracket-separator":{const t="bracket-separator"===e.arrayFormat?"[]=":"=";return n=>(o,i)=>void 0===i||e.skipNull&&null===i||e.skipEmptyString&&""===i?o:(i=null===i?"":i,0===o.length?[[r(n,e),t,r(i,e)].join("")]:[[o,r(i,e)].join(e.arrayFormatSeparator)])}default:return t=>(n,o)=>void 0===o||e.skipNull&&null===o||e.skipEmptyString&&""===o?n:null===o?[...n,r(t,e)]:[...n,[r(t,e),"=",r(o,e)].join("")]}}(t),s={};for(const t of Object.keys(e))o(t)||(s[t]=e[t]);const a=Object.keys(s);return!1!==t.sort&&a.sort(t.sort),a.map(n=>{const o=e[n];return void 0===o?"":null===o?r(n,t):Array.isArray(o)?0===o.length&&"bracket-separator"===t.arrayFormat?r(n,t)+"[]":o.reduce(i(n),[]).join("&"):r(n,t)+"="+r(o,t)}).filter(e=>e.length>0).join("&")},t.parseUrl=(e,t)=>{t=Object.assign({decode:!0},t);const[n,r]=v(e,"#");return Object.assign({url:n.split("?")[0]||"",query:c(a(e),t)},t&&t.parseFragmentIdentifier&&r?{fragmentIdentifier:o(r,t)}:{})},t.stringifyUrl=(e,n)=>{n=Object.assign({encode:!0,strict:!0},n);const o=s(e.url).split("?")[0]||"",i=t.extract(e.url),a=t.parse(i,{sort:!1}),u=Object.assign(a,e.query);let c=t.stringify(u,n);c&&(c=`?${c}`);let f=function(e){let t="";const n=e.indexOf("#");return-1!==n&&(t=e.slice(n)),t}(e.url);return e.fragmentIdentifier&&(f=`#${r(e.fragmentIdentifier,n)}`),`${o}${c}${f}`},t.pick=(e,n,r)=>{r=Object.assign({parseFragmentIdentifier:!0},r);const{url:o,query:i,fragmentIdentifier:s}=t.parseUrl(e,r);return t.stringifyUrl({url:o,query:y(i,n),fragmentIdentifier:s},r)},t.exclude=(e,n,r)=>{const o=Array.isArray(n)?e=>!n.includes(e):(e,t)=>!n(e,t);return t.pick(e,o,r)}});function m(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var _=function(e,t,n){try{return Promise.resolve(P(((null==n?void 0:n.baseUrl)||x)+"/play/restart-from-event",{body:JSON.stringify({eventId:t}),headers:{Authorization:"Bearer "+e},method:"POST"})).then(function(){})}catch(e){return Promise.reject(e)}},b=function(e,t,n){try{return Promise.resolve(P(((null==n?void 0:n.baseUrl)||x)+"/play/restart-from-episode",{body:JSON.stringify({episodeIndex:t}),headers:{Authorization:"Bearer "+e},method:"POST"})).then(function(){})}catch(e){return Promise.reject(e)}},w=function(e,t,n){try{return Promise.resolve(P(((null==n?void 0:n.baseUrl)||x)+"/play/restart-from-episode",{body:JSON.stringify({episodeId:t}),headers:{Authorization:"Bearer "+e},method:"POST"})).then(function(){})}catch(e){return Promise.reject(e)}},O=function(e,n,r,o){try{return Promise.resolve(P(((null==o?void 0:o.baseUrl)||x)+"/play/set-memory",{body:JSON.stringify(t({},"number"==typeof n?{memoryId:n}:{memoryRecallValue:n},{saveValue:r})),headers:{Authorization:"Bearer "+e},method:"POST"})).then(function(){})}catch(e){return Promise.reject(e)}},I=function(e,t){try{return Promise.resolve(P(((null==t?void 0:t.baseUrl)||x)+"/play/playthrough-info",{headers:{Authorization:"Bearer "+e},method:"GET"}))}catch(e){return Promise.reject(e)}},A=function(e,t,n,r){try{var o=g.stringify({conversationId:t,minEventId:n});return Promise.resolve(P(((null==r?void 0:r.baseUrl)||x)+"/play/message-history?"+o,{headers:{Authorization:"Bearer "+e},method:"GET"}))}catch(e){return Promise.reject(e)}},E=function(e,t,n){try{return Promise.resolve(P(((null==n?void 0:n.baseUrl)||x)+"/play/conversation/character",{body:JSON.stringify({characterId:t}),headers:{Authorization:"Bearer "+e},method:"POST"})).then(function(e){return e.conversationId})}catch(e){return Promise.reject(e)}},C=function(e,t){try{return Promise.resolve(P(((null==t?void 0:t.baseUrl)||x)+"/play/conversation",{body:JSON.stringify({}),headers:{Authorization:"Bearer "+e},method:"POST"})).then(function(e){return e.conversationId})}catch(e){return Promise.reject(e)}},S=function(e,t){try{if(-1===e.version&&void 0===e.userToken&&void 0===e.apiKey)throw new Error("To play the draft version (-1) of a story, an `apiKey` or `userToken` must also be passed.");var n;return e.apiKey?n="API-Key "+e.apiKey:e.userToken&&(n="Bearer "+e.userToken),Promise.resolve(m(function(){return Promise.resolve(P(((null==t?void 0:t.baseUrl)||x)+"/play/token",{body:JSON.stringify({storyId:e.storyId,version:e.version}),headers:n?{Authorization:n}:void 0,method:"POST"})).then(function(e){return e.token})},function(e){throw new Error("A playthrough token could not be generated: "+e)}))}catch(e){return Promise.reject(e)}},P=function(e,n){void 0===n&&(n={});try{var r=t({Accept:"application/json"},n.headers);return"string"==typeof n.method&&"post"===n.method.toLowerCase()&&(r=t({"Content-Type":"application/json"},r)),Promise.resolve(s(e,t({mode:"cors"},n,{headers:r}))).then(function(t){function n(){if(!t.ok)throw new Error(r.error||"Something went wrong calling `"+e+"`");return r}var r={},o=m(function(){return Promise.resolve(t.json()).then(function(e){r=e})},function(){});return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},x="https://play.charisma.ai",$=function(){return x},T=function(e){x=e},R={__proto__:null,restartFromEventId:_,restartFromEpisodeIndex:b,restartFromEpisodeId:w,setMemory:O,getPlaythroughInfo:I,getMessageHistory:A,createCharacterConversation:E,createConversation:C,createPlaythroughToken:S,getGlobalBaseUrl:$,setGlobalBaseUrl:T},k=u(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(e,t,r,i,s){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new o(r,i||e,s),u=n?n+t:t;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],a]:e._events[u].push(a):(e._events[u]=a,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function a(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},a.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var r=0,o=t.length,i=new Array(o);r<o;r++)i[r]=t[r].fn;return i},a.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},a.prototype.emit=function(e,t,r,o,i,s){var a=n?n+e:e;if(!this._events[a])return!1;var u,c,f=this._events[a],h=arguments.length;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),h){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,r),!0;case 4:return f.fn.call(f.context,t,r,o),!0;case 5:return f.fn.call(f.context,t,r,o,i),!0;case 6:return f.fn.call(f.context,t,r,o,i,s),!0}for(c=1,u=new Array(h-1);c<h;c++)u[c-1]=arguments[c];f.fn.apply(f.context,u)}else{var l,d=f.length;for(c=0;c<d;c++)switch(f[c].once&&this.removeListener(e,f[c].fn,void 0,!0),h){case 1:f[c].fn.call(f[c].context);break;case 2:f[c].fn.call(f[c].context,t);break;case 3:f[c].fn.call(f[c].context,t,r);break;case 4:f[c].fn.call(f[c].context,t,r,o);break;default:if(!u)for(l=1,u=new Array(h-1);l<h;l++)u[l-1]=arguments[l];f[c].fn.apply(f[c].context,u)}}return!0},a.prototype.on=function(e,t,n){return i(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return i(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,r,o){var i=n?n+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var a=this._events[i];if(a.fn)a.fn!==t||o&&!a.once||r&&a.context!==r||s(this,i);else{for(var u=0,c=[],f=a.length;u<f;u++)(a[u].fn!==t||o&&!a[u].once||r&&a[u].context!==r)&&c.push(a[u]);c.length?this._events[i]=1===c.length?c[0]:c:s(this,i)}return this},a.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&s(this,t):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a});ArrayBuffer.isView||(ArrayBuffer.isView=function(e){return null!==e&&"object"==typeof e&&e.buffer instanceof ArrayBuffer});var j=u(function(e,t){function n(e,t){t.headers=e.headers||{},t.statusMessage=e.statusText,t.statusCode=e.status,t.data=e.response}t.send=function(e,t,r){return new Promise(function(o,i){var s,a,u,c;r=r||{};var f=new XMLHttpRequest,h=r.headers||{};for(s in r.timeout&&(f.timeout=r.timeout),f.ontimeout=f.onerror=function(e){e.timeout="timeout"==e.type,i(e)},f.open(e,t.href||t),f.onload=function(){for(c=f.getAllResponseHeaders().trim().split(/[\r\n]+/),n(f,f);u=c.shift();)u=u.split(": "),f.headers[u.shift().toLowerCase()]=u.join(": ");if((u=f.headers["content-type"])&&~u.indexOf("application/json"))try{f.data=JSON.parse(f.data,r.reviver)}catch(e){return n(f,e),i(e)}(f.status>=400?i:o)(f)},(a=r.body)&&"object"==typeof a&&(h["content-type"]="application/json",a=JSON.stringify(a)),f.withCredentials=!!r.withCredentials,h)f.setRequestHeader(s,h[s]);f.send(a)})},t.get=t.send.bind(t.send,"GET"),t.post=t.send.bind(t.send,"POST"),t.patch=t.send.bind(t.send,"PATCH"),t.del=t.send.bind(t.send,"DELETE"),t.put=t.send.bind(t.send,"PUT")}),M=u(function(e,t){var n,r=a&&a.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0}),t.ServerError=void 0;var o=function(e){function t(t,n){var r=e.call(this,n)||this;return r.name="ServerError",r.code=t,r}return r(t,e),t}(Error);t.ServerError=o});function N(e,t){if(this._offset=t,e instanceof ArrayBuffer)this._buffer=e,this._view=new DataView(this._buffer);else{if(!ArrayBuffer.isView(e))throw new Error("Invalid argument");this._buffer=e.buffer,this._view=new DataView(this._buffer,e.byteOffset,e.byteLength)}}N.prototype._array=function(e){for(var t=new Array(e),n=0;n<e;n++)t[n]=this._parse();return t},N.prototype._map=function(e){for(var t={},n=0;n<e;n++)t[this._parse()]=this._parse();return t},N.prototype._str=function(e){var t=function(e,t,n){for(var r="",o=0,i=t,s=t+n;i<s;i++){var a=e.getUint8(i);if(0!=(128&a))if(192!=(224&a))if(224!=(240&a)){if(240!=(248&a))throw new Error("Invalid byte "+a.toString(16));(o=(7&a)<<18|(63&e.getUint8(++i))<<12|(63&e.getUint8(++i))<<6|(63&e.getUint8(++i))<<0)>=65536?(o-=65536,r+=String.fromCharCode(55296+(o>>>10),56320+(1023&o))):r+=String.fromCharCode(o)}else r+=String.fromCharCode((15&a)<<12|(63&e.getUint8(++i))<<6|(63&e.getUint8(++i))<<0);else r+=String.fromCharCode((31&a)<<6|63&e.getUint8(++i));else r+=String.fromCharCode(a)}return r}(this._view,this._offset,e);return this._offset+=e,t},N.prototype._bin=function(e){var t=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,t},N.prototype._parse=function(){var e,t=this._view.getUint8(this._offset++),n=0,r=0,o=0,i=0;if(t<192)return t<128?t:t<144?this._map(15&t):t<160?this._array(15&t):this._str(31&t);if(t>223)return-1*(255-t+1);switch(t){case 192:return null;case 194:return!1;case 195:return!0;case 196:return n=this._view.getUint8(this._offset),this._offset+=1,this._bin(n);case 197:return n=this._view.getUint16(this._offset),this._offset+=2,this._bin(n);case 198:return n=this._view.getUint32(this._offset),this._offset+=4,this._bin(n);case 199:return n=this._view.getUint8(this._offset),r=this._view.getInt8(this._offset+1),this._offset+=2,[r,this._bin(n)];case 200:return n=this._view.getUint16(this._offset),r=this._view.getInt8(this._offset+2),this._offset+=3,[r,this._bin(n)];case 201:return n=this._view.getUint32(this._offset),r=this._view.getInt8(this._offset+4),this._offset+=5,[r,this._bin(n)];case 202:return e=this._view.getFloat32(this._offset),this._offset+=4,e;case 203:return e=this._view.getFloat64(this._offset),this._offset+=8,e;case 204:return e=this._view.getUint8(this._offset),this._offset+=1,e;case 205:return e=this._view.getUint16(this._offset),this._offset+=2,e;case 206:return e=this._view.getUint32(this._offset),this._offset+=4,e;case 207:return o=this._view.getUint32(this._offset)*Math.pow(2,32),i=this._view.getUint32(this._offset+4),this._offset+=8,o+i;case 208:return e=this._view.getInt8(this._offset),this._offset+=1,e;case 209:return e=this._view.getInt16(this._offset),this._offset+=2,e;case 210:return e=this._view.getInt32(this._offset),this._offset+=4,e;case 211:return o=this._view.getInt32(this._offset)*Math.pow(2,32),i=this._view.getUint32(this._offset+4),this._offset+=8,o+i;case 212:return r=this._view.getInt8(this._offset),this._offset+=1,0===r?void(this._offset+=1):[r,this._bin(1)];case 213:return r=this._view.getInt8(this._offset),this._offset+=1,[r,this._bin(2)];case 214:return r=this._view.getInt8(this._offset),this._offset+=1,[r,this._bin(4)];case 215:return r=this._view.getInt8(this._offset),this._offset+=1,0===r?(o=this._view.getInt32(this._offset)*Math.pow(2,32),i=this._view.getUint32(this._offset+4),this._offset+=8,new Date(o+i)):[r,this._bin(8)];case 216:return r=this._view.getInt8(this._offset),this._offset+=1,[r,this._bin(16)];case 217:return n=this._view.getUint8(this._offset),this._offset+=1,this._str(n);case 218:return n=this._view.getUint16(this._offset),this._offset+=2,this._str(n);case 219:return n=this._view.getUint32(this._offset),this._offset+=4,this._str(n);case 220:return n=this._view.getUint16(this._offset),this._offset+=2,this._array(n);case 221:return n=this._view.getUint32(this._offset),this._offset+=4,this._array(n);case 222:return n=this._view.getUint16(this._offset),this._offset+=2,this._map(n);case 223:return n=this._view.getUint32(this._offset),this._offset+=4,this._map(n)}throw new Error("Could not parse")};var D=Object.defineProperty({default:function(e,t){void 0===t&&(t=0);var n=new N(e,t),r=n._parse();if(n._offset!==e.byteLength)throw new Error(e.byteLength-n._offset+" trailing bytes");return r}},"__esModule",{value:!0});function U(e,t,n){for(var r=0,o=0,i=n.length;o<i;o++)(r=n.charCodeAt(o))<128?e.setUint8(t++,r):r<2048?(e.setUint8(t++,192|r>>6),e.setUint8(t++,128|63&r)):r<55296||r>=57344?(e.setUint8(t++,224|r>>12),e.setUint8(t++,128|r>>6&63),e.setUint8(t++,128|63&r)):(o++,r=65536+((1023&r)<<10|1023&n.charCodeAt(o)),e.setUint8(t++,240|r>>18),e.setUint8(t++,128|r>>12&63),e.setUint8(t++,128|r>>6&63),e.setUint8(t++,128|63&r))}function F(e,t,n){var r=typeof n,o=0,i=0,s=0,a=0,u=0,c=0;if("string"===r){if((u=function(e){for(var t=0,n=0,r=0,o=e.length;r<o;r++)(t=e.charCodeAt(r))<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}(n))<32)e.push(160|u),c=1;else if(u<256)e.push(217,u),c=2;else if(u<65536)e.push(218,u>>8,u),c=3;else{if(!(u<4294967296))throw new Error("String too long");e.push(219,u>>24,u>>16,u>>8,u),c=5}return t.push({_str:n,_length:u,_offset:e.length}),c+u}if("number"===r)return Math.floor(n)===n&&isFinite(n)?n>=0?n<128?(e.push(n),1):n<256?(e.push(204,n),2):n<65536?(e.push(205,n>>8,n),3):n<4294967296?(e.push(206,n>>24,n>>16,n>>8,n),5):(s=n/Math.pow(2,32)>>0,e.push(207,s>>24,s>>16,s>>8,s,(a=n>>>0)>>24,a>>16,a>>8,a),9):n>=-32?(e.push(n),1):n>=-128?(e.push(208,n),2):n>=-32768?(e.push(209,n>>8,n),3):n>=-2147483648?(e.push(210,n>>24,n>>16,n>>8,n),5):(s=Math.floor(n/Math.pow(2,32)),e.push(211,s>>24,s>>16,s>>8,s,(a=n>>>0)>>24,a>>16,a>>8,a),9):(e.push(203),t.push({_float:n,_length:8,_offset:e.length}),9);if("object"===r){if(null===n)return e.push(192),1;if(Array.isArray(n)){if((u=n.length)<16)e.push(144|u),c=1;else if(u<65536)e.push(220,u>>8,u),c=3;else{if(!(u<4294967296))throw new Error("Array too large");e.push(221,u>>24,u>>16,u>>8,u),c=5}for(o=0;o<u;o++)c+=F(e,t,n[o]);return c}if(n instanceof Date){var f=n.getTime();return s=Math.floor(f/Math.pow(2,32)),e.push(215,0,s>>24,s>>16,s>>8,s,(a=f>>>0)>>24,a>>16,a>>8,a),10}if(n instanceof ArrayBuffer){if((u=n.byteLength)<256)e.push(196,u),c=2;else if(u<65536)e.push(197,u>>8,u),c=3;else{if(!(u<4294967296))throw new Error("Buffer too large");e.push(198,u>>24,u>>16,u>>8,u),c=5}return t.push({_bin:n,_length:u,_offset:e.length}),c+u}if("function"==typeof n.toJSON)return F(e,t,n.toJSON());var h=[],l="",d=Object.keys(n);for(o=0,i=d.length;o<i;o++)"function"!=typeof n[l=d[o]]&&h.push(l);if((u=h.length)<16)e.push(128|u),c=1;else if(u<65536)e.push(222,u>>8,u),c=3;else{if(!(u<4294967296))throw new Error("Object too large");e.push(223,u>>24,u>>16,u>>8,u),c=5}for(o=0;o<u;o++)c+=F(e,t,l=h[o]),c+=F(e,t,n[l]);return c}if("boolean"===r)return e.push(n?195:194),1;if("undefined"===r)return e.push(212,0,0),3;throw new Error("Could not encode")}var L=Object.defineProperty({default:function(e){var t=[],n=[],r=F(t,n,e),o=new ArrayBuffer(r),i=new DataView(o),s=0,a=0,u=-1;n.length>0&&(u=n[0]._offset);for(var c,f=0,h=0,l=0,d=t.length;l<d;l++)if(i.setUint8(a+l,t[l]),l+1===u){if(f=(c=n[s])._length,h=a+u,c._bin)for(var p=new Uint8Array(c._bin),v=0;v<f;v++)i.setUint8(h+v,p[v]);else c._str?U(i,h,c._str):void 0!==c._float&&i.setFloat64(h,c._float);a+=f,n[++s]&&(u=n[s]._offset)}return o}},"__esModule",{value:!0}),z=u(function(e,t){var n=a&&a.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.encode=t.decode=void 0;var r=n(D),o=n(L);t.decode=r.default,t.encode=o.default}),B=function(){function e(){this.handlers=[]}return e.prototype.register=function(e,t){return this.handlers.push(e),this},e.prototype.invoke=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.handlers.forEach(function(t){return t.apply(void 0,e)})},e.prototype.invokeAsync=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Promise.all(this.handlers.map(function(t){return t.apply(void 0,e)}))},e.prototype.remove=function(e){var t=this.handlers.indexOf(e);this.handlers[t]=this.handlers[this.handlers.length-1],this.handlers.pop()},e.prototype.clear=function(){this.handlers=[]},e}(),q=Object.defineProperty({EventEmitter:B,createSignal:function(){var e=new B;function t(t){return e.register(t,null===this)}return t.once=function(t){var n=function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];t.apply(void 0,r),e.remove(n)};e.register(n)},t.remove=function(t){return e.remove(t)},t.invoke=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return e.invoke.apply(e,t)},t.invokeAsync=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return e.invokeAsync.apply(e,t)},t.clear=function(){return e.clear()},t}},"__esModule",{value:!0}),H=()=>({events:{},emit(e,...t){(this.events[e]||[]).forEach(e=>e(...t))},on(e,t){return(this.events[e]=this.events[e]||[]).push(t),()=>this.events[e]=(this.events[e]||[]).filter(e=>e!==t)}}),J={exponential:function(e,t){return Math.floor(Math.random()*Math.pow(2,e)*t)},fibonacci:function(e,t){if(e>(r=1))for(var n=1,r=2,o=2;o<e;o++){var i=n+r;n=r,r=i}return Math.floor(Math.random()*r*t)}};function V(e,t){this.func=e,this.attempts=0,this.delay=void 0!==t.initialDelay?t.initialDelay:100}V.prototype.backoff=function(){setTimeout(this.onReady,this.func(++this.attempts,this.delay))};var W=Object.defineProperty({createBackoff:function(e,t){return new V(J[e],t)}},"__esModule",{value:!0}),K=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function G(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var Q=W.createBackoff,X="undefined"!=typeof WebSocket?WebSocket:{__proto__:null,default:{}},Y=function(){function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};G(this,e),this.url=t,this.protocols=n,this.reconnectEnabled=!0,this.listeners={},this.backoff=Q(r.backoff||"exponential",r),this.backoff.onReady=this.onBackoffReady.bind(this),(void 0===r.connect||r.connect)&&this.open()}return K(e,[{key:"open",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.isReconnect=e;var t=this.ws&&this.ws.binaryType;this.ws=new X(this.url,this.protocols),this.ws.onclose=this.onCloseCallback.bind(this),this.ws.onerror=this.onErrorCallback.bind(this),this.ws.onmessage=this.onMessageCallback.bind(this),this.ws.onopen=this.onOpenCallback.bind(this),t&&(this.ws.binaryType=t)}},{key:"onBackoffReady",value:function(e,t){this.open(!0)}},{key:"onCloseCallback",value:function(e){!this.isReconnect&&this.listeners.onclose&&this.listeners.onclose.apply(null,arguments),this.reconnectEnabled&&e.code<3e3&&this.backoff.backoff()}},{key:"onErrorCallback",value:function(){this.listeners.onerror&&this.listeners.onerror.apply(null,arguments)}},{key:"onMessageCallback",value:function(){this.listeners.onmessage&&this.listeners.onmessage.apply(null,arguments)}},{key:"onOpenCallback",value:function(){this.listeners.onopen&&this.listeners.onopen.apply(null,arguments),this.isReconnect&&this.listeners.onreconnect&&this.listeners.onreconnect.apply(null,arguments),this.isReconnect=!1}},{key:"close",value:function(e,t){void 0===e&&(e=1e3),this.reconnectEnabled=!1,this.ws.close(e,t)}},{key:"send",value:function(e){this.ws.send(e)}},{key:"bufferedAmount",get:function(){return this.ws.bufferedAmount}},{key:"readyState",get:function(){return this.ws.readyState}},{key:"binaryType",get:function(){return this.ws.binaryType},set:function(e){this.ws.binaryType=e}},{key:"extensions",get:function(){return this.ws.extensions},set:function(e){this.ws.extensions=e}},{key:"protocol",get:function(){return this.ws.protocol},set:function(e){this.ws.protocol=e}},{key:"onclose",set:function(e){this.listeners.onclose=e},get:function(){return this.listeners.onclose}},{key:"onerror",set:function(e){this.listeners.onerror=e},get:function(){return this.listeners.onerror}},{key:"onmessage",set:function(e){this.listeners.onmessage=e},get:function(){return this.listeners.onmessage}},{key:"onopen",set:function(e){this.listeners.onopen=e},get:function(){return this.listeners.onopen}},{key:"onreconnect",set:function(e){this.listeners.onreconnect=e},get:function(){return this.listeners.onreconnect}}]),e}();Y.CONNECTING=X.CONNECTING,Y.OPEN=X.OPEN,Y.CLOSING=X.CLOSING,Y.CLOSED=X.CLOSED;var Z=Object.defineProperty({default:Y},"__esModule",{value:!0}),ee=u(function(e,t){var n,r=a&&a.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),o=a&&a.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Connection=void 0;var i=o(Z),s=function(e){function t(t,n){void 0===n&&(n=!0);var r=e.call(this,t,void 0,{connect:n})||this;return r._enqueuedCalls=[],r}return r(t,e),t.prototype.onOpenCallback=function(t){if(e.prototype.onOpenCallback.call(this),this.binaryType="arraybuffer",this._enqueuedCalls.length>0){for(var n=0,r=this._enqueuedCalls;n<r.length;n++){var o=r[n];this[o[0]].apply(this,o[1])}this._enqueuedCalls=[]}},t.prototype.send=function(t){if(this.ws.readyState===i.default.OPEN){if(t instanceof ArrayBuffer)return e.prototype.send.call(this,t);if(Array.isArray(t))return e.prototype.send.call(this,new Uint8Array(t).buffer)}else this._enqueuedCalls.push(["send",[t]])},t}(i.default);t.Connection=s}),te=u(function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.getSerializer=t.registerSerializer=void 0;var n={};t.registerSerializer=function(e,t){n[e]=t},t.getSerializer=function(e){var t=n[e];if(!t)throw new Error("missing serializer: "+e);return t}}),ne=u(function(e,t){var n,r;Object.defineProperty(t,"__esModule",{value:!0}),t.utf8Length=t.utf8Read=t.ErrorCode=t.Protocol=void 0,(n=t.Protocol||(t.Protocol={}))[n.HANDSHAKE=9]="HANDSHAKE",n[n.JOIN_ROOM=10]="JOIN_ROOM",n[n.ERROR=11]="ERROR",n[n.LEAVE_ROOM=12]="LEAVE_ROOM",n[n.ROOM_DATA=13]="ROOM_DATA",n[n.ROOM_STATE=14]="ROOM_STATE",n[n.ROOM_STATE_PATCH=15]="ROOM_STATE_PATCH",n[n.ROOM_DATA_SCHEMA=16]="ROOM_DATA_SCHEMA",(r=t.ErrorCode||(t.ErrorCode={}))[r.MATCHMAKE_NO_HANDLER=4210]="MATCHMAKE_NO_HANDLER",r[r.MATCHMAKE_INVALID_CRITERIA=4211]="MATCHMAKE_INVALID_CRITERIA",r[r.MATCHMAKE_INVALID_ROOM_ID=4212]="MATCHMAKE_INVALID_ROOM_ID",r[r.MATCHMAKE_UNHANDLED=4213]="MATCHMAKE_UNHANDLED",r[r.MATCHMAKE_EXPIRED=4214]="MATCHMAKE_EXPIRED",r[r.AUTH_FAILED=4215]="AUTH_FAILED",r[r.APPLICATION_ERROR=4216]="APPLICATION_ERROR",t.utf8Read=function(e,t){for(var n=e[t++],r="",o=0,i=t,s=t+n;i<s;i++){var a=e[i];if(0!=(128&a))if(192!=(224&a))if(224!=(240&a)){if(240!=(248&a))throw new Error("Invalid byte "+a.toString(16));(o=(7&a)<<18|(63&e[++i])<<12|(63&e[++i])<<6|(63&e[++i])<<0)>=65536?(o-=65536,r+=String.fromCharCode(55296+(o>>>10),56320+(1023&o))):r+=String.fromCharCode(o)}else r+=String.fromCharCode((15&a)<<12|(63&e[++i])<<6|(63&e[++i])<<0);else r+=String.fromCharCode((31&a)<<6|63&e[++i]);else r+=String.fromCharCode(a)}return r},t.utf8Length=function(e){void 0===e&&(e="");for(var t=0,n=0,r=0,o=e.length;r<o;r++)(t=e.charCodeAt(r))<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n+1}}),re=u(function(e,t){function n(e,t,n){for(var r=0,o=0,i=n.length;o<i;o++)(r=n.charCodeAt(o))<128?e[t++]=r:r<2048?(e[t++]=192|r>>6,e[t++]=128|63&r):r<55296||r>=57344?(e[t++]=224|r>>12,e[t++]=128|r>>6&63,e[t++]=128|63&r):(o++,r=65536+((1023&r)<<10|1023&n.charCodeAt(o)),e[t++]=240|r>>18,e[t++]=128|r>>12&63,e[t++]=128|r>>6&63,e[t++]=128|63&r)}function r(e,t){e.push(255&t)}function o(e,t){e.push(255&t)}function i(e,t){e.push(255&t),e.push(t>>8&255)}function s(e,t){e.push(255&t),e.push(t>>8&255)}function a(e,t){e.push(255&t),e.push(t>>8&255),e.push(t>>16&255),e.push(t>>24&255)}function u(e,t){var n=t>>24,r=t>>16,o=t>>8;e.push(255&t),e.push(255&o),e.push(255&r),e.push(255&n)}function c(e,t){var n=Math.floor(t/Math.pow(2,32));u(e,t>>>0),u(e,n)}function f(e,t){var n=t/Math.pow(2,32)>>0;u(e,t>>>0),u(e,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.number=t.string=t.boolean=t.writeFloat64=t.writeFloat32=t.float64=t.float32=t.uint64=t.int64=t.uint32=t.int32=t.uint16=t.int16=t.uint8=t.int8=t.utf8Write=void 0,t.utf8Write=n,t.int8=r,t.uint8=o,t.int16=i,t.uint16=s,t.int32=a,t.uint32=u,t.int64=c,t.uint64=f,t.float32=function(e,t){p(e,t)},t.float64=function(e,t){v(e,t)};var h=new Int32Array(2),l=new Float32Array(h.buffer),d=new Float64Array(h.buffer);function p(e,t){l[0]=t,a(e,h[0])}function v(e,t){d[0]=t,a(e,h[0]),a(e,h[1])}t.writeFloat32=p,t.writeFloat64=v,t.boolean=function(e,t){return o(e,t?1:0)},t.string=function(e,t){t||(t="");var r=function(e){for(var t=0,n=0,r=0,o=e.length;r<o;r++)(t=e.charCodeAt(r))<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}(t),i=0;if(r<32)e.push(160|r),i=1;else if(r<256)e.push(217),o(e,r),i=2;else if(r<65536)e.push(218),s(e,r),i=3;else{if(!(r<4294967296))throw new Error("String too long");e.push(219),u(e,r),i=5}return n(e,e.length,t),i+r},t.number=function e(t,n){return isNaN(n)?e(t,0):isFinite(n)?n!==(0|n)?(t.push(203),v(t,n),9):n>=0?n<128?(o(t,n),1):n<256?(t.push(204),o(t,n),2):n<65536?(t.push(205),s(t,n),3):n<4294967296?(t.push(206),u(t,n),5):(t.push(207),f(t,n),9):n>=-32?(t.push(224|n+32),1):n>=-128?(t.push(208),r(t,n),2):n>=-32768?(t.push(209),i(t,n),3):n>=-2147483648?(t.push(210),a(t,n),5):(t.push(211),c(t,n),9):e(t,n>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER)}}),oe=u(function(e,t){var n;Object.defineProperty(t,"__esModule",{value:!0}),t.OPERATION=t.TYPE_ID=t.SWITCH_TO_STRUCTURE=void 0,t.SWITCH_TO_STRUCTURE=255,t.TYPE_ID=213,(n=t.OPERATION||(t.OPERATION={}))[n.ADD=128]="ADD",n[n.REPLACE=0]="REPLACE",n[n.DELETE=64]="DELETE",n[n.DELETE_AND_ADD=192]="DELETE_AND_ADD",n[n.TOUCH=1]="TOUCH",n[n.CLEAR=10]="CLEAR"}),ie=u(function(e,t){function n(e,t){return r(e,t)<<24>>24}function r(e,t){return e[t.offset++]}function o(e,t){return i(e,t)<<16>>16}function i(e,t){return e[t.offset++]|e[t.offset++]<<8}function s(e,t){return e[t.offset++]|e[t.offset++]<<8|e[t.offset++]<<16|e[t.offset++]<<24}function a(e,t){return s(e,t)>>>0}function u(e,t){var n=a(e,t);return s(e,t)*Math.pow(2,32)+n}function c(e,t){var n=a(e,t);return a(e,t)*Math.pow(2,32)+n}Object.defineProperty(t,"__esModule",{value:!0}),t.switchStructureCheck=t.arrayCheck=t.numberCheck=t.number=t.stringCheck=t.string=t.boolean=t.readFloat64=t.readFloat32=t.uint64=t.int64=t.float64=t.float32=t.uint32=t.int32=t.uint16=t.int16=t.uint8=t.int8=void 0,t.int8=n,t.uint8=r,t.int16=o,t.uint16=i,t.int32=s,t.uint32=a,t.float32=function(e,t){return d(e,t)},t.float64=function(e,t){return p(e,t)},t.int64=u,t.uint64=c;var f=new Int32Array(2),h=new Float32Array(f.buffer),l=new Float64Array(f.buffer);function d(e,t){return f[0]=s(e,t),h[0]}function p(e,t){return f[0]=s(e,t),f[1]=s(e,t),l[0]}t.readFloat32=d,t.readFloat64=p,t.boolean=function(e,t){return r(e,t)>0},t.string=function(e,t){var n,o=e[t.offset++];o<192?n=31&o:217===o?n=r(e,t):218===o?n=i(e,t):219===o&&(n=a(e,t));var s=function(e,t,n){for(var r="",o=0,i=t,s=t+n;i<s;i++){var a=e[i];0!=(128&a)?192!=(224&a)?224!=(240&a)?240!=(248&a)?console.error("Invalid byte "+a.toString(16)):(o=(7&a)<<18|(63&e[++i])<<12|(63&e[++i])<<6|(63&e[++i])<<0)>=65536?(o-=65536,r+=String.fromCharCode(55296+(o>>>10),56320+(1023&o))):r+=String.fromCharCode(o):r+=String.fromCharCode((15&a)<<12|(63&e[++i])<<6|(63&e[++i])<<0):r+=String.fromCharCode((31&a)<<6|63&e[++i]):r+=String.fromCharCode(a)}return r}(e,t.offset,n);return t.offset+=n,s},t.stringCheck=function(e,t){var n=e[t.offset];return n<192&&n>160||217===n||218===n||219===n},t.number=function(e,t){var f=e[t.offset++];return f<128?f:202===f?d(e,t):203===f?p(e,t):204===f?r(e,t):205===f?i(e,t):206===f?a(e,t):207===f?c(e,t):208===f?n(e,t):209===f?o(e,t):210===f?s(e,t):211===f?u(e,t):f>223?-1*(255-f+1):void 0},t.numberCheck=function(e,t){var n=e[t.offset];return n<128||n>=202&&n<=211},t.arrayCheck=function(e,t){return e[t.offset]<160},t.switchStructureCheck=function(e,t){return e[t.offset-1]===oe.SWITCH_TO_STRUCTURE&&(e[t.offset]<128||e[t.offset]>=202&&e[t.offset]<=211)}}),se=u(function(e,t){var n=a&&a.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),r=a&&a.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=a&&a.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.hasOwnProperty.call(e,o)&&n(t,e,o);return r(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.Room=void 0;var i=o(z),s=o(re),u=o(ie),c=function(){function e(e,t){var n=this;this.onStateChange=q.createSignal(),this.onError=q.createSignal(),this.onLeave=q.createSignal(),this.onJoin=q.createSignal(),this.hasJoined=!1,this.onMessageHandlers=H(),this.id=null,this.name=e,t&&(this.serializer=new(te.getSerializer("schema")),this.rootSchema=t,this.serializer.state=new t),this.onError(function(e,t){return console.warn("colyseus.js - onError => ("+e+") "+t)}),this.onLeave(function(){return n.removeAllListeners()})}return e.prototype.connect=function(e){var t=this;this.connection=new ee.Connection(e,!1),this.connection.reconnectEnabled=!1,this.connection.onmessage=this.onMessageCallback.bind(this),this.connection.onclose=function(e){if(!t.hasJoined)return console.warn("Room connection was closed unexpectedly ("+e.code+"): "+e.reason),void t.onError.invoke(e.code,e.reason);t.onLeave.invoke(e.code),t.destroy()},this.connection.onerror=function(e){console.warn("Room, onError ("+e.code+"): "+e.reason),t.onError.invoke(e.code,e.reason)},this.connection.open()},e.prototype.leave=function(e){void 0===e&&(e=!0),this.connection?e?this.connection.send([ne.Protocol.LEAVE_ROOM]):this.connection.close():this.onLeave.invoke(4e3)},e.prototype.onMessage=function(e,t){return this.onMessageHandlers.on(this.getMessageHandlerKey(e),t)},e.prototype.send=function(e,t){var n,r=[ne.Protocol.ROOM_DATA];if("string"==typeof e?s.string(r,e):s.number(r,e),void 0!==t){var o=i.encode(t);(n=new Uint8Array(r.length+o.byteLength)).set(new Uint8Array(r),0),n.set(new Uint8Array(o),r.length)}else n=new Uint8Array(r);this.connection.send(n.buffer)},Object.defineProperty(e.prototype,"state",{get:function(){return this.serializer.getState()},enumerable:!1,configurable:!0}),e.prototype.listen=function(e,t,n){if("schema"!==this.serializerId)return this.serializerId||console.warn("room.Listen() should be called after room.onJoin has been called (DEPRECATION WARNING)"),this.serializer.api.listen(e,t,n);console.warn("'"+this.serializerId+"' serializer doesn't support .listen() method here.")},e.prototype.removeListener=function(e){return this.serializer.api.removeListener(e)},e.prototype.removeAllListeners=function(){this.onJoin.clear(),this.onStateChange.clear(),this.onError.clear(),this.onLeave.clear(),this.onMessageHandlers.events={}},e.prototype.onMessageCallback=function(e){var t=Array.from(new Uint8Array(e.data)),n=t[0];if(n===ne.Protocol.JOIN_ROOM){var r=1;if(this.serializerId=ne.utf8Read(t,r),r+=ne.utf8Length(this.serializerId),!this.serializer){var o=te.getSerializer(this.serializerId);this.serializer=new o}t.length>r&&this.serializer.handshake&&this.serializer.handshake(t,{offset:r}),this.hasJoined=!0,this.onJoin.invoke(),this.connection.send([ne.Protocol.JOIN_ROOM])}else if(n===ne.Protocol.ERROR){var s={offset:1},a=u.number(t,s),c=u.string(t,s);this.onError.invoke(a,c)}else if(n===ne.Protocol.LEAVE_ROOM)this.leave();else if(n===ne.Protocol.ROOM_DATA_SCHEMA){var f={offset:1};(c=new(l=this.serializer.getState().constructor._context.get(u.number(t,f)))).decode(t,f),this.dispatchMessage(l,c)}else if(n===ne.Protocol.ROOM_STATE)t.shift(),this.setState(t);else if(n===ne.Protocol.ROOM_STATE_PATCH)t.shift(),this.patch(t);else if(n===ne.Protocol.ROOM_DATA){var h={offset:1},l=u.stringCheck(t,h)?u.string(t,h):u.number(t,h);c=t.length>h.offset?i.decode(e.data,h.offset):void 0,this.dispatchMessage(l,c)}},e.prototype.setState=function(e){this.serializer.setState(e),this.onStateChange.invoke(this.serializer.getState())},e.prototype.patch=function(e){this.serializer.patch(e),this.onStateChange.invoke(this.serializer.getState())},e.prototype.dispatchMessage=function(e,t){var n=this.getMessageHandlerKey(e);this.onMessageHandlers.events[n]?this.onMessageHandlers.emit(n,t):this.onMessageHandlers.events["*"]?this.onMessageHandlers.emit("*",e,t):console.warn("onMessage not registered for type '"+e+"'.")},e.prototype.destroy=function(){this.serializer&&this.serializer.teardown()},e.prototype.getMessageHandlerKey=function(e){switch(typeof e){case"function":return"$"+e._typeid;case"string":return e;case"number":return"i"+e;default:throw new Error("invalid message type.")}},e}();t.Room=c}),ae=u(function(e,t){var n;function r(){return n||(n="undefined"!=typeof cc&&cc.sys&&cc.sys.localStorage?cc.sys.localStorage:"undefined"!=typeof window&&window.localStorage?window.localStorage:{cache:{},setItem:function(e,t){this.cache[e]=t},getItem:function(e){},removeItem:function(e){delete this.cache[e]}}),n}Object.defineProperty(t,"__esModule",{value:!0}),t.getItem=t.removeItem=t.setItem=void 0,t.setItem=function(e,t){r().setItem(e,t)},t.removeItem=function(e){r().removeItem(e)},t.getItem=function(e,t){var n=r().getItem(e);"undefined"!=typeof Promise&&n instanceof Promise?n.then(function(e){return t(e)}):t(n)}}),ue=u(function(e,t){var n=a&&a.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),r=a&&a.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=a&&a.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.hasOwnProperty.call(e,o)&&n(t,e,o);return r(t,e),t},i=a&&a.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}u((r=r.apply(e,t||[])).next())})},s=a&&a.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.Auth=t.Platform=void 0;var u,c=o(j),f="colyseus-auth-token";(u=t.Platform||(t.Platform={})).ios="ios",u.android="android";var h=function(){function e(e){var t=this;this._id=void 0,this.username=void 0,this.displayName=void 0,this.avatarUrl=void 0,this.isAnonymous=void 0,this.email=void 0,this.lang=void 0,this.location=void 0,this.timezone=void 0,this.metadata=void 0,this.devices=void 0,this.facebookId=void 0,this.twitterId=void 0,this.googleId=void 0,this.gameCenterId=void 0,this.steamId=void 0,this.friendIds=void 0,this.blockedUserIds=void 0,this.createdAt=void 0,this.updatedAt=void 0,this.token=void 0,this.endpoint=e.replace("ws","http"),ae.getItem(f,function(e){return t.token=e})}return Object.defineProperty(e.prototype,"hasToken",{get:function(){return!!this.token},enumerable:!1,configurable:!0}),e.prototype.login=function(e){return void 0===e&&(e={}),i(this,void 0,void 0,function(){var t,n,r;return s(this,function(o){switch(o.label){case 0:return t=Object.assign({},e),this.hasToken&&(t.token=this.token),[4,this.request("post","/auth",t)];case 1:for(r in n=o.sent(),this.token=n.token,ae.setItem(f,this.token),n)this.hasOwnProperty(r)&&(this[r]=n[r]);return this.registerPingService(),[2,this]}})})},e.prototype.save=function(){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.request("put","/auth",{},{username:this.username,displayName:this.displayName,avatarUrl:this.avatarUrl,lang:this.lang,location:this.location,timezone:this.timezone})];case 1:return e.sent(),[2,this]}})})},e.prototype.getFriends=function(){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.request("get","/friends/all")];case 1:return[2,e.sent()]}})})},e.prototype.getOnlineFriends=function(){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.request("get","/friends/online")];case 1:return[2,e.sent()]}})})},e.prototype.getFriendRequests=function(){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.request("get","/friends/requests")];case 1:return[2,e.sent()]}})})},e.prototype.sendFriendRequest=function(e){return i(this,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,this.request("post","/friends/requests",{userId:e})];case 1:return[2,t.sent()]}})})},e.prototype.acceptFriendRequest=function(e){return i(this,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,this.request("put","/friends/requests",{userId:e})];case 1:return[2,t.sent()]}})})},e.prototype.declineFriendRequest=function(e){return i(this,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,this.request("del","/friends/requests",{userId:e})];case 1:return[2,t.sent()]}})})},e.prototype.blockUser=function(e){return i(this,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,this.request("post","/friends/block",{userId:e})];case 1:return[2,t.sent()]}})})},e.prototype.unblockUser=function(e){return i(this,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:return[4,this.request("put","/friends/block",{userId:e})];case 1:return[2,t.sent()]}})})},e.prototype.request=function(e,t,n,r,o){return void 0===n&&(n={}),void 0===o&&(o={}),i(this,void 0,void 0,function(){var i,a,u,f;return s(this,function(s){switch(s.label){case 0:for(a in o.Accept="application/json",this.hasToken&&(o.Authorization="Bearer "+this.token),i=[],n)i.push(a+"="+n[a]);return u=i.length>0?"?"+i.join("&"):"",f={headers:o},r&&(f.body=r),[4,c[e](""+this.endpoint+t+u,f)];case 1:return[2,s.sent().data]}})})},e.prototype.logout=function(){this.token=void 0,ae.removeItem(f),this.unregisterPingService()},e.prototype.registerPingService=function(e){var t=this;void 0===e&&(e=15e3),this.unregisterPingService(),this.keepOnlineInterval=setInterval(function(){return t.request("get","/auth")},e)},e.prototype.unregisterPingService=function(){clearInterval(this.keepOnlineInterval)},e}();t.Auth=h}),ce=u(function(e,t){var n=a&&a.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}u((r=r.apply(e,t||[])).next())})},r=a&&a.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.Push=void 0;var o=function(){function e(e){this.endpoint=e.replace("ws","http")}return e.prototype.register=function(){return n(this,void 0,void 0,function(){return r(this,function(e){switch(e.label){case 0:return this.check(),[4,this.registerServiceWorker()];case 1:return e.sent(),[4,this.requestNotificationPermission()];case 2:return e.sent(),[2]}})})},e.prototype.registerServiceWorker=function(){return n(this,void 0,void 0,function(){return r(this,function(e){switch(e.label){case 0:return[4,navigator.serviceWorker.register(this.endpoint+"/push")];case 1:return[2,e.se