@needle-tools/engine 3.6.0-alpha → 3.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/needle-engine.js +3 -3
- package/dist/needle-engine.light.js +4956 -4956
- package/dist/needle-engine.light.min.js +3 -3
- package/dist/needle-engine.light.umd.cjs +3 -3
- package/dist/needle-engine.min.js +3 -3
- package/dist/needle-engine.umd.cjs +3 -3
- package/package.json +1 -1
- package/plugins/vite/defines.js +5 -2
|
@@ -3333,11 +3333,11 @@ a=extmap-allow-mixed`)!==-1){const r=s.sdp.split(`
|
|
|
3333
3333
|
isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},i}()),zk={iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:["turn:eu-0.turn.peerjs.com:3478","turn:us-0.turn.peerjs.com:3478"],username:"peerjs",credential:"peerjsp"}],sdpSemantics:"unified-plan"},y8=function(){function i(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=zk,this.browser=sg.getBrowser(),this.browserVersion=sg.getVersion(),this.supports=function(){var e={browser:sg.isBrowserSupported(),webRTC:sg.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(zk),e.audioVideo=!0;var s=void 0;try{s=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!s.ordered;try{s.binaryType="blob",e.binaryBlob=!sg.isIOS}catch{}}catch{}finally{s&&s.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=qB.pack,this.unpack=qB.unpack,this._dataCount=1}return i.prototype.noop=function(){},i.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},i.prototype.chunk=function(e){for(var t=[],s=e.size,r=Math.ceil(s/oi.chunkedMTU),n=0,o=0;o<s;){var a=Math.min(s,o+oi.chunkedMTU),l=e.slice(o,a),c={__peerData:this._dataCount,n,data:l,total:r};t.push(c),o=a,n++}return this._dataCount++,t},i.prototype.blobToArrayBuffer=function(e,t){var s=new FileReader;return s.onload=function(r){r.target&&t(r.target.result)},s.readAsArrayBuffer(e),s},i.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),s=0;s<e.length;s++)t[s]=e.charCodeAt(s)&255;return t.buffer},i.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},i.prototype.isSecure=function(){return location.protocol==="https:"},i}(),oi=new y8,Qk={};jo(Qk,"Peer",()=>i2,i=>i2=i);var rg={},b8=Object.prototype.hasOwnProperty,wr="~";function ng(){}Object.create&&(ng.prototype=Object.create(null),new ng().__proto__||(wr=!1));function _8(i,e,t){this.fn=i,this.context=e,this.once=t||!1}function jk(i,e,t,s,r){if(typeof t!="function")throw new TypeError("The listener must be a function");var n=new _8(t,s||i,r),o=wr?wr+e:e;return i._events[o]?i._events[o].fn?i._events[o]=[i._events[o],n]:i._events[o].push(n):(i._events[o]=n,i._eventsCount++),i}function Q0(i,e){--i._eventsCount===0?i._events=new ng:delete i._events[e]}function or(){this._events=new ng,this._eventsCount=0}or.prototype.eventNames=function(){var i=[],e,t;if(this._eventsCount===0)return i;for(t in e=this._events)b8.call(e,t)&&i.push(wr?t.slice(1):t);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},or.prototype.listeners=function(i){var e=wr?wr+i:i,t=this._events[e];if(!t)return[];if(t.fn)return[t.fn];for(var s=0,r=t.length,n=new Array(r);s<r;s++)n[s]=t[s].fn;return n},or.prototype.listenerCount=function(i){var e=wr?wr+i:i,t=this._events[e];return t?t.fn?1:t.length:0},or.prototype.emit=function(i,e,t,s,r,n){var o=wr?wr+i:i;if(!this._events[o])return!1;var a=this._events[o],l=arguments.length,c,u;if(a.fn){switch(a.once&&this.removeListener(i,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,t),!0;case 4:return a.fn.call(a.context,e,t,s),!0;case 5:return a.fn.call(a.context,e,t,s,r),!0;case 6:return a.fn.call(a.context,e,t,s,r,n),!0}for(u=1,c=new Array(l-1);u<l;u++)c[u-1]=arguments[u];a.fn.apply(a.context,c)}else{var d=a.length,p;for(u=0;u<d;u++)switch(a[u].once&&this.removeListener(i,a[u].fn,void 0,!0),l){case 1:a[u].fn.call(a[u].context);break;case 2:a[u].fn.call(a[u].context,e);break;case 3:a[u].fn.call(a[u].context,e,t);break;case 4:a[u].fn.call(a[u].context,e,t,s);break;default:if(!c)for(p=1,c=new Array(l-1);p<l;p++)c[p-1]=arguments[p];a[u].fn.apply(a[u].context,c)}}return!0},or.prototype.on=function(i,e,t){return jk(this,i,e,t,!1)},or.prototype.once=function(i,e,t){return jk(this,i,e,t,!0)},or.prototype.removeListener=function(i,e,t,s){var r=wr?wr+i:i;if(!this._events[r])return this;if(!e)return Q0(this,r),this;var n=this._events[r];if(n.fn)n.fn===e&&(!s||n.once)&&(!t||n.context===t)&&Q0(this,r);else{for(var o=0,a=[],l=n.length;o<l;o++)(n[o].fn!==e||s&&!n[o].once||t&&n[o].context!==t)&&a.push(n[o]);a.length?this._events[r]=a.length===1?a[0]:a:Q0(this,r)}return this},or.prototype.removeAllListeners=function(i){var e;return i?(e=wr?wr+i:i,this._events[e]&&Q0(this,e)):(this._events=new ng,this._eventsCount=0),this},or.prototype.off=or.prototype.removeListener,or.prototype.addListener=or.prototype.on,or.prefixed=wr,or.EventEmitter=or,rg=or;var et={};jo(et,"LogLevel",()=>zr,i=>zr=i),jo(et,"default",()=>Gk,i=>Gk=i);var zh=function(i,e){var t=typeof Symbol=="function"&&i[Symbol.iterator];if(!t)return i;var s=t.call(i),r,n=[],o;try{for(;(e===void 0||e-- >0)&&!(r=s.next()).done;)n.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(t=s.return)&&t.call(s)}finally{if(o)throw o.error}}return n},Qh=function(i,e,t){if(t||arguments.length===2)for(var s=0,r=e.length,n;s<r;s++)(n||!(s in e))&&(n||(n=Array.prototype.slice.call(e,0,s)),n[s]=e[s]);return i.concat(n||Array.prototype.slice.call(e))},w8="PeerJS: ",zr;(function(i){i[i.Disabled=0]="Disabled",i[i.Errors=1]="Errors",i[i.Warnings=2]="Warnings",i[i.All=3]="All"})(zr||(zr={}));var x8=function(){function i(){this._logLevel=zr.Disabled}return Object.defineProperty(i.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),i.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=zr.All&&this._print.apply(this,Qh([zr.All],zh(e),!1))},i.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=zr.Warnings&&this._print.apply(this,Qh([zr.Warnings],zh(e),!1))},i.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=zr.Errors&&this._print.apply(this,Qh([zr.Errors],zh(e),!1))},i.prototype.setLogFunction=function(e){this._print=e},i.prototype._print=function(e){for(var t=[],s=1;s<arguments.length;s++)t[s-1]=arguments[s];var r=Qh([w8],zh(t),!1);for(var n in r)r[n]instanceof Error&&(r[n]="("+r[n].name+") "+r[n].message);e>=zr.All?console.log.apply(console,Qh([],zh(r),!1)):e>=zr.Warnings?console.warn.apply(console,Qh(["WARNING"],zh(r),!1)):e>=zr.Errors&&console.error.apply(console,Qh(["ERROR"],zh(r),!1))},i}(),Gk=new x8,Hk={};jo(Hk,"Socket",()=>Vk,i=>Vk=i);var go;(function(i){i.Data="data",i.Media="media"})(go||(go={}));var Ji;(function(i){i.BrowserIncompatible="browser-incompatible",i.Disconnected="disconnected",i.InvalidID="invalid-id",i.InvalidKey="invalid-key",i.Network="network",i.PeerUnavailable="peer-unavailable",i.SslUnavailable="ssl-unavailable",i.ServerError="server-error",i.SocketError="socket-error",i.SocketClosed="socket-closed",i.UnavailableID="unavailable-id",i.WebRTC="webrtc"})(Ji||(Ji={}));var Ja;(function(i){i.Binary="binary",i.BinaryUTF8="binary-utf8",i.JSON="json"})(Ja||(Ja={}));var Ka;(function(i){i.Message="message",i.Disconnected="disconnected",i.Error="error",i.Close="close"})(Ka||(Ka={}));var js;(function(i){i.Heartbeat="HEARTBEAT",i.Candidate="CANDIDATE",i.Offer="OFFER",i.Answer="ANSWER",i.Open="OPEN",i.Error="ERROR",i.IdTaken="ID-TAKEN",i.InvalidKey="INVALID-KEY",i.Leave="LEAVE",i.Expire="EXPIRE"})(js||(js={}));var G1={};G1=JSON.parse('{"name":"peerjs","version":"1.4.7","keywords":["peerjs","webrtc","p2p","rtc"],"description":"PeerJS client","homepage":"https://peerjs.com","bugs":{"url":"https://github.com/peers/peerjs/issues"},"repository":{"type":"git","url":"https://github.com/peers/peerjs"},"license":"MIT","contributors":["Michelle Bu <michelle@michellebu.com>","afrokick <devbyru@gmail.com>","ericz <really.ez@gmail.com>","Jairo <kidandcat@gmail.com>","Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>","Jairo Caro-Accino Viciana <jairo@galax.be>","Carlos Caballero <carlos.caballero.gonzalez@gmail.com>","hc <hheennrryy@gmail.com>","Muhammad Asif <capripio@gmail.com>","PrashoonB <prashoonbhattacharjee@gmail.com>","Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>","akotynski <aleksanderkotbury@gmail.com>","lmb <i@lmb.io>","Jairooo <jairocaro@msn.com>","Moritz St\xFCckler <moritz.stueckler@gmail.com>","Simon <crydotsnakegithub@gmail.com>","Denis Lukov <denismassters@gmail.com>","Philipp Hancke <fippo@andyet.net>","Hans Oksendahl <hansoksendahl@gmail.com>","Jess <jessachandler@gmail.com>","khankuan <khankuan@gmail.com>","DUODVK <kurmanov.work@gmail.com>","XiZhao <kwang1imsa@gmail.com>","Matthias Lohr <matthias@lohr.me>","=frank tree <=frnktrb@googlemail.com>","Andre Eckardt <aeckardt@outlook.com>","Chris Cowan <agentme49@gmail.com>","Alex Chuev <alex@chuev.com>","alxnull <alxnull@e.mail.de>","Yemel Jardi <angel.jardi@gmail.com>","Ben Parnell <benjaminparnell.94@gmail.com>","Benny Lichtner <bennlich@gmail.com>","fresheneesz <bitetrudpublic@gmail.com>","bob.barstead@exaptive.com <bob.barstead@exaptive.com>","chandika <chandika@gmail.com>","emersion <contact@emersion.fr>","Christopher Van <cvan@users.noreply.github.com>","eddieherm <edhermoso@gmail.com>","Eduardo Pinho <enet4mikeenet@gmail.com>","Evandro Zanatta <ezanatta@tray.net.br>","Gardner Bickford <gardner@users.noreply.github.com>","Gian Luca <gianluca.cecchi@cynny.com>","PatrickJS <github@gdi2290.com>","jonnyf <github@jonathanfoss.co.uk>","Hizkia Felix <hizkifw@gmail.com>","Hristo Oskov <hristo.oskov@gmail.com>","Isaac Madwed <i.madwed@gmail.com>","Ilya Konanykhin <ilya.konanykhin@gmail.com>","jasonbarry <jasbarry@me.com>","Jonathan Burke <jonathan.burke.1311@googlemail.com>","Josh Hamit <josh.hamit@gmail.com>","Jordan Austin <jrax86@gmail.com>","Joel Wetzell <jwetzell@yahoo.com>","xizhao <kevin.wang@cloudera.com>","Alberto Torres <kungfoobar@gmail.com>","Jonathan Mayol <mayoljonathan@gmail.com>","Jefferson Felix <me@jsfelix.dev>","Rolf Erik Lekang <me@rolflekang.com>","Kevin Mai-Husan Chia <mhchia@users.noreply.github.com>","Pepijn de Vos <pepijndevos@gmail.com>","JooYoung <qkdlql@naver.com>","Tobias Speicher <rootcommander@gmail.com>","Steve Blaurock <sblaurock@gmail.com>","Kyrylo Shegeda <shegeda@ualberta.ca>","Diwank Singh Tomer <singh@diwank.name>","So\u0308ren Balko <Soeren.Balko@gmail.com>","Arpit Solanki <solankiarpit1997@gmail.com>","Yuki Ito <yuki@gnnk.net>","Artur Zayats <zag2art@gmail.com>"],"funding":{"type":"opencollective","url":"https://opencollective.com/peer"},"collective":{"type":"opencollective","url":"https://opencollective.com/peer"},"files":["dist/*"],"sideEffects":["lib/global.ts","lib/supports.ts"],"main":"dist/bundler.cjs","module":"dist/bundler.mjs","browser-minified":"dist/peerjs.min.js","browser-unminified":"dist/peerjs.js","types":"dist/types.d.ts","engines":{"node":">= 10"},"targets":{"types":{"source":"lib/exports.ts"},"main":{"source":"lib/exports.ts","sourceMap":{"inlineSources":true}},"module":{"source":"lib/exports.ts","includeNodeModules":["eventemitter3"],"sourceMap":{"inlineSources":true}},"browser-minified":{"context":"browser","outputFormat":"global","optimize":true,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"},"browser-unminified":{"context":"browser","outputFormat":"global","optimize":false,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"}},"scripts":{"contributors":"git-authors-cli --print=false && prettier --write package.json && git add package.json package-lock.json && git commit -m \\"chore(contributors): update and sort contributors list\\"","check":"tsc --noEmit","watch":"parcel watch","build":"rm -rf dist && parcel build","prepublishOnly":"npm run build","test":"mocha -r ts-node/register -r jsdom-global/register test/**/*.ts","format":"prettier --write .","semantic-release":"semantic-release"},"devDependencies":{"@parcel/config-default":"^2.5.0","@parcel/packager-ts":"^2.5.0","@parcel/transformer-typescript-tsc":"^2.5.0","@parcel/transformer-typescript-types":"^2.5.0","@semantic-release/changelog":"^6.0.1","@semantic-release/git":"^10.0.1","@types/chai":"^4.3.0","@types/mocha":"^9.1.0","@types/node":"^17.0.18","chai":"^4.3.6","git-authors-cli":"^1.0.40","jsdom":"^19.0.0","jsdom-global":"^3.0.2","mocha":"^9.2.0","mock-socket":"8.0.5","parcel":"^2.5.0","parcel-transformer-tsc-sourcemaps":"^1.0.2","prettier":"^2.6.2","semantic-release":"^19.0.2","standard":"^16.0.4","ts-node":"^10.5.0","typescript":"^4.5.5"},"dependencies":{"@swc/helpers":"^0.3.13","eventemitter3":"^4.0.7","peerjs-js-binarypack":"1.0.1","webrtc-adapter":"^7.7.1"}}');var C8=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,r){s.__proto__=r}||function(s,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(s[n]=r[n])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function s(){this.constructor=e}e.prototype=t===null?Object.create(t):(s.prototype=t.prototype,new s)}}(),S8=function(i,e){var t=typeof Symbol=="function"&&i[Symbol.iterator];if(!t)return i;var s=t.call(i),r,n=[],o;try{for(;(e===void 0||e-- >0)&&!(r=s.next()).done;)n.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(t=s.return)&&t.call(s)}finally{if(o)throw o.error}}return n},E8=function(i,e,t){if(t||arguments.length===2)for(var s=0,r=e.length,n;s<r;s++)(n||!(s in e))&&(n||(n=Array.prototype.slice.call(e,0,s)),n[s]=e[s]);return i.concat(n||Array.prototype.slice.call(e))},M8=function(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],s=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&s>=i.length&&(i=void 0),{value:i&&i[s++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Vk=function(i){C8(e,i);function e(t,s,r,n,o,a){a===void 0&&(a=5e3);var l=i.call(this)||this;l.pingInterval=a,l._disconnected=!0,l._messagesQueue=[];var c=t?"wss://":"ws://";return l._baseUrl=c+s+":"+r+n+"peerjs?key="+o,l}return e.prototype.start=function(t,s){var r=this;this._id=t;var n="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(s);this._socket||!this._disconnected||(this._socket=new WebSocket(n+"&version="+G1.version),this._disconnected=!1,this._socket.onmessage=function(o){var a;try{a=JSON.parse(o.data),et.default.log("Server message received:",a)}catch{et.default.log("Invalid server message",o.data);return}r.emit(Ka.Message,a)},this._socket.onclose=function(o){r._disconnected||(et.default.log("Socket closed.",o),r._cleanup(),r._disconnected=!0,r.emit(Ka.Disconnected))},this._socket.onopen=function(){r._disconnected||(r._sendQueuedMessages(),et.default.log("Socket open"),r._scheduleHeartbeat())})},e.prototype._scheduleHeartbeat=function(){var t=this;this._wsPingTimer=setTimeout(function(){t._sendHeartbeat()},this.pingInterval)},e.prototype._sendHeartbeat=function(){if(!this._wsOpen()){et.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:js.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,s,r=E8([],S8(this._messagesQueue),!1);this._messagesQueue=[];try{for(var n=M8(r),o=n.next();!o.done;o=n.next()){var a=o.value;this.send(a)}}catch(l){t={error:l}}finally{try{o&&!o.done&&(s=n.return)&&s.call(n)}finally{if(t)throw t.error}}},e.prototype.send=function(t){if(!this._disconnected){if(!this._id){this._messagesQueue.push(t);return}if(!t.type){this.emit(Ka.Error,"Invalid message");return}if(this._wsOpen()){var s=JSON.stringify(t);this._socket.send(s)}}},e.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},e.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)},e}(rg.EventEmitter),H1={};jo(H1,"MediaConnection",()=>Xk,i=>Xk=i);var V1={};jo(V1,"Negotiator",()=>Wk,i=>Wk=i);var j0=function(){return j0=Object.assign||function(i){for(var e,t=1,s=arguments.length;t<s;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},j0.apply(this,arguments)},G0=function(i,e,t,s){function r(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function a(u){try{c(s.next(u))}catch(d){o(d)}}function l(u){try{c(s.throw(u))}catch(d){o(d)}}function c(u){u.done?n(u.value):r(u.value).then(a,l)}c((s=s.apply(i,e||[])).next())})},H0=function(i,e){var t={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},s,r,n,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(u){return l([c,u])}}function l(c){if(s)throw new TypeError("Generator is already executing.");for(;t;)try{if(s=1,r&&(n=c[0]&2?r.return:c[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,c[1])).done)return n;switch(r=0,n&&(c=[c[0]&2,n.value]),c[0]){case 0:case 1:n=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,r=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(n=t.trys,!(n=n.length>0&&n[n.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!n||c[1]>n[0]&&c[1]<n[3])){t.label=c[1];break}if(c[0]===6&&t.label<n[1]){t.label=n[1],n=c;break}if(n&&t.label<n[2]){t.label=n[2],t.ops.push(c);break}n[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(i,t)}catch(u){c=[6,u],r=0}finally{s=n=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},Wk=function(){function i(e){this.connection=e}return i.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===go.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===go.Data){var s=this.connection,r={ordered:!!e.reliable},n=t.createDataChannel(s.label,r);s.initialize(n)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},i.prototype._startPeerConnection=function(){et.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},i.prototype._setupListeners=function(e){var t=this,s=this.connection.peer,r=this.connection.connectionId,n=this.connection.type,o=this.connection.provider;et.default.log("Listening for ICE candidates."),e.onicecandidate=function(a){!a.candidate||!a.candidate.candidate||(et.default.log("Received ICE candidates for ".concat(s,":"),a.candidate),o.socket.send({type:js.Candidate,payload:{candidate:a.candidate,type:n,connectionId:r},dst:s}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":et.default.log("iceConnectionState is failed, closing connections to "+s),t.connection.emit("error",new Error("Negotiation of connection to "+s+" failed.")),t.connection.close();break;case"closed":et.default.log("iceConnectionState is closed, closing connections to "+s),t.connection.emit("error",new Error("Connection to "+s+" closed.")),t.connection.close();break;case"disconnected":et.default.log("iceConnectionState changed to disconnected on the connection with "+s);break;case"completed":e.onicecandidate=oi.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},et.default.log("Listening for data channel"),e.ondatachannel=function(a){et.default.log("Received data channel");var l=a.channel,c=o.getConnection(s,r);c.initialize(l)},et.default.log("Listening for remote stream"),e.ontrack=function(a){et.default.log("Received remote stream");var l=a.streams[0],c=o.getConnection(s,r);if(c.type===go.Media){var u=c;t._addStreamToMediaConnection(l,u)}}},i.prototype.cleanup=function(){et.default.log("Cleaning up PeerConnection to "+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!=="closed",s=!1;if(this.connection.type===go.Data){var r=this.connection,n=r.dataChannel;n&&(s=!!n.readyState&&n.readyState!=="closed")}(t||s)&&e.close()}},i.prototype._makeOffer=function(){return G0(this,void 0,Promise,function(){var e,t,s,r,n,o,a;return H0(this,function(l){switch(l.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,l.label=1;case 1:return l.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:s=l.sent(),et.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(s.sdp=this.connection.options.sdpTransform(s.sdp)||s.sdp),l.label=3;case 3:return l.trys.push([3,5,,6]),[4,e.setLocalDescription(s)];case 4:return l.sent(),et.default.log("Set localDescription:",s,"for:".concat(this.connection.peer)),r={sdp:s,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:oi.browser},this.connection.type===go.Data&&(n=this.connection,r=j0(j0({},r),{label:n.label,reliable:n.reliable,serialization:n.serialization})),t.socket.send({type:js.Offer,payload:r,dst:this.connection.peer}),[3,6];case 5:return o=l.sent(),o!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(t.emitError(Ji.WebRTC,o),et.default.log("Failed to setLocalDescription, ",o)),[3,6];case 6:return[3,8];case 7:return a=l.sent(),t.emitError(Ji.WebRTC,a),et.default.log("Failed to createOffer, ",a),[3,8];case 8:return[2]}})})},i.prototype._makeAnswer=function(){return G0(this,void 0,Promise,function(){var e,t,s,r,n;return H0(this,function(o){switch(o.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,o.label=1;case 1:return o.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:s=o.sent(),et.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(s.sdp=this.connection.options.sdpTransform(s.sdp)||s.sdp),o.label=3;case 3:return o.trys.push([3,5,,6]),[4,e.setLocalDescription(s)];case 4:return o.sent(),et.default.log("Set localDescription:",s,"for:".concat(this.connection.peer)),t.socket.send({type:js.Answer,payload:{sdp:s,type:this.connection.type,connectionId:this.connection.connectionId,browser:oi.browser},dst:this.connection.peer}),[3,6];case 5:return r=o.sent(),t.emitError(Ji.WebRTC,r),et.default.log("Failed to setLocalDescription, ",r),[3,6];case 6:return[3,8];case 7:return n=o.sent(),t.emitError(Ji.WebRTC,n),et.default.log("Failed to create answer, ",n),[3,8];case 8:return[2]}})})},i.prototype.handleSDP=function(e,t){return G0(this,void 0,Promise,function(){var s,r,n,o;return H0(this,function(a){switch(a.label){case 0:t=new RTCSessionDescription(t),s=this.connection.peerConnection,r=this.connection.provider,et.default.log("Setting remote description",t),n=this,a.label=1;case 1:return a.trys.push([1,5,,6]),[4,s.setRemoteDescription(t)];case 2:return a.sent(),et.default.log("Set remoteDescription:".concat(e," for:").concat(this.connection.peer)),e!=="OFFER"?[3,4]:[4,n._makeAnswer()];case 3:a.sent(),a.label=4;case 4:return[3,6];case 5:return o=a.sent(),r.emitError(Ji.WebRTC,o),et.default.log("Failed to setRemoteDescription, ",o),[3,6];case 6:return[2]}})})},i.prototype.handleCandidate=function(e){return G0(this,void 0,Promise,function(){var t,s,r,n,o,a;return H0(this,function(l){switch(l.label){case 0:et.default.log("handleCandidate:",e),t=e.candidate,s=e.sdpMLineIndex,r=e.sdpMid,n=this.connection.peerConnection,o=this.connection.provider,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,n.addIceCandidate(new RTCIceCandidate({sdpMid:r,sdpMLineIndex:s,candidate:t}))];case 2:return l.sent(),et.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return a=l.sent(),o.emitError(Ji.WebRTC,a),et.default.log("Failed to handleCandidate, ",a),[3,4];case 4:return[2]}})})},i.prototype._addTracksToConnection=function(e,t){if(et.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return et.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(s){t.addTrack(s,e)})},i.prototype._addStreamToMediaConnection=function(e,t){et.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},i}(),W1={};jo(W1,"BaseConnection",()=>qk,i=>qk=i);var I8=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,r){s.__proto__=r}||function(s,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(s[n]=r[n])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function s(){this.constructor=e}e.prototype=t===null?Object.create(t):(s.prototype=t.prototype,new s)}}(),qk=function(i){I8(e,i);function e(t,s,r){var n=i.call(this)||this;return n.peer=t,n.provider=s,n.options=r,n._open=!1,n.metadata=r.metadata,n}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e}(rg.EventEmitter),T8=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,r){s.__proto__=r}||function(s,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(s[n]=r[n])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function s(){this.constructor=e}e.prototype=t===null?Object.create(t):(s.prototype=t.prototype,new s)}}(),V0=function(){return V0=Object.assign||function(i){for(var e,t=1,s=arguments.length;t<s;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},V0.apply(this,arguments)},R8=function(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],s=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&s>=i.length&&(i=void 0),{value:i&&i[s++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Xk=function(i){T8(e,i);function e(t,s,r){var n=i.call(this,t,s,r)||this;return n._localStream=n.options._stream,n.connectionId=n.options.connectionId||e.ID_PREFIX+oi.randomToken(),n._negotiator=new V1.Negotiator(n),n._localStream&&n._negotiator.startConnection({_stream:n._localStream,originator:!0}),n}return Object.defineProperty(e.prototype,"type",{get:function(){return go.Media},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localStream",{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteStream",{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),e.prototype.addStream=function(t){et.default.log("Receiving stream",t),this._remoteStream=t,i.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var s=t.type,r=t.payload;switch(t.type){case js.Answer:this._negotiator.handleSDP(s,r.sdp),this._open=!0;break;case js.Candidate:this._negotiator.handleCandidate(r.candidate);break;default:et.default.warn("Unrecognized message type:".concat(s," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,s){var r,n;if(s===void 0&&(s={}),this._localStream){et.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,s&&s.sdpTransform&&(this.options.sdpTransform=s.sdpTransform),this._negotiator.startConnection(V0(V0({},this.options._payload),{_stream:t}));var o=this.provider._getMessages(this.connectionId);try{for(var a=R8(o),l=a.next();!l.done;l=a.next()){var c=l.value;this.handleMessage(c)}}catch(u){r={error:u}}finally{try{l&&!l.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}this._open=!0},e.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,i.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e}(W1.BaseConnection),q1={};jo(q1,"DataConnection",()=>Kk,i=>Kk=i);var Yk={};jo(Yk,"EncodingQueue",()=>Jk,i=>Jk=i);var P8=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,r){s.__proto__=r}||function(s,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(s[n]=r[n])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function s(){this.constructor=e}e.prototype=t===null?Object.create(t):(s.prototype=t.prototype,new s)}}(),Jk=function(i){P8(e,i);function e(){var t=i.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(s){t._processing=!1,s.target&&t.emit("done",s.target.result),t.doNextTask()},t.fileReader.onerror=function(s){et.default.error("EncodingQueue error:",s),t._processing=!1,t.destroy(),t.emit("error",s)},t}return Object.defineProperty(e.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),e.prototype.enque=function(t){this.queue.push(t),!this.processing&&this.doNextTask()},e.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},e.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},e}(rg.EventEmitter),B8=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,r){s.__proto__=r}||function(s,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(s[n]=r[n])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function s(){this.constructor=e}e.prototype=t===null?Object.create(t):(s.prototype=t.prototype,new s)}}(),k8=function(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],s=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&s>=i.length&&(i=void 0),{value:i&&i[s++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Kk=function(i){B8(e,i);function e(t,s,r){var n=i.call(this,t,s,r)||this;return n.stringify=JSON.stringify,n.parse=JSON.parse,n._buffer=[],n._bufferSize=0,n._buffering=!1,n._chunkedData={},n._encodingQueue=new Yk.EncodingQueue,n.connectionId=n.options.connectionId||e.ID_PREFIX+oi.randomToken(),n.label=n.options.label||n.connectionId,n.serialization=n.options.serialization||Ja.Binary,n.reliable=!!n.options.reliable,n._encodingQueue.on("done",function(o){n._bufferedSend(o)}),n._encodingQueue.on("error",function(){et.default.error("DC#".concat(n.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),n.close()}),n._negotiator=new V1.Negotiator(n),n._negotiator.startConnection(n.options._payload||{originator:!0}),n}return Object.defineProperty(e.prototype,"type",{get:function(){return go.Data},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataChannel",{get:function(){return this._dc},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bufferSize",{get:function(){return this._bufferSize},enumerable:!1,configurable:!0}),e.prototype.initialize=function(t){this._dc=t,this._configureDataChannel()},e.prototype._configureDataChannel=function(){var t=this;(!oi.supports.binaryBlob||oi.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){et.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(s){et.default.log("DC#".concat(t.connectionId," dc onmessage:"),s.data),t._handleDataMessage(s)},this.dataChannel.onclose=function(){et.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var s=this,r=t.data,n=r.constructor,o=this.serialization===Ja.Binary||this.serialization===Ja.BinaryUTF8,a=r;if(o){if(n===Blob){oi.blobToArrayBuffer(r,function(c){var u=oi.unpack(c);s.emit("data",u)});return}else if(n===ArrayBuffer)a=oi.unpack(r);else if(n===String){var l=oi.binaryStringToArrayBuffer(r);a=oi.unpack(l)}}else this.serialization===Ja.JSON&&(a=this.parse(r));if(a.__peerData){this._handleChunk(a);return}i.prototype.emit.call(this,"data",a)},e.prototype._handleChunk=function(t){var s=t.__peerData,r=this._chunkedData[s]||{data:[],count:0,total:t.total};if(r.data[t.n]=t.data,r.count++,this._chunkedData[s]=r,r.total===r.count){delete this._chunkedData[s];var n=new Blob(r.data);this._handleDataMessage({data:n})}},e.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),this._encodingQueue=null),this.open&&(this._open=!1,i.prototype.emit.call(this,"close"))},e.prototype.send=function(t,s){if(!this.open){i.prototype.emit.call(this,"error",new Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===Ja.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===Ja.Binary||this.serialization===Ja.BinaryUTF8){var r=oi.pack(t);if(!s&&r.size>oi.chunkedMTU){this._sendChunks(r);return}oi.supports.binaryBlob?this._bufferedSend(r):this._encodingQueue.enque(r)}else this._bufferedSend(t)},e.prototype._bufferedSend=function(t){(this._buffering||!this._trySend(t))&&(this._buffer.push(t),this._bufferSize=this._buffer.length)},e.prototype._trySend=function(t){var s=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){s._buffering=!1,s._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(r){return et.default.error("DC#:".concat(this.connectionId," Error when sending:"),r),this._buffering=!0,this.close(),!1}return!0},e.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},e.prototype._sendChunks=function(t){var s,r,n=oi.chunk(t);et.default.log("DC#".concat(this.connectionId," Try to send ").concat(n.length," chunks..."));try{for(var o=k8(n),a=o.next();!a.done;a=o.next()){var l=a.value;this.send(l,!0)}}catch(c){s={error:c}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(s)throw s.error}}},e.prototype.handleMessage=function(t){var s=t.payload;switch(t.type){case js.Answer:this._negotiator.handleSDP(t.type,s.sdp);break;case js.Candidate:this._negotiator.handleCandidate(s.candidate);break;default:et.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e}(W1.BaseConnection),Zk={};jo(Zk,"API",()=>t2,i=>t2=i);var $k=function(i,e,t,s){function r(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function a(u){try{c(s.next(u))}catch(d){o(d)}}function l(u){try{c(s.throw(u))}catch(d){o(d)}}function c(u){u.done?n(u.value):r(u.value).then(a,l)}c((s=s.apply(i,e||[])).next())})},e2=function(i,e){var t={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},s,r,n,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(u){return l([c,u])}}function l(c){if(s)throw new TypeError("Generator is already executing.");for(;t;)try{if(s=1,r&&(n=c[0]&2?r.return:c[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,c[1])).done)return n;switch(r=0,n&&(c=[c[0]&2,n.value]),c[0]){case 0:case 1:n=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,r=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(n=t.trys,!(n=n.length>0&&n[n.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!n||c[1]>n[0]&&c[1]<n[3])){t.label=c[1];break}if(c[0]===6&&t.label<n[1]){t.label=n[1],n=c;break}if(n&&t.label<n[2]){t.label=n[2],t.ops.push(c);break}n[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(i,t)}catch(u){c=[6,u],r=0}finally{s=n=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},t2=function(){function i(e){this._options=e}return i.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",s=this._options,r=s.host,n=s.port,o=s.path,a=s.key,l=new URL("".concat(t,"://").concat(r,":").concat(n).concat(o).concat(a,"/").concat(e));return l.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),l.searchParams.set("version",G1.version),fetch(l.href,{referrerPolicy:this._options.referrerPolicy})},i.prototype.retrieveId=function(){return $k(this,void 0,Promise,function(){var e,t,s;return e2(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=r.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=r.sent(),et.default.error("Error retrieving ID",t),s="",this._options.path==="/"&&this._options.host!==oi.CLOUD_HOST&&(s=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+s);case 3:return[2]}})})},i.prototype.listAllPeers=function(){return $k(this,void 0,Promise,function(){var e,t,s;return e2(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=r.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===oi.CLOUD_HOST?t="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":t="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+t)):new Error("Error. Status:".concat(e.status));return[2,e.json()];case 2:throw s=r.sent(),et.default.error("Error retrieving list peers",s),new Error("Could not get list peers from the server."+s);case 3:return[2]}})})},i}(),D8=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,r){s.__proto__=r}||function(s,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(s[n]=r[n])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function s(){this.constructor=e}e.prototype=t===null?Object.create(t):(s.prototype=t.prototype,new s)}}(),og=function(){return og=Object.assign||function(i){for(var e,t=1,s=arguments.length;t<s;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},og.apply(this,arguments)},ag=function(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],s=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&s>=i.length&&(i=void 0),{value:i&&i[s++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},O8=function(i,e){var t=typeof Symbol=="function"&&i[Symbol.iterator];if(!t)return i;var s=t.call(i),r,n=[],o;try{for(;(e===void 0||e-- >0)&&!(r=s.next()).done;)n.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(t=s.return)&&t.call(s)}finally{if(o)throw o.error}}return n},i2=function(i){D8(e,i);function e(t,s){var r=i.call(this)||this;r._id=null,r._lastServerId=null,r._destroyed=!1,r._disconnected=!1,r._open=!1,r._connections=new Map,r._lostMessages=new Map;var n;return t&&t.constructor==Object?s=t:t&&(n=t.toString()),s=og({debug:0,host:oi.CLOUD_HOST,port:oi.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:oi.randomToken(),config:oi.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},s),r._options=s,r._options.host==="/"&&(r._options.host=window.location.hostname),r._options.path&&(r._options.path[0]!=="/"&&(r._options.path="/"+r._options.path),r._options.path[r._options.path.length-1]!=="/"&&(r._options.path+="/")),r._options.secure===void 0&&r._options.host!==oi.CLOUD_HOST?r._options.secure=oi.isSecure():r._options.host==oi.CLOUD_HOST&&(r._options.secure=!0),r._options.logFunction&&et.default.setLogFunction(r._options.logFunction),et.default.logLevel=r._options.debug||0,r._api=new Zk.API(s),r._socket=r._createServerConnection(),!oi.supports.audioVideo&&!oi.supports.data?(r._delayedAbort(Ji.BrowserIncompatible,"The current browser does not support WebRTC"),r):n&&!oi.validateId(n)?(r._delayedAbort(Ji.InvalidID,'ID "'.concat(n,'" is invalid')),r):(n?r._initialize(n):r._api.retrieveId().then(function(o){return r._initialize(o)}).catch(function(o){return r._abort(Ji.ServerError,o)}),r)}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){var t,s,r=Object.create(null);try{for(var n=ag(this._connections),o=n.next();!o.done;o=n.next()){var a=O8(o.value,2),l=a[0],c=a[1];r[l]=c}}catch(u){t={error:u}}finally{try{o&&!o.done&&(s=n.return)&&s.call(n)}finally{if(t)throw t.error}}return r},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),e.prototype._createServerConnection=function(){var t=this,s=new Hk.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return s.on(Ka.Message,function(r){t._handleMessage(r)}),s.on(Ka.Error,function(r){t._abort(Ji.SocketError,r)}),s.on(Ka.Disconnected,function(){t.disconnected||(t.emitError(Ji.Network,"Lost connection to server."),t.disconnect())}),s.on(Ka.Close,function(){t.disconnected||t._abort(Ji.SocketClosed,"Underlying socket is already closed.")}),s},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var s,r,n=t.type,o=t.payload,a=t.src;switch(n){case js.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case js.Error:this._abort(Ji.ServerError,o.msg);break;case js.IdTaken:this._abort(Ji.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case js.InvalidKey:this._abort(Ji.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case js.Leave:et.default.log("Received leave message from ".concat(a)),this._cleanupPeer(a),this._connections.delete(a);break;case js.Expire:this.emitError(Ji.PeerUnavailable,"Could not connect to peer ".concat(a));break;case js.Offer:var g=o.connectionId,m=this.getConnection(a,g);if(m&&(m.close(),et.default.warn("Offer received for existing Connection ID:".concat(g))),o.type===go.Media){var l=new H1.MediaConnection(a,this,{connectionId:g,_payload:o,metadata:o.metadata});m=l,this._addConnection(a,m),this.emit("call",l)}else if(o.type===go.Data){var c=new q1.DataConnection(a,this,{connectionId:g,_payload:o,metadata:o.metadata,label:o.label,serialization:o.serialization,reliable:o.reliable});m=c,this._addConnection(a,m),this.emit("connection",c)}else{et.default.warn("Received malformed connection type:".concat(o.type));return}var u=this._getMessages(g);try{for(var d=ag(u),p=d.next();!p.done;p=d.next()){var f=p.value;m.handleMessage(f)}}catch(v){s={error:v}}finally{try{p&&!p.done&&(r=d.return)&&r.call(d)}finally{if(s)throw s.error}}break;default:if(!o){et.default.warn("You received a malformed message from ".concat(a," of type ").concat(n));return}var g=o.connectionId,m=this.getConnection(a,g);m&&m.peerConnection?m.handleMessage(t):g?this._storeMessage(g,t):et.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,s){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(s)},e.prototype._getMessages=function(t){var s=this._lostMessages.get(t);return s?(this._lostMessages.delete(t),s):[]},e.prototype.connect=function(t,s){if(s===void 0&&(s={}),this.disconnected){et.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),this.emitError(Ji.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var r=new q1.DataConnection(t,this,s);return this._addConnection(t,r),r},e.prototype.call=function(t,s,r){if(r===void 0&&(r={}),this.disconnected){et.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),this.emitError(Ji.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!s){et.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var n=new H1.MediaConnection(t,this,og(og({},r),{_stream:s}));return this._addConnection(t,n),n},e.prototype._addConnection=function(t,s){et.default.log("add connection ".concat(s.type,":").concat(s.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(s)},e.prototype._removeConnection=function(t){var s=this._connections.get(t.peer);if(s){var r=s.indexOf(t);r!==-1&&s.splice(r,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,s){var r,n,o=this._connections.get(t);if(!o)return null;try{for(var a=ag(o),l=a.next();!l.done;l=a.next()){var c=l.value;if(c.connectionId===s)return c}}catch(u){r={error:u}}finally{try{l&&!l.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}return null},e.prototype._delayedAbort=function(t,s){var r=this;setTimeout(function(){r._abort(t,s)},0)},e.prototype._abort=function(t,s){et.default.error("Aborting!"),this.emitError(t,s),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,s){et.default.error("Error:",s);var r;typeof s=="string"?r=new Error(s):r=s,r.type=t,this.emit("error",r)},e.prototype.destroy=function(){this.destroyed||(et.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},e.prototype._cleanup=function(){var t,s;try{for(var r=ag(this._connections.keys()),n=r.next();!n.done;n=r.next()){var o=n.value;this._cleanupPeer(o),this._connections.delete(o)}}catch(a){t={error:a}}finally{try{n&&!n.done&&(s=r.return)&&s.call(r)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var s,r,n=this._connections.get(t);if(n)try{for(var o=ag(n),a=o.next();!a.done;a=o.next()){var l=a.value;l.close()}}catch(c){s={error:c}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(s)throw s.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;et.default.log("Disconnect peer with ID:".concat(t)),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=t,this._id=null,this.emit("disconnected",t)}},e.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)et.default.log("Attempting reconnection to server with ID ".concat(this._lastServerId)),this._disconnected=!1,this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(!this.disconnected&&!this.open)et.default.error("In a hurry? We're still trying to make the initial connection!");else throw new Error("Peer ".concat(this.id," cannot reconnect because it is not disconnected from the server!"))}},e.prototype.listAllPeers=function(t){var s=this;t===void 0&&(t=function(r){}),this._api.listAllPeers().then(function(r){return t(r)}).catch(function(r){return s._abort(Ji.ServerError,r)})},e.DEFAULT_KEY="peerjs",e}(rg.EventEmitter),W0=Qk.Peer;class L8{constructor(){h(this,"_host"),h(this,"_client"),h(this,"_clientData"),this.onEnable()}get isHost(){return this._host!==void 0}onEnable(){const e="HOST-5980e65c-8438-453e-8b35-f13c736dcd81";this.trySetupHost(e)}trySetupHost(e){let t=new W0(e);t.on("error",s=>{console.error(s),this._host=void 0,this.trySetupClient(e)}),t.on("open",s=>{this._host=new U8(t)})}trySetupClient(e){this._client=new W0,this._client.on("error",t=>{console.error("Client error",t)}),this._client.on("open",t=>{console.log("client connected",t),this._clientData=this._client.connect(e,{metadata:{id:t}}),this._clientData.on("open",()=>{console.log("Connected to host")}),this._clientData.on("data",s=>{console.log("<<",s)})})}}class F8{constructor(e){h(this,"_peer"),this._peer=e}}class U8 extends F8{constructor(e){var t;super(e),h(this,"_connections",[]),console.log("I AM THE HOST"),(t=this._peer)==null||t.on("connection",this.onConnection.bind(this)),this._peer.on("close",()=>{this.broadcast("BYE")}),setInterval(()=>{this.broadcast("HELLO")},2e3)}get isHost(){return!0}onConnection(e){console.log("host connection",e),e.on("open",()=>{this._connections.push(e),this.broadcastConnection(e)})}broadcastConnection(e){const t=this._connections.map(s=>{var r;return(r=s.metadata)==null?void 0:r.id}).filter(s=>s!==void 0);this.broadcast({type:"connection-list",connections:t})}broadcast(e){if(e!=null){console.log(">>",e);for(const t in this._peer.connections){const s=this._peer.connections[t];if(s)if(Array.isArray(s))for(const r of s)r&&r.send(e);else console.warn(s)}}}}var Qr=(i=>(i[i.OnConnection=0]="OnConnection",i[i.OnRoomJoin=1]="OnRoomJoin",i[i.Queued=2]="Queued",i[i.Immediate=3]="Immediate",i))(Qr||{});const s2="https://urls.needle.tools/default-networking-backend/index";let dc="wss://needle-tiny-starter.glitch.me/socket";const xr=!!oe("debugnet"),lg=!!(xr||oe("debugowner"));var r2=(i=>(i.ConnectionInfo="connection-start-info",i))(r2||{}),Ni=(i=>(i.Join="join-room",i.Leave="leave-room",i.JoinedRoom="joined-room",i.LeftRoom="left-room",i.UserJoinedRoom="user-joined-room",i.UserLeftRoom="user-left-room",i))(Ni||{});class N8{constructor(){h(this,"room"),h(this,"viewId"),h(this,"allowEditing"),h(this,"inRoom")}}class z8{constructor(){h(this,"room")}}class Q8{constructor(){h(this,"userId")}}var n2=(i=>(i.RequestHasOwner="request-has-owner",i.ResponseHasOwner="response-has-owner",i.RequestIsOwner="request-is-owner",i.ResponseIsOwner="response-is-owner",i.RequestOwnership="request-ownership",i.GainedOwnership="gained-ownership",i.RemoveOwnership="remove-ownership",i.LostOwnership="lost-ownership",i.GainedOwnershipBroadcast="gained-ownership-broadcast",i.LostOwnershipBroadcast="lost-ownership-broadcast",i))(n2||{});class q0{constructor(e,t){h(this,"guid"),h(this,"connection"),h(this,"_hasOwnership",!1),h(this,"_isOwned"),h(this,"_gainSubscription"),h(this,"_lostSubscription"),h(this,"_hasOwnerResponse"),h(this,"_isWaitingForOwnershipResponseCallback",null),this.connection=e,this.guid=t,this._gainSubscription=this.onGainedOwnership.bind(this),this._lostSubscription=this.onLostOwnership.bind(this),e.beginListen("lost-ownership",this._lostSubscription),e.beginListen("gained-ownership-broadcast",this._gainSubscription),this._hasOwnerResponse=this.onHasOwnerResponse.bind(this),e.beginListen("response-has-owner",this._hasOwnerResponse)}get hasOwnership(){return this._hasOwnership}get isOwned(){return this._isOwned}get isConnected(){return this.connection.isConnected}updateIsOwned(){this.connection.send("request-has-owner",{guid:this.guid})}onHasOwnerResponse(e){e.guid===this.guid&&(this._isOwned=e.value)}requestOwnershipIfNotOwned(){return this._isWaitingForOwnershipResponseCallback!==null?this:(this._isWaitingForOwnershipResponseCallback=this.waitForHasOwnershipRequestResponse.bind(this),this.connection.beginListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this.connection.send("request-has-owner",{guid:this.guid}),this)}waitForHasOwnershipRequestResponse(e){e.guid===this.guid&&(this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this._isOwned=e.value,e.value||(lg&&console.log("request ownership",this.guid),this.requestOwnership()))}requestOwnershipAsync(){return new Promise((e,t)=>{this.requestOwnership();let s=0;const r=()=>{if(s++>10)return t("Timeout");setTimeout(()=>{this.hasOwnership?e(this):r()},100)};r()})}requestOwnership(){return lg&&console.log("Request ownership",this.guid),this.connection.send("request-ownership",{guid:this.guid}),this}freeOwnership(){return this.connection.send("remove-ownership",{guid:this.guid}),this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this}destroy(){this.connection.stopListen("gained-ownership",this._gainSubscription),this.connection.stopListen("lost-ownership",this._lostSubscription),this.connection.stopListen("response-has-owner",this._hasOwnerResponse),this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null)}onGainedOwnership(e){e.guid===this.guid&&(this._isOwned=!0,this.connection.connectionId===e.owner?(lg&&console.log("GAINED OWNERSHIP",this.guid),this._hasOwnership=!0):this._hasOwnership=!1)}onLostOwnership(e){e===this.guid&&(lg&&console.log("LOST OWNERSHIP",this.guid),this._hasOwnership=!1,this._isOwned=!1)}}class o2{constructor(e){h(this,"context"),h(this,"_peer",null),h(this,"_usersInRoomCopy",[]),h(this,"_defaultMessagesBuffer",[]),h(this,"_defaultMessagesBufferArray",[]),h(this,"netWebSocketUrlProvider"),h(this,"_listeners",{}),h(this,"_listenersBinary",{}),h(this,"connected",!1),h(this,"channelId"),h(this,"_connectionId",null),h(this,"_ws"),h(this,"_waitingForSocket",{}),h(this,"_isInRoom",!1),h(this,"_currentRoomName",null),h(this,"_currentRoomViewId",null),h(this,"_currentRoomAllowEditing",!0),h(this,"_currentInRoom",[]),h(this,"_state",{}),h(this,"_currentDelay",-1),h(this,"_connectingToWebsocketPromise",null),this.context=e}get peer(){return this._peer||(this._peer=new L8),this._peer}tryGetState(e){return e==="invalid"?null:this._state[e]}get connectionId(){return this._connectionId}get isDebugEnabled(){return xr}get isConnected(){return this.connected}get currentRoomName(){return this._currentRoomName}get allowEditing(){return this._currentRoomAllowEditing}get currentRoomViewId(){return this._currentRoomViewId}get isInRoom(){return this._isInRoom}get currentLatency(){return this._currentDelay}sendPing(){this.send("ping",{time:this.context.time.time})}userIsInRoom(e){return this._currentInRoom.indexOf(e)!==-1}usersInRoom(e=null){e||(e=this._usersInRoomCopy),e.length=0;for(const t of this._currentInRoom)e.push(t);return e}joinRoom(e,t=!1){this.connect(),xr&&console.log("join: "+e),this.send("join-room",{room:e,viewOnly:t},Qr.OnConnection)}leaveRoom(e=null){if(e||(e=this.currentRoomName),!e){console.error("Can not leave unknown room");return}this.send("leave-room",{room:e})}send(e,t=null,s=Qr.Queued){if(t===null&&(t={}),s===Qr.Queued){this._defaultMessagesBuffer.push({key:e,value:t});return}return this.sendWithWebsocket(e,t,s)}sendDeleteRemoteState(e){this.send("delete-state",{guid:e,dontSave:!0}),delete this._state[e]}sendDeleteRemoteStateAll(){this.send("delete-all-state"),this._state={}}sendBinary(e){var t;xr&&console.log("<< bin",e.length),(t=this._ws)==null||t.send(e)}sendBufferedMessagesNow(){var e;if(!this._ws)return;this._defaultMessagesBufferArray.length=0;const t=Object.keys(this._defaultMessagesBuffer).length;for(const r in this._defaultMessagesBuffer){const n=this._defaultMessagesBuffer[r];if(t<=1){this.sendWithWebsocket(n.key,n.value,Qr.Immediate);break}const o=this.toMessage(n.key,n.value);this._defaultMessagesBufferArray.push(o)}if(this._defaultMessagesBuffer.length=0,this._defaultMessagesBufferArray.length>0&&xr&&console.log("SEND BUFFERED",this._defaultMessagesBufferArray.length),this._defaultMessagesBufferArray.length<=0)return;const s=JSON.stringify(this._defaultMessagesBufferArray);(e=this._ws)==null||e.send(s)}beginListen(e,t){return this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t),t}stopListening(e,t){return this.stopListen(e,t)}stopListen(e,t){if(!t||!this._listeners[e])return;const s=this._listeners[e].indexOf(t);s>=0&&this._listeners[e].splice(s,1)}beginListenBinary(e,t){return this._listenersBinary[e]||(this._listenersBinary[e]=[]),this._listenersBinary[e].push(t),t}stopListenBinary(e,t){if(!this._listenersBinary[e])return;const s=this._listenersBinary[e].indexOf(t);s>=0&&this._listenersBinary[e].splice(s,1)}registerProvider(e){this.netWebSocketUrlProvider=e}async connect(){var e;if(this.connected)return Promise.resolve(!0);xr&&console.log("connecting");const t=(e=this.netWebSocketUrlProvider)==null?void 0:e.getWebsocketUrl();return t?dc=t:JI()&&(dc="wss://"+window.location.host+"/socket"),this.connectWebsocket()}disconnect(){var e;(e=this._ws)==null||e.close(),this._ws=void 0}connectWebsocket(){return this._connectingToWebsocketPromise?this._connectingToWebsocketPromise:this._connectingToWebsocketPromise=new Promise(async(e,t)=>{let s=!1;const r=o=>{s||(s=!0,e(o))};if(dc===void 0&&(console.log("Fetch default backend url: "+s2),dc=await(await fetch(s2)).text()),dc===void 0){r(!1);return}console.log(`\u22A1 Connecting to networking backend on
|
|
3334
3334
|
`+dc);const n=new UB.WebsocketBuilder(dc).onOpen(()=>{this._connectingToWebsocketPromise=null,this._ws=n,this.connected=!0,console.log(`\u229E Connected to networking backend
|
|
3335
3335
|
`+dc),r(!0),this.onSendQueued(Qr.OnConnection)}).onClose(o=>{this._connectingToWebsocketPromise=null,this.connected=!1,this._isInRoom=!1,r(!1)}).onError((o,a)=>{console.error("\u22A0 Websocket error",o,a),r(!1)}).onMessage(this.onMessage.bind(this)).onRetry(()=>{console.log("Retry connecting to networking websocket")}).build()})}onMessage(e,t){const s=t.data;try{if(typeof s!="string"){s.size&&this.handleIncomingBinaryMessage(s);return}const r=JSON.parse(s);if(Array.isArray(r))for(const n of r)this.handleIncomingStringMessage(n);else this.handleIncomingStringMessage(r);return}catch{xr&&s==="pong"&&console.log("<<",s)}}async handleIncomingBinaryMessage(e){const t=await e.arrayBuffer();var s=new Uint8Array(t);const r=new kv(s),n=r.getBufferIdentifier(),o=this._listenersBinary[n],a=e8(r),l=t8(a);if(l&&typeof l=="string"&&(this._state[l]=a),!o)return;const c=a??r;for(const u of o)u(c)}handleIncomingStringMessage(e){var t,s;if(xr&&console.log("<<",e.key??e),e.key)switch(e.key){case"connection-start-info":if(e.data){const a=e.data;a&&(console.assert(a.id!==void 0&&a.id!==null&&a.id.length>0,"server did not send connection id",a.id),console.log("Your id is: "+a.id,this.context.alias??""),this._connectionId=a.id)}else console.warn("Expected connection id in "+e.key);break;case"joined-room":if(xr&&console.log(e),e){this._isInRoom=!0;const a=e;this._currentRoomName=a.room,this._currentRoomViewId=a.viewId,this._currentRoomAllowEditing=a.allowEditing??!0,console.log("Room view id",this._currentRoomViewId),this._currentInRoom.length=0,this._currentInRoom.push(...a.inRoom),xr&&console.log("joined room with",this._currentInRoom,this.context.alias??"")}this.onSendQueued(Qr.OnRoomJoin);break;case"left-room":e.room===this.currentRoomName&&(this._isInRoom=!1,this._currentRoomName=null,this._currentInRoom.length=0);break;case"user-joined-room":if(e.data){const a=e.data;this._currentInRoom.push(a.userId),xr&&console.log(a.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(e.data){const a=e.data,l=this._currentInRoom.indexOf(a.userId);l>=0&&(console.log(a.userId+" left",this.context.alias??""),this._currentInRoom.splice(l,1)),a.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":xr&&console.log("RECEIVED all-room-state-deleted"),this._state={};break;case"ping":case"pong":const o=(t=e.data)==null?void 0:t.time;o&&(this._currentDelay=this.context.time.time-o),xr&&console.log("Current latency: "+this._currentDelay.toFixed(1)+" sec","Clients in room: "+((s=this._currentInRoom)==null?void 0:s.length));break}const r=this._listeners[e.key];if(r)for(const o of r)o(e.data);const n=e.data;n&&(this._state[n.guid]=n)}toMessage(e,t){return{key:e,data:t}}sendWithWebsocket(e,t,s=Qr.OnRoomJoin){if(!this._ws){const n=this._waitingForSocket[s]||[];n.push(()=>this.sendWithWebsocket(e,t,s)),this._waitingForSocket[s]=n;return}const r=JSON.stringify(this.toMessage(e,t));xr&&console.log(">>",e),this._ws.send(r)}onSendQueued(e){const t=this._waitingForSocket[e];if(t){for(const s of t)s();t.length=0}}}function wd(i,e){try{e?i(e):i()}catch(t){return console.error(t),!1}return!0}(0,eval)(`
|
|
3336
|
-
if(!globalThis[""
|
|
3337
|
-
globalThis[""
|
|
3336
|
+
if(!globalThis["NEEDLE_ENGINE_VERSION"])
|
|
3337
|
+
globalThis["NEEDLE_ENGINE_VERSION"] = "0.0.0";
|
|
3338
3338
|
if(!globalThis[""undefined""])
|
|
3339
3339
|
globalThis[""undefined""] = "unknown";
|
|
3340
|
-
`);const a2="null",j8="undefined",Za="needle_isActiveInHierarchy",jh="builtin_components",cg="needle_editor_guid",G8=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function H8(i){return typeof i=="string"&&G8.test(i)}const Gs=[];for(let i=0;i<256;++i)Gs.push((i+256).toString(16).slice(1));function V8(i,e=0){return(Gs[i[e+0]]+Gs[i[e+1]]+Gs[i[e+2]]+Gs[i[e+3]]+"-"+Gs[i[e+4]]+Gs[i[e+5]]+"-"+Gs[i[e+6]]+Gs[i[e+7]]+"-"+Gs[i[e+8]]+Gs[i[e+9]]+"-"+Gs[i[e+10]]+Gs[i[e+11]]+Gs[i[e+12]]+Gs[i[e+13]]+Gs[i[e+14]]+Gs[i[e+15]]).toLowerCase()}function W8(i){if(!H8(i))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(i.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(i.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(i.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(i.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(i.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function q8(i){i=unescape(encodeURIComponent(i));const e=[];for(let t=0;t<i.length;++t)e.push(i.charCodeAt(t));return e}const X8="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Y8="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function J8(i,e,t){function s(r,n,o,a){var l;if(typeof r=="string"&&(r=q8(r)),typeof n=="string"&&(n=W8(n)),((l=n)===null||l===void 0?void 0:l.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+r.length);if(c.set(n),c.set(r,n.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,o){a=a||0;for(let u=0;u<16;++u)o[a+u]=c[u];return o}return V8(c)}try{s.name=i}catch{}return s.DNS=X8,s.URL=Y8,s}function K8(i,e,t,s){switch(i){case 0:return e&t^~e&s;case 1:return e^t^s;case 2:return e&t^e&s^t&s;case 3:return e^t^s}}function X1(i,e){return i<<e|i>>>32-e}function Z8(i){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof i=="string"){const o=unescape(encodeURIComponent(i));i=[];for(let a=0;a<o.length;++a)i.push(o.charCodeAt(a))}else Array.isArray(i)||(i=Array.prototype.slice.call(i));i.push(128);const s=i.length/4+2,r=Math.ceil(s/16),n=new Array(r);for(let o=0;o<r;++o){const a=new Uint32Array(16);for(let l=0;l<16;++l)a[l]=i[o*64+l*4]<<24|i[o*64+l*4+1]<<16|i[o*64+l*4+2]<<8|i[o*64+l*4+3];n[o]=a}n[r-1][14]=(i.length-1)*8/Math.pow(2,32),n[r-1][14]=Math.floor(n[r-1][14]),n[r-1][15]=(i.length-1)*8&4294967295;for(let o=0;o<r;++o){const a=new Uint32Array(80);for(let f=0;f<16;++f)a[f]=n[o][f];for(let f=16;f<80;++f)a[f]=X1(a[f-3]^a[f-8]^a[f-14]^a[f-16],1);let l=t[0],c=t[1],u=t[2],d=t[3],p=t[4];for(let f=0;f<80;++f){const g=Math.floor(f/20),m=X1(l,5)+K8(g,c,u,d)+p+e[g]+a[f]>>>0;p=d,d=u,u=X1(c,30)>>>0,c=l,l=m}t[0]=t[0]+l>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+d>>>0,t[4]=t[4]+p>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const $8=J8("v5",80,Z8),l2=$8;Gi.registerCallback(Cn.ContextCreated,i=>{const e=i.context;f2(e),p2(e)});const X0=oe("debugcomponents"),c2="eff8ba80-635d-11ec-90d6-0242ac120003";class Ur{constructor(e){h(this,"_originalSeed"),h(this,"_seed"),typeof e=="string"&&(e=Ur.hash(e)),this._originalSeed=e,this._seed=e}get seed(){return this._seed}set seed(e){this._seed=e}reset(){this._seed=this._originalSeed}generateUUID(e){if(typeof e=="string")return l2(e,c2);const t=this._seed;return this._seed-=1,l2(t.toString(),c2)}initialize(e){typeof e=="string"?this._seed=Ur.hash(e):this._seed=e}static createFromString(e){return new Ur(this.hash(e))}static hash(e){let t=0;for(let s=0;s<e.length;s++)t=e.charCodeAt(s)+((t<<5)-t);return t}}var h2=(i=>(i.NewInstanceCreated="new-instance-created",i.InstanceDestroyed="instance-destroyed",i))(h2||{});class u2{constructor(e){h(this,"guid"),this.guid=e}}function Y0(i,e,t=!0){if(!i)return;const s=i;if($a(i,t),!e){console.warn("Can not send destroy: No networking connection provided",i.guid);return}if(!e.isConnected){console.warn("Can not send destroy: not connected",i.guid);return}let r=i.guid;if(!r&&s.uuid&&(r=s.uuid),!r){console.warn("Can not send destroy: failed to find guid",i);return}const n=new u2(r);e.send("instance-destroyed",n,Qr.Queued)}function d2(i,e){const t=new u2(i);e.send("instance-destroyed",t,Qr.Queued)}function p2(i){i.connection.beginListen("instance-destroyed",e=>{X0&&console.log("[Remote] Destroyed",i.scene,e);const t=yg(e.guid,i.scene);t&&$a(t)})}class e9{constructor(e,t,s){h(this,"filename"),h(this,"hash"),h(this,"size"),this.filename=e,this.hash=t,this.size=s}}class t9{constructor(e,t){h(this,"guid"),h(this,"originalGuid"),h(this,"seed"),h(this,"visible"),h(this,"hostData"),h(this,"dontSave"),h(this,"parent"),h(this,"position"),h(this,"rotation"),h(this,"scale"),this.originalGuid=e,this.guid=t}}function Y1(i,e,t,s){var r;const n=i;if(!n.guid)return console.warn("Can not instantiate: No guid",n),null;if(e.context||(e.context=_t.Current),!e.context)return console.error("Missing network instantiate options / reference to network connection in sync instantiate"),null;const o=e?{...e}:null,{instance:a,seed:l}=i9(n,e);if(a){const c=a;if(c.guid){X0&&console.log("[Local] new instance","gameobject:",a?.guid);const u=new t9(n.guid,c.guid);u.seed=l,o&&(o.position&&(u.position={x:o.position.x,y:o.position.y,z:o.position.z}),o.rotation&&(u.rotation={x:o.rotation.x,y:o.rotation.y,z:o.rotation.z,w:o.rotation.w}),o.scale&&(u.scale={x:o.scale.x,y:o.scale.y,z:o.scale.z})),u.position||(u.position={x:c.position.x,y:c.position.y,z:c.position.z}),u.rotation||(u.rotation={x:c.quaternion.x,y:c.quaternion.y,z:c.quaternion.z,w:c.quaternion.w}),u.scale||(u.scale={x:c.scale.x,y:c.scale.y,z:c.scale.z}),u.visible=n.visible,o!=null&&o.parent&&(typeof o.parent=="string"?u.parent=o.parent:u.parent=o.parent.guid),u.hostData=t,s===!1&&(u.dontSave=!0),(r=e?.context)==null||r.connection.send("new-instance-created",u)}else console.warn("Missing guid, can not send new instance event",c)}return a}function J0(){return Math.random()*9999999}function f2(i){i.connection.beginListen("new-instance-created",async e=>{const t=await s9(e.originalGuid,i.scene);if(!t){console.warn("could not find object that was instantiated: "+e.guid);return}const s=new Go;e.position&&(s.position=new S(e.position.x,e.position.y,e.position.z)),e.rotation&&(s.rotation=new xe(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w)),e.scale&&(s.scale=new S(e.scale.x,e.scale.y,e.scale.z)),s.parent=e.parent,e.seed&&(s.idProvider=new Ur(e.seed)),s.visible=e.visible,s.context=i,X0&&i.alias&&console.log("[Remote] instantiate in: "+i.alias);const r=bg(t,s);r&&(e.parent==="scene"&&i.scene.add(r),X0&&console.log("[Remote] new instance","gameobject:",r?.guid,t))})}function i9(i,e){const t=J0(),s=e??new Go;s.idProvider=new Ur(t);const r=bg(i,s);return{seed:t,instance:r}}const g2={};function m2(i,e){g2[i]=e}async function s9(i,e){const t=g2[i];if(t!=null){const s=await t(i);if(s)return s}return v2(i,e)}function v2(i,e){if(e===null||!i)return null;if(e.guid===i)return e;if(e.children)for(const t of e.children){const s=v2(i,t);if(s)return s}return null}const A2=new Map;function r9(i,e){if(!i)return;if(!e){console.warn("No prototype found",i,i.prototype,i.constructor);return}let t=A2.get(e);t&&t.apply(i)}function n9(i){const e=o9(i.prototype);A2.set(i,e)}function o9(i){return new a9(i)}class a9{constructor(e){h(this,"$symbol"),h(this,"extensions"),h(this,"descriptors"),this.$symbol=Symbol("prototype-extension"),this.extensions=Object.keys(e),this.descriptors=new Array;for(let t=0;t<this.extensions.length;t++){const s=this.extensions[t],r=Object.getOwnPropertyDescriptor(e,s);r&&this.descriptors.push(r)}}apply(e){if(!e[this.$symbol]){e[this.$symbol]=!0;for(let t=0;t<this.extensions.length;t++){const s=this.extensions[t],r=this.descriptors[t];r&&Object.defineProperty(e,s,r)}}}}var hg=(i=>(i.Added="component-added",i.Removing="removing-component",i))(hg||{});const y2=oe("debugcomponentevents");class ug{static addComponentLifecylceEventListener(e,t){this.eventListeners.has(e)&&this.eventListeners.set(e,[]);let s=this.eventListeners.get(e);s||(s=[]),s.push(t),this.eventListeners.set(e,s),y2&&console.log("Added event listener for "+e,this.eventListeners)}static removeComponentLifecylceEventListener(e,t){const s=this.eventListeners.get(e);if(!s)return;const r=s.indexOf(t);r<0||s.splice(r,1)}static dispatchComponentLifecycleEvent(e,t){const s=this.eventListeners.get(e);if(y2&&console.log("Dispatching event "+e,s),!!s)for(const r of s)r(t)}}h(ug,"eventListeners",new Map);const J1=oe("debuggetcomponent");function l9(i){return i==null||i.isObject3D?i:i.object&&i.object.isObject3D?i.object:i}function K1(i,e){if(!i||!i.userData.components)return;const t=i.userData.components.indexOf(e);t<0||(ug.dispatchComponentLifecycleEvent(hg.Removing,e),e.gameObject=null,i.userData.components.splice(t,1))}function K0(i,e){const t=xd(i,e);if(t)return t;const s=new e;return Gh(i,s)}const b2=new Ur("addComponentIdProvider");function Gh(i,e,t=!0){i.userData||(i.userData={}),i.userData.components||(i.userData.components=[]),i.userData.components.push(e),e.gameObject=i,(e.guid===void 0||e.guid==="invalid")&&(e.guid=b2.generateUUID()),$0(i),yy(e);try{t&&e.__internalAwake&&(_g(i),e.__internalAwake()),ug.dispatchComponentLifecycleEvent(hg.Added,e)}catch(s){console.error(s)}return e}function Z1(i,e){if(e.gameObject===i)return e;if(e.gameObject&&e.gameObject.userData.components){const t=e.gameObject.userData.components.indexOf(e);e.gameObject.userData.components.splice(t,1)}if(!i.userData.components)i.userData.components=[];else if(i.userData.components.includes(e))return e;return i.userData.components.push(e),e.gameObject=i,(e.guid===void 0||e.guid==="invalid")&&(e.guid=b2.generateUUID()),yy(e),e}function _2(i){if(i.gameObject&&i.gameObject.userData.components){const e=i.gameObject.userData.components.indexOf(i);i.gameObject.userData.components.splice(e,1)}i.__internalDisable&&i.__internalDisable(),i.onDestroy&&i.onDestroy(),el(i,i.context??_t.Current),i.__internalDestroy(),i.gameObject=null}let w2=!1;function x2(i,e,t){var s;if(i!=null){if(!i.isObject3D){console.error("Object is not object3D");return}if(!((s=i?.userData)!=null&&s.components))return null;if(typeof e=="string"&&(w2||(w2=!0,console.warn(`Accessing components by name is not supported.
|
|
3340
|
+
`);const a2=NEEDLE_ENGINE_VERSION,j8="undefined",Za="needle_isActiveInHierarchy",jh="builtin_components",cg="needle_editor_guid",G8=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function H8(i){return typeof i=="string"&&G8.test(i)}const Gs=[];for(let i=0;i<256;++i)Gs.push((i+256).toString(16).slice(1));function V8(i,e=0){return(Gs[i[e+0]]+Gs[i[e+1]]+Gs[i[e+2]]+Gs[i[e+3]]+"-"+Gs[i[e+4]]+Gs[i[e+5]]+"-"+Gs[i[e+6]]+Gs[i[e+7]]+"-"+Gs[i[e+8]]+Gs[i[e+9]]+"-"+Gs[i[e+10]]+Gs[i[e+11]]+Gs[i[e+12]]+Gs[i[e+13]]+Gs[i[e+14]]+Gs[i[e+15]]).toLowerCase()}function W8(i){if(!H8(i))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(i.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(i.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(i.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(i.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(i.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function q8(i){i=unescape(encodeURIComponent(i));const e=[];for(let t=0;t<i.length;++t)e.push(i.charCodeAt(t));return e}const X8="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Y8="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function J8(i,e,t){function s(r,n,o,a){var l;if(typeof r=="string"&&(r=q8(r)),typeof n=="string"&&(n=W8(n)),((l=n)===null||l===void 0?void 0:l.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+r.length);if(c.set(n),c.set(r,n.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,o){a=a||0;for(let u=0;u<16;++u)o[a+u]=c[u];return o}return V8(c)}try{s.name=i}catch{}return s.DNS=X8,s.URL=Y8,s}function K8(i,e,t,s){switch(i){case 0:return e&t^~e&s;case 1:return e^t^s;case 2:return e&t^e&s^t&s;case 3:return e^t^s}}function X1(i,e){return i<<e|i>>>32-e}function Z8(i){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof i=="string"){const o=unescape(encodeURIComponent(i));i=[];for(let a=0;a<o.length;++a)i.push(o.charCodeAt(a))}else Array.isArray(i)||(i=Array.prototype.slice.call(i));i.push(128);const s=i.length/4+2,r=Math.ceil(s/16),n=new Array(r);for(let o=0;o<r;++o){const a=new Uint32Array(16);for(let l=0;l<16;++l)a[l]=i[o*64+l*4]<<24|i[o*64+l*4+1]<<16|i[o*64+l*4+2]<<8|i[o*64+l*4+3];n[o]=a}n[r-1][14]=(i.length-1)*8/Math.pow(2,32),n[r-1][14]=Math.floor(n[r-1][14]),n[r-1][15]=(i.length-1)*8&4294967295;for(let o=0;o<r;++o){const a=new Uint32Array(80);for(let f=0;f<16;++f)a[f]=n[o][f];for(let f=16;f<80;++f)a[f]=X1(a[f-3]^a[f-8]^a[f-14]^a[f-16],1);let l=t[0],c=t[1],u=t[2],d=t[3],p=t[4];for(let f=0;f<80;++f){const g=Math.floor(f/20),m=X1(l,5)+K8(g,c,u,d)+p+e[g]+a[f]>>>0;p=d,d=u,u=X1(c,30)>>>0,c=l,l=m}t[0]=t[0]+l>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+d>>>0,t[4]=t[4]+p>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const $8=J8("v5",80,Z8),l2=$8;Gi.registerCallback(Cn.ContextCreated,i=>{const e=i.context;f2(e),p2(e)});const X0=oe("debugcomponents"),c2="eff8ba80-635d-11ec-90d6-0242ac120003";class Ur{constructor(e){h(this,"_originalSeed"),h(this,"_seed"),typeof e=="string"&&(e=Ur.hash(e)),this._originalSeed=e,this._seed=e}get seed(){return this._seed}set seed(e){this._seed=e}reset(){this._seed=this._originalSeed}generateUUID(e){if(typeof e=="string")return l2(e,c2);const t=this._seed;return this._seed-=1,l2(t.toString(),c2)}initialize(e){typeof e=="string"?this._seed=Ur.hash(e):this._seed=e}static createFromString(e){return new Ur(this.hash(e))}static hash(e){let t=0;for(let s=0;s<e.length;s++)t=e.charCodeAt(s)+((t<<5)-t);return t}}var h2=(i=>(i.NewInstanceCreated="new-instance-created",i.InstanceDestroyed="instance-destroyed",i))(h2||{});class u2{constructor(e){h(this,"guid"),this.guid=e}}function Y0(i,e,t=!0){if(!i)return;const s=i;if($a(i,t),!e){console.warn("Can not send destroy: No networking connection provided",i.guid);return}if(!e.isConnected){console.warn("Can not send destroy: not connected",i.guid);return}let r=i.guid;if(!r&&s.uuid&&(r=s.uuid),!r){console.warn("Can not send destroy: failed to find guid",i);return}const n=new u2(r);e.send("instance-destroyed",n,Qr.Queued)}function d2(i,e){const t=new u2(i);e.send("instance-destroyed",t,Qr.Queued)}function p2(i){i.connection.beginListen("instance-destroyed",e=>{X0&&console.log("[Remote] Destroyed",i.scene,e);const t=yg(e.guid,i.scene);t&&$a(t)})}class e9{constructor(e,t,s){h(this,"filename"),h(this,"hash"),h(this,"size"),this.filename=e,this.hash=t,this.size=s}}class t9{constructor(e,t){h(this,"guid"),h(this,"originalGuid"),h(this,"seed"),h(this,"visible"),h(this,"hostData"),h(this,"dontSave"),h(this,"parent"),h(this,"position"),h(this,"rotation"),h(this,"scale"),this.originalGuid=e,this.guid=t}}function Y1(i,e,t,s){var r;const n=i;if(!n.guid)return console.warn("Can not instantiate: No guid",n),null;if(e.context||(e.context=_t.Current),!e.context)return console.error("Missing network instantiate options / reference to network connection in sync instantiate"),null;const o=e?{...e}:null,{instance:a,seed:l}=i9(n,e);if(a){const c=a;if(c.guid){X0&&console.log("[Local] new instance","gameobject:",a?.guid);const u=new t9(n.guid,c.guid);u.seed=l,o&&(o.position&&(u.position={x:o.position.x,y:o.position.y,z:o.position.z}),o.rotation&&(u.rotation={x:o.rotation.x,y:o.rotation.y,z:o.rotation.z,w:o.rotation.w}),o.scale&&(u.scale={x:o.scale.x,y:o.scale.y,z:o.scale.z})),u.position||(u.position={x:c.position.x,y:c.position.y,z:c.position.z}),u.rotation||(u.rotation={x:c.quaternion.x,y:c.quaternion.y,z:c.quaternion.z,w:c.quaternion.w}),u.scale||(u.scale={x:c.scale.x,y:c.scale.y,z:c.scale.z}),u.visible=n.visible,o!=null&&o.parent&&(typeof o.parent=="string"?u.parent=o.parent:u.parent=o.parent.guid),u.hostData=t,s===!1&&(u.dontSave=!0),(r=e?.context)==null||r.connection.send("new-instance-created",u)}else console.warn("Missing guid, can not send new instance event",c)}return a}function J0(){return Math.random()*9999999}function f2(i){i.connection.beginListen("new-instance-created",async e=>{const t=await s9(e.originalGuid,i.scene);if(!t){console.warn("could not find object that was instantiated: "+e.guid);return}const s=new Go;e.position&&(s.position=new S(e.position.x,e.position.y,e.position.z)),e.rotation&&(s.rotation=new xe(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w)),e.scale&&(s.scale=new S(e.scale.x,e.scale.y,e.scale.z)),s.parent=e.parent,e.seed&&(s.idProvider=new Ur(e.seed)),s.visible=e.visible,s.context=i,X0&&i.alias&&console.log("[Remote] instantiate in: "+i.alias);const r=bg(t,s);r&&(e.parent==="scene"&&i.scene.add(r),X0&&console.log("[Remote] new instance","gameobject:",r?.guid,t))})}function i9(i,e){const t=J0(),s=e??new Go;s.idProvider=new Ur(t);const r=bg(i,s);return{seed:t,instance:r}}const g2={};function m2(i,e){g2[i]=e}async function s9(i,e){const t=g2[i];if(t!=null){const s=await t(i);if(s)return s}return v2(i,e)}function v2(i,e){if(e===null||!i)return null;if(e.guid===i)return e;if(e.children)for(const t of e.children){const s=v2(i,t);if(s)return s}return null}const A2=new Map;function r9(i,e){if(!i)return;if(!e){console.warn("No prototype found",i,i.prototype,i.constructor);return}let t=A2.get(e);t&&t.apply(i)}function n9(i){const e=o9(i.prototype);A2.set(i,e)}function o9(i){return new a9(i)}class a9{constructor(e){h(this,"$symbol"),h(this,"extensions"),h(this,"descriptors"),this.$symbol=Symbol("prototype-extension"),this.extensions=Object.keys(e),this.descriptors=new Array;for(let t=0;t<this.extensions.length;t++){const s=this.extensions[t],r=Object.getOwnPropertyDescriptor(e,s);r&&this.descriptors.push(r)}}apply(e){if(!e[this.$symbol]){e[this.$symbol]=!0;for(let t=0;t<this.extensions.length;t++){const s=this.extensions[t],r=this.descriptors[t];r&&Object.defineProperty(e,s,r)}}}}var hg=(i=>(i.Added="component-added",i.Removing="removing-component",i))(hg||{});const y2=oe("debugcomponentevents");class ug{static addComponentLifecylceEventListener(e,t){this.eventListeners.has(e)&&this.eventListeners.set(e,[]);let s=this.eventListeners.get(e);s||(s=[]),s.push(t),this.eventListeners.set(e,s),y2&&console.log("Added event listener for "+e,this.eventListeners)}static removeComponentLifecylceEventListener(e,t){const s=this.eventListeners.get(e);if(!s)return;const r=s.indexOf(t);r<0||s.splice(r,1)}static dispatchComponentLifecycleEvent(e,t){const s=this.eventListeners.get(e);if(y2&&console.log("Dispatching event "+e,s),!!s)for(const r of s)r(t)}}h(ug,"eventListeners",new Map);const J1=oe("debuggetcomponent");function l9(i){return i==null||i.isObject3D?i:i.object&&i.object.isObject3D?i.object:i}function K1(i,e){if(!i||!i.userData.components)return;const t=i.userData.components.indexOf(e);t<0||(ug.dispatchComponentLifecycleEvent(hg.Removing,e),e.gameObject=null,i.userData.components.splice(t,1))}function K0(i,e){const t=xd(i,e);if(t)return t;const s=new e;return Gh(i,s)}const b2=new Ur("addComponentIdProvider");function Gh(i,e,t=!0){i.userData||(i.userData={}),i.userData.components||(i.userData.components=[]),i.userData.components.push(e),e.gameObject=i,(e.guid===void 0||e.guid==="invalid")&&(e.guid=b2.generateUUID()),$0(i),yy(e);try{t&&e.__internalAwake&&(_g(i),e.__internalAwake()),ug.dispatchComponentLifecycleEvent(hg.Added,e)}catch(s){console.error(s)}return e}function Z1(i,e){if(e.gameObject===i)return e;if(e.gameObject&&e.gameObject.userData.components){const t=e.gameObject.userData.components.indexOf(e);e.gameObject.userData.components.splice(t,1)}if(!i.userData.components)i.userData.components=[];else if(i.userData.components.includes(e))return e;return i.userData.components.push(e),e.gameObject=i,(e.guid===void 0||e.guid==="invalid")&&(e.guid=b2.generateUUID()),yy(e),e}function _2(i){if(i.gameObject&&i.gameObject.userData.components){const e=i.gameObject.userData.components.indexOf(i);i.gameObject.userData.components.splice(e,1)}i.__internalDisable&&i.__internalDisable(),i.onDestroy&&i.onDestroy(),el(i,i.context??_t.Current),i.__internalDestroy(),i.gameObject=null}let w2=!1;function x2(i,e,t){var s;if(i!=null){if(!i.isObject3D){console.error("Object is not object3D");return}if(!((s=i?.userData)!=null&&s.components))return null;if(typeof e=="string"&&(w2||(w2=!0,console.warn(`Accessing components by name is not supported.
|
|
3341
3341
|
Please use the component type instead. This may keep working in local development but it will fail when bundling your application.
|
|
3342
3342
|
|
|
3343
3343
|
You can import other modules your main module to get access to types
|
|
@@ -3333,11 +3333,11 @@ a=extmap-allow-mixed`)!==-1){const r=s.sdp.split(`
|
|
|
3333
3333
|
isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},n}()),YP={iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:["turn:eu-0.turn.peerjs.com:3478","turn:us-0.turn.peerjs.com:3478"],username:"peerjs",credential:"peerjsp"}],sdpSemantics:"unified-plan"},Cj=function(){function n(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=YP,this.browser=Qp.getBrowser(),this.browserVersion=Qp.getVersion(),this.supports=function(){var e={browser:Qp.isBrowserSupported(),webRTC:Qp.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(YP),e.audioVideo=!0;var i=void 0;try{i=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!i.ordered;try{i.binaryType="blob",e.binaryBlob=!Qp.isIOS}catch{}}catch{}finally{i&&i.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=UP.pack,this.unpack=UP.unpack,this._dataCount=1}return n.prototype.noop=function(){},n.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},n.prototype.chunk=function(e){for(var t=[],i=e.size,s=Math.ceil(i/li.chunkedMTU),r=0,o=0;o<i;){var a=Math.min(i,o+li.chunkedMTU),l=e.slice(o,a),c={__peerData:this._dataCount,n:r,data:l,total:s};t.push(c),o=a,r++}return this._dataCount++,t},n.prototype.blobToArrayBuffer=function(e,t){var i=new FileReader;return i.onload=function(s){s.target&&t(s.target.result)},i.readAsArrayBuffer(e),i},n.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),i=0;i<e.length;i++)t[i]=e.charCodeAt(i)&255;return t.buffer},n.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},n.prototype.isSecure=function(){return location.protocol==="https:"},n}(),li=new Cj,aL={};La(aL,"Peer",()=>oR,n=>oR=n);var uA={},Sj=Object.prototype.hasOwnProperty,Hs="~";function mm(){}Object.create&&(mm.prototype=Object.create(null),new mm().__proto__||(Hs=!1));function Ej(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function lL(n,e,t,i,s){if(typeof t!="function")throw new TypeError("The listener must be a function");var r=new Ej(t,i||n,s),o=Hs?Hs+e:e;return n._events[o]?n._events[o].fn?n._events[o]=[n._events[o],r]:n._events[o].push(r):(n._events[o]=r,n._eventsCount++),n}function Yy(n,e){--n._eventsCount===0?n._events=new mm:delete n._events[e]}function bs(){this._events=new mm,this._eventsCount=0}bs.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)Sj.call(t,i)&&e.push(Hs?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};bs.prototype.listeners=function(e){var t=Hs?Hs+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var s=0,r=i.length,o=new Array(r);s<r;s++)o[s]=i[s].fn;return o};bs.prototype.listenerCount=function(e){var t=Hs?Hs+e:e,i=this._events[t];return i?i.fn?1:i.length:0};bs.prototype.emit=function(e,t,i,s,r,o){var a=Hs?Hs+e:e;if(!this._events[a])return!1;var l=this._events[a],c=arguments.length,h,d;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,i),!0;case 4:return l.fn.call(l.context,t,i,s),!0;case 5:return l.fn.call(l.context,t,i,s,r),!0;case 6:return l.fn.call(l.context,t,i,s,r,o),!0}for(d=1,h=new Array(c-1);d<c;d++)h[d-1]=arguments[d];l.fn.apply(l.context,h)}else{var f=l.length,p;for(d=0;d<f;d++)switch(l[d].once&&this.removeListener(e,l[d].fn,void 0,!0),c){case 1:l[d].fn.call(l[d].context);break;case 2:l[d].fn.call(l[d].context,t);break;case 3:l[d].fn.call(l[d].context,t,i);break;case 4:l[d].fn.call(l[d].context,t,i,s);break;default:if(!h)for(p=1,h=new Array(c-1);p<c;p++)h[p-1]=arguments[p];l[d].fn.apply(l[d].context,h)}}return!0};bs.prototype.on=function(e,t,i){return lL(this,e,t,i,!1)};bs.prototype.once=function(e,t,i){return lL(this,e,t,i,!0)};bs.prototype.removeListener=function(e,t,i,s){var r=Hs?Hs+e:e;if(!this._events[r])return this;if(!t)return Yy(this,r),this;var o=this._events[r];if(o.fn)o.fn===t&&(!s||o.once)&&(!i||o.context===i)&&Yy(this,r);else{for(var a=0,l=[],c=o.length;a<c;a++)(o[a].fn!==t||s&&!o[a].once||i&&o[a].context!==i)&&l.push(o[a]);l.length?this._events[r]=l.length===1?l[0]:l:Yy(this,r)}return this};bs.prototype.removeAllListeners=function(e){var t;return e?(t=Hs?Hs+e:e,this._events[t]&&Yy(this,t)):(this._events=new mm,this._eventsCount=0),this};bs.prototype.off=bs.prototype.removeListener;bs.prototype.addListener=bs.prototype.on;bs.prefixed=Hs;bs.EventEmitter=bs;uA=bs;var it={};La(it,"LogLevel",()=>$s,n=>$s=n);La(it,"default",()=>JP,n=>JP=n);var Th=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var i=t.call(n),s,r=[],o;try{for(;(e===void 0||e-- >0)&&!(s=i.next()).done;)r.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return r},Ph=function(n,e,t){if(t||arguments.length===2)for(var i=0,s=e.length,r;i<s;i++)(r||!(i in e))&&(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return n.concat(r||Array.prototype.slice.call(e))},Ij="PeerJS: ",$s;(function(n){n[n.Disabled=0]="Disabled",n[n.Errors=1]="Errors",n[n.Warnings=2]="Warnings",n[n.All=3]="All"})($s||($s={}));var Mj=function(){function n(){this._logLevel=$s.Disabled}return Object.defineProperty(n.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),n.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=$s.All&&this._print.apply(this,Ph([$s.All],Th(e),!1))},n.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=$s.Warnings&&this._print.apply(this,Ph([$s.Warnings],Th(e),!1))},n.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=$s.Errors&&this._print.apply(this,Ph([$s.Errors],Th(e),!1))},n.prototype.setLogFunction=function(e){this._print=e},n.prototype._print=function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];var s=Ph([Ij],Th(t),!1);for(var r in s)s[r]instanceof Error&&(s[r]="("+s[r].name+") "+s[r].message);e>=$s.All?console.log.apply(console,Ph([],Th(s),!1)):e>=$s.Warnings?console.warn.apply(console,Ph(["WARNING"],Th(s),!1)):e>=$s.Errors&&console.error.apply(console,Ph(["ERROR"],Th(s),!1))},n}(),JP=new Mj,cL={};La(cL,"Socket",()=>KP,n=>KP=n);var ko;(function(n){n.Data="data",n.Media="media"})(ko||(ko={}));var nn;(function(n){n.BrowserIncompatible="browser-incompatible",n.Disconnected="disconnected",n.InvalidID="invalid-id",n.InvalidKey="invalid-key",n.Network="network",n.PeerUnavailable="peer-unavailable",n.SslUnavailable="ssl-unavailable",n.ServerError="server-error",n.SocketError="socket-error",n.SocketClosed="socket-closed",n.UnavailableID="unavailable-id",n.WebRTC="webrtc"})(nn||(nn={}));var ol;(function(n){n.Binary="binary",n.BinaryUTF8="binary-utf8",n.JSON="json"})(ol||(ol={}));var Cl;(function(n){n.Message="message",n.Disconnected="disconnected",n.Error="error",n.Close="close"})(Cl||(Cl={}));var ts;(function(n){n.Heartbeat="HEARTBEAT",n.Candidate="CANDIDATE",n.Offer="OFFER",n.Answer="ANSWER",n.Open="OPEN",n.Error="ERROR",n.IdTaken="ID-TAKEN",n.InvalidKey="INVALID-KEY",n.Leave="LEAVE",n.Expire="EXPIRE"})(ts||(ts={}));var E1={};E1=JSON.parse('{"name":"peerjs","version":"1.4.7","keywords":["peerjs","webrtc","p2p","rtc"],"description":"PeerJS client","homepage":"https://peerjs.com","bugs":{"url":"https://github.com/peers/peerjs/issues"},"repository":{"type":"git","url":"https://github.com/peers/peerjs"},"license":"MIT","contributors":["Michelle Bu <michelle@michellebu.com>","afrokick <devbyru@gmail.com>","ericz <really.ez@gmail.com>","Jairo <kidandcat@gmail.com>","Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>","Jairo Caro-Accino Viciana <jairo@galax.be>","Carlos Caballero <carlos.caballero.gonzalez@gmail.com>","hc <hheennrryy@gmail.com>","Muhammad Asif <capripio@gmail.com>","PrashoonB <prashoonbhattacharjee@gmail.com>","Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>","akotynski <aleksanderkotbury@gmail.com>","lmb <i@lmb.io>","Jairooo <jairocaro@msn.com>","Moritz Stückler <moritz.stueckler@gmail.com>","Simon <crydotsnakegithub@gmail.com>","Denis Lukov <denismassters@gmail.com>","Philipp Hancke <fippo@andyet.net>","Hans Oksendahl <hansoksendahl@gmail.com>","Jess <jessachandler@gmail.com>","khankuan <khankuan@gmail.com>","DUODVK <kurmanov.work@gmail.com>","XiZhao <kwang1imsa@gmail.com>","Matthias Lohr <matthias@lohr.me>","=frank tree <=frnktrb@googlemail.com>","Andre Eckardt <aeckardt@outlook.com>","Chris Cowan <agentme49@gmail.com>","Alex Chuev <alex@chuev.com>","alxnull <alxnull@e.mail.de>","Yemel Jardi <angel.jardi@gmail.com>","Ben Parnell <benjaminparnell.94@gmail.com>","Benny Lichtner <bennlich@gmail.com>","fresheneesz <bitetrudpublic@gmail.com>","bob.barstead@exaptive.com <bob.barstead@exaptive.com>","chandika <chandika@gmail.com>","emersion <contact@emersion.fr>","Christopher Van <cvan@users.noreply.github.com>","eddieherm <edhermoso@gmail.com>","Eduardo Pinho <enet4mikeenet@gmail.com>","Evandro Zanatta <ezanatta@tray.net.br>","Gardner Bickford <gardner@users.noreply.github.com>","Gian Luca <gianluca.cecchi@cynny.com>","PatrickJS <github@gdi2290.com>","jonnyf <github@jonathanfoss.co.uk>","Hizkia Felix <hizkifw@gmail.com>","Hristo Oskov <hristo.oskov@gmail.com>","Isaac Madwed <i.madwed@gmail.com>","Ilya Konanykhin <ilya.konanykhin@gmail.com>","jasonbarry <jasbarry@me.com>","Jonathan Burke <jonathan.burke.1311@googlemail.com>","Josh Hamit <josh.hamit@gmail.com>","Jordan Austin <jrax86@gmail.com>","Joel Wetzell <jwetzell@yahoo.com>","xizhao <kevin.wang@cloudera.com>","Alberto Torres <kungfoobar@gmail.com>","Jonathan Mayol <mayoljonathan@gmail.com>","Jefferson Felix <me@jsfelix.dev>","Rolf Erik Lekang <me@rolflekang.com>","Kevin Mai-Husan Chia <mhchia@users.noreply.github.com>","Pepijn de Vos <pepijndevos@gmail.com>","JooYoung <qkdlql@naver.com>","Tobias Speicher <rootcommander@gmail.com>","Steve Blaurock <sblaurock@gmail.com>","Kyrylo Shegeda <shegeda@ualberta.ca>","Diwank Singh Tomer <singh@diwank.name>","Sören Balko <Soeren.Balko@gmail.com>","Arpit Solanki <solankiarpit1997@gmail.com>","Yuki Ito <yuki@gnnk.net>","Artur Zayats <zag2art@gmail.com>"],"funding":{"type":"opencollective","url":"https://opencollective.com/peer"},"collective":{"type":"opencollective","url":"https://opencollective.com/peer"},"files":["dist/*"],"sideEffects":["lib/global.ts","lib/supports.ts"],"main":"dist/bundler.cjs","module":"dist/bundler.mjs","browser-minified":"dist/peerjs.min.js","browser-unminified":"dist/peerjs.js","types":"dist/types.d.ts","engines":{"node":">= 10"},"targets":{"types":{"source":"lib/exports.ts"},"main":{"source":"lib/exports.ts","sourceMap":{"inlineSources":true}},"module":{"source":"lib/exports.ts","includeNodeModules":["eventemitter3"],"sourceMap":{"inlineSources":true}},"browser-minified":{"context":"browser","outputFormat":"global","optimize":true,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"},"browser-unminified":{"context":"browser","outputFormat":"global","optimize":false,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"}},"scripts":{"contributors":"git-authors-cli --print=false && prettier --write package.json && git add package.json package-lock.json && git commit -m \\"chore(contributors): update and sort contributors list\\"","check":"tsc --noEmit","watch":"parcel watch","build":"rm -rf dist && parcel build","prepublishOnly":"npm run build","test":"mocha -r ts-node/register -r jsdom-global/register test/**/*.ts","format":"prettier --write .","semantic-release":"semantic-release"},"devDependencies":{"@parcel/config-default":"^2.5.0","@parcel/packager-ts":"^2.5.0","@parcel/transformer-typescript-tsc":"^2.5.0","@parcel/transformer-typescript-types":"^2.5.0","@semantic-release/changelog":"^6.0.1","@semantic-release/git":"^10.0.1","@types/chai":"^4.3.0","@types/mocha":"^9.1.0","@types/node":"^17.0.18","chai":"^4.3.6","git-authors-cli":"^1.0.40","jsdom":"^19.0.0","jsdom-global":"^3.0.2","mocha":"^9.2.0","mock-socket":"8.0.5","parcel":"^2.5.0","parcel-transformer-tsc-sourcemaps":"^1.0.2","prettier":"^2.6.2","semantic-release":"^19.0.2","standard":"^16.0.4","ts-node":"^10.5.0","typescript":"^4.5.5"},"dependencies":{"@swc/helpers":"^0.3.13","eventemitter3":"^4.0.7","peerjs-js-binarypack":"1.0.1","webrtc-adapter":"^7.7.1"}}');var Tj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),Pj=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var i=t.call(n),s,r=[],o;try{for(;(e===void 0||e-- >0)&&!(s=i.next()).done;)r.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return r},Rj=function(n,e,t){if(t||arguments.length===2)for(var i=0,s=e.length,r;i<s;i++)(r||!(i in e))&&(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return n.concat(r||Array.prototype.slice.call(e))},Bj=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},KP=function(n){Tj(e,n);function e(t,i,s,r,o,a){a===void 0&&(a=5e3);var l=n.call(this)||this;l.pingInterval=a,l._disconnected=!0,l._messagesQueue=[];var c=t?"wss://":"ws://";return l._baseUrl=c+i+":"+s+r+"peerjs?key="+o,l}return e.prototype.start=function(t,i){var s=this;this._id=t;var r="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(i);this._socket||!this._disconnected||(this._socket=new WebSocket(r+"&version="+E1.version),this._disconnected=!1,this._socket.onmessage=function(o){var a;try{a=JSON.parse(o.data),it.default.log("Server message received:",a)}catch{it.default.log("Invalid server message",o.data);return}s.emit(Cl.Message,a)},this._socket.onclose=function(o){s._disconnected||(it.default.log("Socket closed.",o),s._cleanup(),s._disconnected=!0,s.emit(Cl.Disconnected))},this._socket.onopen=function(){s._disconnected||(s._sendQueuedMessages(),it.default.log("Socket open"),s._scheduleHeartbeat())})},e.prototype._scheduleHeartbeat=function(){var t=this;this._wsPingTimer=setTimeout(function(){t._sendHeartbeat()},this.pingInterval)},e.prototype._sendHeartbeat=function(){if(!this._wsOpen()){it.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:ts.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,i,s=Rj([],Pj(this._messagesQueue),!1);this._messagesQueue=[];try{for(var r=Bj(s),o=r.next();!o.done;o=r.next()){var a=o.value;this.send(a)}}catch(l){t={error:l}}finally{try{o&&!o.done&&(i=r.return)&&i.call(r)}finally{if(t)throw t.error}}},e.prototype.send=function(t){if(!this._disconnected){if(!this._id){this._messagesQueue.push(t);return}if(!t.type){this.emit(Cl.Error,"Invalid message");return}if(this._wsOpen()){var i=JSON.stringify(t);this._socket.send(i)}}},e.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},e.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)},e}(uA.EventEmitter),IS={};La(IS,"MediaConnection",()=>eR,n=>eR=n);var I1={};La(I1,"Negotiator",()=>ZP,n=>ZP=n);var H0=function(){return H0=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},H0.apply(this,arguments)},ty=function(n,e,t,i){function s(r){return r instanceof t?r:new t(function(o){o(r)})}return new(t||(t=Promise))(function(r,o){function a(h){try{c(i.next(h))}catch(d){o(d)}}function l(h){try{c(i.throw(h))}catch(d){o(d)}}function c(h){h.done?r(h.value):s(h.value).then(a,l)}c((i=i.apply(n,e||[])).next())})},iy=function(n,e){var t={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},i,s,r,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return l([c,h])}}function l(c){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,s&&(r=c[0]&2?s.return:c[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,c[1])).done)return r;switch(s=0,r&&(c=[c[0]&2,r.value]),c[0]){case 0:case 1:r=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,s=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(r=t.trys,!(r=r.length>0&&r[r.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!r||c[1]>r[0]&&c[1]<r[3])){t.label=c[1];break}if(c[0]===6&&t.label<r[1]){t.label=r[1],r=c;break}if(r&&t.label<r[2]){t.label=r[2],t.ops.push(c);break}r[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(n,t)}catch(h){c=[6,h],s=0}finally{i=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},ZP=function(){function n(e){this.connection=e}return n.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===ko.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===ko.Data){var i=this.connection,s={ordered:!!e.reliable},r=t.createDataChannel(i.label,s);i.initialize(r)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},n.prototype._startPeerConnection=function(){it.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},n.prototype._setupListeners=function(e){var t=this,i=this.connection.peer,s=this.connection.connectionId,r=this.connection.type,o=this.connection.provider;it.default.log("Listening for ICE candidates."),e.onicecandidate=function(a){!a.candidate||!a.candidate.candidate||(it.default.log("Received ICE candidates for ".concat(i,":"),a.candidate),o.socket.send({type:ts.Candidate,payload:{candidate:a.candidate,type:r,connectionId:s},dst:i}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":it.default.log("iceConnectionState is failed, closing connections to "+i),t.connection.emit("error",new Error("Negotiation of connection to "+i+" failed.")),t.connection.close();break;case"closed":it.default.log("iceConnectionState is closed, closing connections to "+i),t.connection.emit("error",new Error("Connection to "+i+" closed.")),t.connection.close();break;case"disconnected":it.default.log("iceConnectionState changed to disconnected on the connection with "+i);break;case"completed":e.onicecandidate=li.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},it.default.log("Listening for data channel"),e.ondatachannel=function(a){it.default.log("Received data channel");var l=a.channel,c=o.getConnection(i,s);c.initialize(l)},it.default.log("Listening for remote stream"),e.ontrack=function(a){it.default.log("Received remote stream");var l=a.streams[0],c=o.getConnection(i,s);if(c.type===ko.Media){var h=c;t._addStreamToMediaConnection(l,h)}}},n.prototype.cleanup=function(){it.default.log("Cleaning up PeerConnection to "+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!=="closed",i=!1;if(this.connection.type===ko.Data){var s=this.connection,r=s.dataChannel;r&&(i=!!r.readyState&&r.readyState!=="closed")}(t||i)&&e.close()}},n.prototype._makeOffer=function(){return ty(this,void 0,Promise,function(){var e,t,i,s,r,o,a;return iy(this,function(l){switch(l.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,l.label=1;case 1:return l.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:i=l.sent(),it.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(i.sdp=this.connection.options.sdpTransform(i.sdp)||i.sdp),l.label=3;case 3:return l.trys.push([3,5,,6]),[4,e.setLocalDescription(i)];case 4:return l.sent(),it.default.log("Set localDescription:",i,"for:".concat(this.connection.peer)),s={sdp:i,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:li.browser},this.connection.type===ko.Data&&(r=this.connection,s=H0(H0({},s),{label:r.label,reliable:r.reliable,serialization:r.serialization})),t.socket.send({type:ts.Offer,payload:s,dst:this.connection.peer}),[3,6];case 5:return o=l.sent(),o!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(t.emitError(nn.WebRTC,o),it.default.log("Failed to setLocalDescription, ",o)),[3,6];case 6:return[3,8];case 7:return a=l.sent(),t.emitError(nn.WebRTC,a),it.default.log("Failed to createOffer, ",a),[3,8];case 8:return[2]}})})},n.prototype._makeAnswer=function(){return ty(this,void 0,Promise,function(){var e,t,i,s,r;return iy(this,function(o){switch(o.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,o.label=1;case 1:return o.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:i=o.sent(),it.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(i.sdp=this.connection.options.sdpTransform(i.sdp)||i.sdp),o.label=3;case 3:return o.trys.push([3,5,,6]),[4,e.setLocalDescription(i)];case 4:return o.sent(),it.default.log("Set localDescription:",i,"for:".concat(this.connection.peer)),t.socket.send({type:ts.Answer,payload:{sdp:i,type:this.connection.type,connectionId:this.connection.connectionId,browser:li.browser},dst:this.connection.peer}),[3,6];case 5:return s=o.sent(),t.emitError(nn.WebRTC,s),it.default.log("Failed to setLocalDescription, ",s),[3,6];case 6:return[3,8];case 7:return r=o.sent(),t.emitError(nn.WebRTC,r),it.default.log("Failed to create answer, ",r),[3,8];case 8:return[2]}})})},n.prototype.handleSDP=function(e,t){return ty(this,void 0,Promise,function(){var i,s,r,o;return iy(this,function(a){switch(a.label){case 0:t=new RTCSessionDescription(t),i=this.connection.peerConnection,s=this.connection.provider,it.default.log("Setting remote description",t),r=this,a.label=1;case 1:return a.trys.push([1,5,,6]),[4,i.setRemoteDescription(t)];case 2:return a.sent(),it.default.log("Set remoteDescription:".concat(e," for:").concat(this.connection.peer)),e!=="OFFER"?[3,4]:[4,r._makeAnswer()];case 3:a.sent(),a.label=4;case 4:return[3,6];case 5:return o=a.sent(),s.emitError(nn.WebRTC,o),it.default.log("Failed to setRemoteDescription, ",o),[3,6];case 6:return[2]}})})},n.prototype.handleCandidate=function(e){return ty(this,void 0,Promise,function(){var t,i,s,r,o,a;return iy(this,function(l){switch(l.label){case 0:it.default.log("handleCandidate:",e),t=e.candidate,i=e.sdpMLineIndex,s=e.sdpMid,r=this.connection.peerConnection,o=this.connection.provider,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,r.addIceCandidate(new RTCIceCandidate({sdpMid:s,sdpMLineIndex:i,candidate:t}))];case 2:return l.sent(),it.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return a=l.sent(),o.emitError(nn.WebRTC,a),it.default.log("Failed to handleCandidate, ",a),[3,4];case 4:return[2]}})})},n.prototype._addTracksToConnection=function(e,t){if(it.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return it.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(i){t.addTrack(i,e)})},n.prototype._addStreamToMediaConnection=function(e,t){it.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},n}(),M1={};La(M1,"BaseConnection",()=>$P,n=>$P=n);var Dj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),$P=function(n){Dj(e,n);function e(t,i,s){var r=n.call(this)||this;return r.peer=t,r.provider=i,r.options=s,r._open=!1,r.metadata=s.metadata,r}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e}(uA.EventEmitter),kj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),V0=function(){return V0=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},V0.apply(this,arguments)},Oj=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},eR=function(n){kj(e,n);function e(t,i,s){var r=n.call(this,t,i,s)||this;return r._localStream=r.options._stream,r.connectionId=r.options.connectionId||e.ID_PREFIX+li.randomToken(),r._negotiator=new I1.Negotiator(r),r._localStream&&r._negotiator.startConnection({_stream:r._localStream,originator:!0}),r}return Object.defineProperty(e.prototype,"type",{get:function(){return ko.Media},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localStream",{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteStream",{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),e.prototype.addStream=function(t){it.default.log("Receiving stream",t),this._remoteStream=t,n.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var i=t.type,s=t.payload;switch(t.type){case ts.Answer:this._negotiator.handleSDP(i,s.sdp),this._open=!0;break;case ts.Candidate:this._negotiator.handleCandidate(s.candidate);break;default:it.default.warn("Unrecognized message type:".concat(i," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,i){var s,r;if(i===void 0&&(i={}),this._localStream){it.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,i&&i.sdpTransform&&(this.options.sdpTransform=i.sdpTransform),this._negotiator.startConnection(V0(V0({},this.options._payload),{_stream:t}));var o=this.provider._getMessages(this.connectionId);try{for(var a=Oj(o),l=a.next();!l.done;l=a.next()){var c=l.value;this.handleMessage(c)}}catch(h){s={error:h}}finally{try{l&&!l.done&&(r=a.return)&&r.call(a)}finally{if(s)throw s.error}}this._open=!0},e.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,n.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e}(M1.BaseConnection),MS={};La(MS,"DataConnection",()=>iR,n=>iR=n);var hL={};La(hL,"EncodingQueue",()=>tR,n=>tR=n);var Lj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),tR=function(n){Lj(e,n);function e(){var t=n.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(i){t._processing=!1,i.target&&t.emit("done",i.target.result),t.doNextTask()},t.fileReader.onerror=function(i){it.default.error("EncodingQueue error:",i),t._processing=!1,t.destroy(),t.emit("error",i)},t}return Object.defineProperty(e.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),e.prototype.enque=function(t){this.queue.push(t),!this.processing&&this.doNextTask()},e.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},e.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},e}(uA.EventEmitter),Fj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),Uj=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},iR=function(n){Fj(e,n);function e(t,i,s){var r=n.call(this,t,i,s)||this;return r.stringify=JSON.stringify,r.parse=JSON.parse,r._buffer=[],r._bufferSize=0,r._buffering=!1,r._chunkedData={},r._encodingQueue=new hL.EncodingQueue,r.connectionId=r.options.connectionId||e.ID_PREFIX+li.randomToken(),r.label=r.options.label||r.connectionId,r.serialization=r.options.serialization||ol.Binary,r.reliable=!!r.options.reliable,r._encodingQueue.on("done",function(o){r._bufferedSend(o)}),r._encodingQueue.on("error",function(){it.default.error("DC#".concat(r.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),r.close()}),r._negotiator=new I1.Negotiator(r),r._negotiator.startConnection(r.options._payload||{originator:!0}),r}return Object.defineProperty(e.prototype,"type",{get:function(){return ko.Data},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataChannel",{get:function(){return this._dc},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bufferSize",{get:function(){return this._bufferSize},enumerable:!1,configurable:!0}),e.prototype.initialize=function(t){this._dc=t,this._configureDataChannel()},e.prototype._configureDataChannel=function(){var t=this;(!li.supports.binaryBlob||li.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){it.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(i){it.default.log("DC#".concat(t.connectionId," dc onmessage:"),i.data),t._handleDataMessage(i)},this.dataChannel.onclose=function(){it.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var i=this,s=t.data,r=s.constructor,o=this.serialization===ol.Binary||this.serialization===ol.BinaryUTF8,a=s;if(o){if(r===Blob){li.blobToArrayBuffer(s,function(c){var h=li.unpack(c);i.emit("data",h)});return}else if(r===ArrayBuffer)a=li.unpack(s);else if(r===String){var l=li.binaryStringToArrayBuffer(s);a=li.unpack(l)}}else this.serialization===ol.JSON&&(a=this.parse(s));if(a.__peerData){this._handleChunk(a);return}n.prototype.emit.call(this,"data",a)},e.prototype._handleChunk=function(t){var i=t.__peerData,s=this._chunkedData[i]||{data:[],count:0,total:t.total};if(s.data[t.n]=t.data,s.count++,this._chunkedData[i]=s,s.total===s.count){delete this._chunkedData[i];var r=new Blob(s.data);this._handleDataMessage({data:r})}},e.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),this._encodingQueue=null),this.open&&(this._open=!1,n.prototype.emit.call(this,"close"))},e.prototype.send=function(t,i){if(!this.open){n.prototype.emit.call(this,"error",new Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===ol.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===ol.Binary||this.serialization===ol.BinaryUTF8){var s=li.pack(t);if(!i&&s.size>li.chunkedMTU){this._sendChunks(s);return}li.supports.binaryBlob?this._bufferedSend(s):this._encodingQueue.enque(s)}else this._bufferedSend(t)},e.prototype._bufferedSend=function(t){(this._buffering||!this._trySend(t))&&(this._buffer.push(t),this._bufferSize=this._buffer.length)},e.prototype._trySend=function(t){var i=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){i._buffering=!1,i._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(s){return it.default.error("DC#:".concat(this.connectionId," Error when sending:"),s),this._buffering=!0,this.close(),!1}return!0},e.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},e.prototype._sendChunks=function(t){var i,s,r=li.chunk(t);it.default.log("DC#".concat(this.connectionId," Try to send ").concat(r.length," chunks..."));try{for(var o=Uj(r),a=o.next();!a.done;a=o.next()){var l=a.value;this.send(l,!0)}}catch(c){i={error:c}}finally{try{a&&!a.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}},e.prototype.handleMessage=function(t){var i=t.payload;switch(t.type){case ts.Answer:this._negotiator.handleSDP(t.type,i.sdp);break;case ts.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:it.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e}(M1.BaseConnection),uL={};La(uL,"API",()=>rR,n=>rR=n);var nR=function(n,e,t,i){function s(r){return r instanceof t?r:new t(function(o){o(r)})}return new(t||(t=Promise))(function(r,o){function a(h){try{c(i.next(h))}catch(d){o(d)}}function l(h){try{c(i.throw(h))}catch(d){o(d)}}function c(h){h.done?r(h.value):s(h.value).then(a,l)}c((i=i.apply(n,e||[])).next())})},sR=function(n,e){var t={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},i,s,r,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return l([c,h])}}function l(c){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,s&&(r=c[0]&2?s.return:c[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,c[1])).done)return r;switch(s=0,r&&(c=[c[0]&2,r.value]),c[0]){case 0:case 1:r=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,s=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(r=t.trys,!(r=r.length>0&&r[r.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!r||c[1]>r[0]&&c[1]<r[3])){t.label=c[1];break}if(c[0]===6&&t.label<r[1]){t.label=r[1],r=c;break}if(r&&t.label<r[2]){t.label=r[2],t.ops.push(c);break}r[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(n,t)}catch(h){c=[6,h],s=0}finally{i=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},rR=function(){function n(e){this._options=e}return n.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",i=this._options,s=i.host,r=i.port,o=i.path,a=i.key,l=new URL("".concat(t,"://").concat(s,":").concat(r).concat(o).concat(a,"/").concat(e));return l.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),l.searchParams.set("version",E1.version),fetch(l.href,{referrerPolicy:this._options.referrerPolicy})},n.prototype.retrieveId=function(){return nR(this,void 0,Promise,function(){var e,t,i;return sR(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=s.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=s.sent(),it.default.error("Error retrieving ID",t),i="",this._options.path==="/"&&this._options.host!==li.CLOUD_HOST&&(i=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+i);case 3:return[2]}})})},n.prototype.listAllPeers=function(){return nR(this,void 0,Promise,function(){var e,t,i;return sR(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=s.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===li.CLOUD_HOST?t="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":t="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+t)):new Error("Error. Status:".concat(e.status));return[2,e.json()];case 2:throw i=s.sent(),it.default.error("Error retrieving list peers",i),new Error("Could not get list peers from the server."+i);case 3:return[2]}})})},n}(),Nj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),Pg=function(){return Pg=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},Pg.apply(this,arguments)},Hp=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},zj=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var i=t.call(n),s,r=[],o;try{for(;(e===void 0||e-- >0)&&!(s=i.next()).done;)r.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return r},oR=function(n){Nj(e,n);function e(t,i){var s=n.call(this)||this;s._id=null,s._lastServerId=null,s._destroyed=!1,s._disconnected=!1,s._open=!1,s._connections=new Map,s._lostMessages=new Map;var r;return t&&t.constructor==Object?i=t:t&&(r=t.toString()),i=Pg({debug:0,host:li.CLOUD_HOST,port:li.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:li.randomToken(),config:li.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},i),s._options=i,s._options.host==="/"&&(s._options.host=window.location.hostname),s._options.path&&(s._options.path[0]!=="/"&&(s._options.path="/"+s._options.path),s._options.path[s._options.path.length-1]!=="/"&&(s._options.path+="/")),s._options.secure===void 0&&s._options.host!==li.CLOUD_HOST?s._options.secure=li.isSecure():s._options.host==li.CLOUD_HOST&&(s._options.secure=!0),s._options.logFunction&&it.default.setLogFunction(s._options.logFunction),it.default.logLevel=s._options.debug||0,s._api=new uL.API(i),s._socket=s._createServerConnection(),!li.supports.audioVideo&&!li.supports.data?(s._delayedAbort(nn.BrowserIncompatible,"The current browser does not support WebRTC"),s):r&&!li.validateId(r)?(s._delayedAbort(nn.InvalidID,'ID "'.concat(r,'" is invalid')),s):(r?s._initialize(r):s._api.retrieveId().then(function(o){return s._initialize(o)}).catch(function(o){return s._abort(nn.ServerError,o)}),s)}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){var t,i,s=Object.create(null);try{for(var r=Hp(this._connections),o=r.next();!o.done;o=r.next()){var a=zj(o.value,2),l=a[0],c=a[1];s[l]=c}}catch(h){t={error:h}}finally{try{o&&!o.done&&(i=r.return)&&i.call(r)}finally{if(t)throw t.error}}return s},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),e.prototype._createServerConnection=function(){var t=this,i=new cL.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return i.on(Cl.Message,function(s){t._handleMessage(s)}),i.on(Cl.Error,function(s){t._abort(nn.SocketError,s)}),i.on(Cl.Disconnected,function(){t.disconnected||(t.emitError(nn.Network,"Lost connection to server."),t.disconnect())}),i.on(Cl.Close,function(){t.disconnected||t._abort(nn.SocketClosed,"Underlying socket is already closed.")}),i},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var i,s,r=t.type,o=t.payload,a=t.src;switch(r){case ts.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case ts.Error:this._abort(nn.ServerError,o.msg);break;case ts.IdTaken:this._abort(nn.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case ts.InvalidKey:this._abort(nn.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case ts.Leave:it.default.log("Received leave message from ".concat(a)),this._cleanupPeer(a),this._connections.delete(a);break;case ts.Expire:this.emitError(nn.PeerUnavailable,"Could not connect to peer ".concat(a));break;case ts.Offer:var g=o.connectionId,m=this.getConnection(a,g);if(m&&(m.close(),it.default.warn("Offer received for existing Connection ID:".concat(g))),o.type===ko.Media){var l=new IS.MediaConnection(a,this,{connectionId:g,_payload:o,metadata:o.metadata});m=l,this._addConnection(a,m),this.emit("call",l)}else if(o.type===ko.Data){var c=new MS.DataConnection(a,this,{connectionId:g,_payload:o,metadata:o.metadata,label:o.label,serialization:o.serialization,reliable:o.reliable});m=c,this._addConnection(a,m),this.emit("connection",c)}else{it.default.warn("Received malformed connection type:".concat(o.type));return}var h=this._getMessages(g);try{for(var d=Hp(h),f=d.next();!f.done;f=d.next()){var p=f.value;m.handleMessage(p)}}catch(A){i={error:A}}finally{try{f&&!f.done&&(s=d.return)&&s.call(d)}finally{if(i)throw i.error}}break;default:if(!o){it.default.warn("You received a malformed message from ".concat(a," of type ").concat(r));return}var g=o.connectionId,m=this.getConnection(a,g);m&&m.peerConnection?m.handleMessage(t):g?this._storeMessage(g,t):it.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,i){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(i)},e.prototype._getMessages=function(t){var i=this._lostMessages.get(t);return i?(this._lostMessages.delete(t),i):[]},e.prototype.connect=function(t,i){if(i===void 0&&(i={}),this.disconnected){it.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),this.emitError(nn.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var s=new MS.DataConnection(t,this,i);return this._addConnection(t,s),s},e.prototype.call=function(t,i,s){if(s===void 0&&(s={}),this.disconnected){it.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),this.emitError(nn.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!i){it.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var r=new IS.MediaConnection(t,this,Pg(Pg({},s),{_stream:i}));return this._addConnection(t,r),r},e.prototype._addConnection=function(t,i){it.default.log("add connection ".concat(i.type,":").concat(i.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(i)},e.prototype._removeConnection=function(t){var i=this._connections.get(t.peer);if(i){var s=i.indexOf(t);s!==-1&&i.splice(s,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,i){var s,r,o=this._connections.get(t);if(!o)return null;try{for(var a=Hp(o),l=a.next();!l.done;l=a.next()){var c=l.value;if(c.connectionId===i)return c}}catch(h){s={error:h}}finally{try{l&&!l.done&&(r=a.return)&&r.call(a)}finally{if(s)throw s.error}}return null},e.prototype._delayedAbort=function(t,i){var s=this;setTimeout(function(){s._abort(t,i)},0)},e.prototype._abort=function(t,i){it.default.error("Aborting!"),this.emitError(t,i),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,i){it.default.error("Error:",i);var s;typeof i=="string"?s=new Error(i):s=i,s.type=t,this.emit("error",s)},e.prototype.destroy=function(){this.destroyed||(it.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},e.prototype._cleanup=function(){var t,i;try{for(var s=Hp(this._connections.keys()),r=s.next();!r.done;r=s.next()){var o=r.value;this._cleanupPeer(o),this._connections.delete(o)}}catch(a){t={error:a}}finally{try{r&&!r.done&&(i=s.return)&&i.call(s)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var i,s,r=this._connections.get(t);if(r)try{for(var o=Hp(r),a=o.next();!a.done;a=o.next()){var l=a.value;l.close()}}catch(c){i={error:c}}finally{try{a&&!a.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;it.default.log("Disconnect peer with ID:".concat(t)),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=t,this._id=null,this.emit("disconnected",t)}},e.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)it.default.log("Attempting reconnection to server with ID ".concat(this._lastServerId)),this._disconnected=!1,this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(!this.disconnected&&!this.open)it.default.error("In a hurry? We're still trying to make the initial connection!");else throw new Error("Peer ".concat(this.id," cannot reconnect because it is not disconnected from the server!"))}},e.prototype.listAllPeers=function(t){var i=this;t===void 0&&(t=function(s){}),this._api.listAllPeers().then(function(s){return t(s)}).catch(function(s){return i._abort(nn.ServerError,s)})},e.DEFAULT_KEY="peerjs",e}(uA.EventEmitter),j0=aL.Peer;class Gj{constructor(){u(this,"_host");u(this,"_client");u(this,"_clientData");this.onEnable()}get isHost(){return this._host!==void 0}onEnable(){const e="HOST-5980e65c-8438-453e-8b35-f13c736dcd81";this.trySetupHost(e)}trySetupHost(e){let t=new j0(e);t.on("error",i=>{console.error(i),this._host=void 0,this.trySetupClient(e)}),t.on("open",i=>{this._host=new Hj(t)})}trySetupClient(e){this._client=new j0,this._client.on("error",t=>{console.error("Client error",t)}),this._client.on("open",t=>{console.log("client connected",t),this._clientData=this._client.connect(e,{metadata:{id:t}}),this._clientData.on("open",()=>{console.log("Connected to host")}),this._clientData.on("data",i=>{console.log("<<",i)})})}}class Qj{constructor(e){u(this,"_peer");this._peer=e}}class Hj extends Qj{constructor(t){var i;super(t);u(this,"_connections",[]);console.log("I AM THE HOST"),(i=this._peer)==null||i.on("connection",this.onConnection.bind(this)),this._peer.on("close",()=>{this.broadcast("BYE")}),setInterval(()=>{this.broadcast("HELLO")},2e3)}get isHost(){return!0}onConnection(t){console.log("host connection",t),t.on("open",()=>{this._connections.push(t),this.broadcastConnection(t)})}broadcastConnection(t){const i=this._connections.map(s=>{var r;return(r=s.metadata)==null?void 0:r.id}).filter(s=>s!==void 0);this.broadcast({type:"connection-list",connections:i})}broadcast(t){if(t!=null){console.log(">>",t);for(const i in this._peer.connections){const s=this._peer.connections[i];if(s)if(Array.isArray(s))for(const r of s)r&&r.send(t);else console.warn(s)}}}}var tr=(n=>(n[n.OnConnection=0]="OnConnection",n[n.OnRoomJoin=1]="OnRoomJoin",n[n.Queued=2]="Queued",n[n.Immediate=3]="Immediate",n))(tr||{});const aR="https://urls.needle.tools/default-networking-backend/index";let hc="wss://needle-tiny-starter.glitch.me/socket";const Ps=!!le("debugnet"),pg=!!(Ps||le("debugowner"));var dL=(n=>(n.ConnectionInfo="connection-start-info",n))(dL||{}),Ji=(n=>(n.Join="join-room",n.Leave="leave-room",n.JoinedRoom="joined-room",n.LeftRoom="left-room",n.UserJoinedRoom="user-joined-room",n.UserLeftRoom="user-left-room",n))(Ji||{});class Vj{constructor(){u(this,"room");u(this,"viewId");u(this,"allowEditing");u(this,"inRoom")}}class jj{constructor(){u(this,"room")}}class Wj{constructor(){u(this,"userId")}}var fL=(n=>(n.RequestHasOwner="request-has-owner",n.ResponseHasOwner="response-has-owner",n.RequestIsOwner="request-is-owner",n.ResponseIsOwner="response-is-owner",n.RequestOwnership="request-ownership",n.GainedOwnership="gained-ownership",n.RemoveOwnership="remove-ownership",n.LostOwnership="lost-ownership",n.GainedOwnershipBroadcast="gained-ownership-broadcast",n.LostOwnershipBroadcast="lost-ownership-broadcast",n))(fL||{});class db{constructor(e,t){u(this,"guid");u(this,"connection");u(this,"_hasOwnership",!1);u(this,"_isOwned");u(this,"_gainSubscription");u(this,"_lostSubscription");u(this,"_hasOwnerResponse");u(this,"_isWaitingForOwnershipResponseCallback",null);this.connection=e,this.guid=t,this._gainSubscription=this.onGainedOwnership.bind(this),this._lostSubscription=this.onLostOwnership.bind(this),e.beginListen("lost-ownership",this._lostSubscription),e.beginListen("gained-ownership-broadcast",this._gainSubscription),this._hasOwnerResponse=this.onHasOwnerResponse.bind(this),e.beginListen("response-has-owner",this._hasOwnerResponse)}get hasOwnership(){return this._hasOwnership}get isOwned(){return this._isOwned}get isConnected(){return this.connection.isConnected}updateIsOwned(){this.connection.send("request-has-owner",{guid:this.guid})}onHasOwnerResponse(e){e.guid===this.guid&&(this._isOwned=e.value)}requestOwnershipIfNotOwned(){return this._isWaitingForOwnershipResponseCallback!==null?this:(this._isWaitingForOwnershipResponseCallback=this.waitForHasOwnershipRequestResponse.bind(this),this.connection.beginListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this.connection.send("request-has-owner",{guid:this.guid}),this)}waitForHasOwnershipRequestResponse(e){e.guid===this.guid&&(this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this._isOwned=e.value,e.value||(pg&&console.log("request ownership",this.guid),this.requestOwnership()))}requestOwnershipAsync(){return new Promise((e,t)=>{this.requestOwnership();let i=0;const s=()=>{if(i++>10)return t("Timeout");setTimeout(()=>{this.hasOwnership?e(this):s()},100)};s()})}requestOwnership(){return pg&&console.log("Request ownership",this.guid),this.connection.send("request-ownership",{guid:this.guid}),this}freeOwnership(){return this.connection.send("remove-ownership",{guid:this.guid}),this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this}destroy(){this.connection.stopListen("gained-ownership",this._gainSubscription),this.connection.stopListen("lost-ownership",this._lostSubscription),this.connection.stopListen("response-has-owner",this._hasOwnerResponse),this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null)}onGainedOwnership(e){e.guid===this.guid&&(this._isOwned=!0,this.connection.connectionId===e.owner?(pg&&console.log("GAINED OWNERSHIP",this.guid),this._hasOwnership=!0):this._hasOwnership=!1)}onLostOwnership(e){e===this.guid&&(pg&&console.log("LOST OWNERSHIP",this.guid),this._hasOwnership=!1,this._isOwned=!1)}}class pL{constructor(e){u(this,"context");u(this,"_peer",null);u(this,"_usersInRoomCopy",[]);u(this,"_defaultMessagesBuffer",[]);u(this,"_defaultMessagesBufferArray",[]);u(this,"netWebSocketUrlProvider");u(this,"_listeners",{});u(this,"_listenersBinary",{});u(this,"connected",!1);u(this,"channelId");u(this,"_connectionId",null);u(this,"_ws");u(this,"_waitingForSocket",{});u(this,"_isInRoom",!1);u(this,"_currentRoomName",null);u(this,"_currentRoomViewId",null);u(this,"_currentRoomAllowEditing",!0);u(this,"_currentInRoom",[]);u(this,"_state",{});u(this,"_currentDelay",-1);u(this,"_connectingToWebsocketPromise",null);this.context=e}get peer(){return this._peer||(this._peer=new Gj),this._peer}tryGetState(e){return e==="invalid"?null:this._state[e]}get connectionId(){return this._connectionId}get isDebugEnabled(){return Ps}get isConnected(){return this.connected}get currentRoomName(){return this._currentRoomName}get allowEditing(){return this._currentRoomAllowEditing}get currentRoomViewId(){return this._currentRoomViewId}get isInRoom(){return this._isInRoom}get currentLatency(){return this._currentDelay}sendPing(){this.send("ping",{time:this.context.time.time})}userIsInRoom(e){return this._currentInRoom.indexOf(e)!==-1}usersInRoom(e=null){e||(e=this._usersInRoomCopy),e.length=0;for(const t of this._currentInRoom)e.push(t);return e}joinRoom(e,t=!1){this.connect(),Ps&&console.log("join: "+e),this.send("join-room",{room:e,viewOnly:t},tr.OnConnection)}leaveRoom(e=null){if(e||(e=this.currentRoomName),!e){console.error("Can not leave unknown room");return}this.send("leave-room",{room:e})}send(e,t=null,i=tr.Queued){if(t===null&&(t={}),i===tr.Queued){this._defaultMessagesBuffer.push({key:e,value:t});return}return this.sendWithWebsocket(e,t,i)}sendDeleteRemoteState(e){this.send("delete-state",{guid:e,dontSave:!0}),delete this._state[e]}sendDeleteRemoteStateAll(){this.send("delete-all-state"),this._state={}}sendBinary(e){var t;Ps&&console.log("<< bin",e.length),(t=this._ws)==null||t.send(e)}sendBufferedMessagesNow(){var i;if(!this._ws)return;this._defaultMessagesBufferArray.length=0;const e=Object.keys(this._defaultMessagesBuffer).length;for(const s in this._defaultMessagesBuffer){const r=this._defaultMessagesBuffer[s];if(e<=1){this.sendWithWebsocket(r.key,r.value,tr.Immediate);break}const o=this.toMessage(r.key,r.value);this._defaultMessagesBufferArray.push(o)}if(this._defaultMessagesBuffer.length=0,this._defaultMessagesBufferArray.length>0&&Ps&&console.log("SEND BUFFERED",this._defaultMessagesBufferArray.length),this._defaultMessagesBufferArray.length<=0)return;const t=JSON.stringify(this._defaultMessagesBufferArray);(i=this._ws)==null||i.send(t)}beginListen(e,t){return this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t),t}stopListening(e,t){return this.stopListen(e,t)}stopListen(e,t){if(!t||!this._listeners[e])return;const i=this._listeners[e].indexOf(t);i>=0&&this._listeners[e].splice(i,1)}beginListenBinary(e,t){return this._listenersBinary[e]||(this._listenersBinary[e]=[]),this._listenersBinary[e].push(t),t}stopListenBinary(e,t){if(!this._listenersBinary[e])return;const i=this._listenersBinary[e].indexOf(t);i>=0&&this._listenersBinary[e].splice(i,1)}registerProvider(e){this.netWebSocketUrlProvider=e}async connect(){var t;if(this.connected)return Promise.resolve(!0);Ps&&console.log("connecting");const e=(t=this.netWebSocketUrlProvider)==null?void 0:t.getWebsocketUrl();return e?hc=e:ck()&&(hc="wss://"+window.location.host+"/socket"),this.connectWebsocket()}disconnect(){var e;(e=this._ws)==null||e.close(),this._ws=void 0}connectWebsocket(){return this._connectingToWebsocketPromise?this._connectingToWebsocketPromise:this._connectingToWebsocketPromise=new Promise(async(e,t)=>{let i=!1;const s=o=>{i||(i=!0,e(o))};if(hc===void 0&&(console.log("Fetch default backend url: "+aR),hc=await(await fetch(aR)).text()),hc===void 0){s(!1);return}console.log(`⊡ Connecting to networking backend on
|
|
3334
3334
|
`+hc);const r=new yO.WebsocketBuilder(hc).onOpen(()=>{this._connectingToWebsocketPromise=null,this._ws=r,this.connected=!0,console.log(`⊞ Connected to networking backend
|
|
3335
3335
|
`+hc),s(!0),this.onSendQueued(tr.OnConnection)}).onClose(o=>{this._connectingToWebsocketPromise=null,this.connected=!1,this._isInRoom=!1,s(!1)}).onError((o,a)=>{console.error("⊠ Websocket error",o,a),s(!1)}).onMessage(this.onMessage.bind(this)).onRetry(()=>{console.log("Retry connecting to networking websocket")}).build()})}onMessage(e,t){const i=t.data;try{if(typeof i!="string"){i.size&&this.handleIncomingBinaryMessage(i);return}const s=JSON.parse(i);if(Array.isArray(s))for(const r of s)this.handleIncomingStringMessage(r);else this.handleIncomingStringMessage(s);return}catch{Ps&&i==="pong"&&console.log("<<",i)}}async handleIncomingBinaryMessage(e){const t=await e.arrayBuffer();var i=new Uint8Array(t);const s=new gm(i),r=s.getBufferIdentifier(),o=this._listenersBinary[r],a=rj(s),l=oj(a);if(l&&typeof l=="string"&&(this._state[l]=a),!o)return;const c=a??s;for(const h of o)h(c)}handleIncomingStringMessage(e){var s,r;if(Ps&&console.log("<<",e.key??e),e.key)switch(e.key){case"connection-start-info":if(e.data){const l=e.data;l&&(console.assert(l.id!==void 0&&l.id!==null&&l.id.length>0,"server did not send connection id",l.id),console.log("Your id is: "+l.id,this.context.alias??""),this._connectionId=l.id)}else console.warn("Expected connection id in "+e.key);break;case"joined-room":if(Ps&&console.log(e),e){this._isInRoom=!0;const l=e;this._currentRoomName=l.room,this._currentRoomViewId=l.viewId,this._currentRoomAllowEditing=l.allowEditing??!0,console.log("Room view id",this._currentRoomViewId),this._currentInRoom.length=0,this._currentInRoom.push(...l.inRoom),Ps&&console.log("joined room with",this._currentInRoom,this.context.alias??"")}this.onSendQueued(tr.OnRoomJoin);break;case"left-room":e.room===this.currentRoomName&&(this._isInRoom=!1,this._currentRoomName=null,this._currentInRoom.length=0);break;case"user-joined-room":if(e.data){const l=e.data;this._currentInRoom.push(l.userId),Ps&&console.log(l.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(e.data){const l=e.data,c=this._currentInRoom.indexOf(l.userId);c>=0&&(console.log(l.userId+" left",this.context.alias??""),this._currentInRoom.splice(c,1)),l.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":Ps&&console.log("RECEIVED all-room-state-deleted"),this._state={};break;case"ping":case"pong":const a=(s=e.data)==null?void 0:s.time;a&&(this._currentDelay=this.context.time.time-a),Ps&&console.log("Current latency: "+this._currentDelay.toFixed(1)+" sec","Clients in room: "+((r=this._currentInRoom)==null?void 0:r.length));break}const t=this._listeners[e.key];if(t)for(const o of t)o(e.data);const i=e.data;i&&(this._state[i.guid]=i)}toMessage(e,t){return{key:e,data:t}}sendWithWebsocket(e,t,i=tr.OnRoomJoin){if(!this._ws){const r=this._waitingForSocket[i]||[];r.push(()=>this.sendWithWebsocket(e,t,i)),this._waitingForSocket[i]=r;return}const s=JSON.stringify(this.toMessage(e,t));Ps&&console.log(">>",e),this._ws.send(s)}onSendQueued(e){const t=this._waitingForSocket[e];if(t){for(const i of t)i();t.length=0}}}function ef(n,e){try{e?n(e):n()}catch(t){return console.error(t),!1}return!0}(0,eval)(`
|
|
3336
|
-
if(!globalThis[""
|
|
3337
|
-
globalThis[""
|
|
3336
|
+
if(!globalThis["NEEDLE_ENGINE_VERSION"])
|
|
3337
|
+
globalThis["NEEDLE_ENGINE_VERSION"] = "0.0.0";
|
|
3338
3338
|
if(!globalThis[""undefined""])
|
|
3339
3339
|
globalThis[""undefined""] = "unknown";
|
|
3340
|
-
`);const gL="null",qj="undefined",Ml="needle_isActiveInHierarchy",Qh="builtin_components",Rg="needle_editor_guid",Xj=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Yj(n){return typeof n=="string"&&Xj.test(n)}const $n=[];for(let n=0;n<256;++n)$n.push((n+256).toString(16).slice(1));function Jj(n,e=0){return($n[n[e+0]]+$n[n[e+1]]+$n[n[e+2]]+$n[n[e+3]]+"-"+$n[n[e+4]]+$n[n[e+5]]+"-"+$n[n[e+6]]+$n[n[e+7]]+"-"+$n[n[e+8]]+$n[n[e+9]]+"-"+$n[n[e+10]]+$n[n[e+11]]+$n[n[e+12]]+$n[n[e+13]]+$n[n[e+14]]+$n[n[e+15]]).toLowerCase()}function Kj(n){if(!Yj(n))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function Zj(n){n=unescape(encodeURIComponent(n));const e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}const $j="6ba7b810-9dad-11d1-80b4-00c04fd430c8",eW="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function tW(n,e,t){function i(s,r,o,a){var l;if(typeof s=="string"&&(s=Zj(s)),typeof r=="string"&&(r=Kj(r)),((l=r)===null||l===void 0?void 0:l.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+s.length);if(c.set(r),c.set(s,r.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,o){a=a||0;for(let h=0;h<16;++h)o[a+h]=c[h];return o}return Jj(c)}try{i.name=n}catch{}return i.DNS=$j,i.URL=eW,i}function iW(n,e,t,i){switch(n){case 0:return e&t^~e&i;case 1:return e^t^i;case 2:return e&t^e&i^t&i;case 3:return e^t^i}}function mw(n,e){return n<<e|n>>>32-e}function nW(n){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof n=="string"){const o=unescape(encodeURIComponent(n));n=[];for(let a=0;a<o.length;++a)n.push(o.charCodeAt(a))}else Array.isArray(n)||(n=Array.prototype.slice.call(n));n.push(128);const i=n.length/4+2,s=Math.ceil(i/16),r=new Array(s);for(let o=0;o<s;++o){const a=new Uint32Array(16);for(let l=0;l<16;++l)a[l]=n[o*64+l*4]<<24|n[o*64+l*4+1]<<16|n[o*64+l*4+2]<<8|n[o*64+l*4+3];r[o]=a}r[s-1][14]=(n.length-1)*8/Math.pow(2,32),r[s-1][14]=Math.floor(r[s-1][14]),r[s-1][15]=(n.length-1)*8&4294967295;for(let o=0;o<s;++o){const a=new Uint32Array(80);for(let p=0;p<16;++p)a[p]=r[o][p];for(let p=16;p<80;++p)a[p]=mw(a[p-3]^a[p-8]^a[p-14]^a[p-16],1);let l=t[0],c=t[1],h=t[2],d=t[3],f=t[4];for(let p=0;p<80;++p){const g=Math.floor(p/20),m=mw(l,5)+iW(g,c,h,d)+f+e[g]+a[p]>>>0;f=d,d=h,h=mw(c,30)>>>0,c=l,l=m}t[0]=t[0]+l>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+h>>>0,t[3]=t[3]+d>>>0,t[4]=t[4]+f>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const sW=tW("v5",80,nW),lR=sW;sn.registerCallback(to.ContextCreated,n=>{const e=n.context;_L(e),yL(e)});const W0=le("debugcomponents"),cR="eff8ba80-635d-11ec-90d6-0242ac120003";class Us{constructor(e){u(this,"_originalSeed");u(this,"_seed");typeof e=="string"&&(e=Us.hash(e)),this._originalSeed=e,this._seed=e}get seed(){return this._seed}set seed(e){this._seed=e}reset(){this._seed=this._originalSeed}generateUUID(e){if(typeof e=="string")return lR(e,cR);const t=this._seed;return this._seed-=1,lR(t.toString(),cR)}initialize(e){typeof e=="string"?this._seed=Us.hash(e):this._seed=e}static createFromString(e){return new Us(this.hash(e))}static hash(e){let t=0;for(let i=0;i<e.length;i++)t=e.charCodeAt(i)+((t<<5)-t);return t}}var mL=(n=>(n.NewInstanceCreated="new-instance-created",n.InstanceDestroyed="instance-destroyed",n))(mL||{});class AL{constructor(e){u(this,"guid");this.guid=e}}function fb(n,e,t=!0){if(!n)return;const i=n;if(kl(n,t),!e){console.warn("Can not send destroy: No networking connection provided",n.guid);return}if(!e.isConnected){console.warn("Can not send destroy: not connected",n.guid);return}let s=n.guid;if(!s&&i.uuid&&(s=i.uuid),!s){console.warn("Can not send destroy: failed to find guid",n);return}const r=new AL(s);e.send("instance-destroyed",r,tr.Queued)}function vL(n,e){const t=new AL(n);e.send("instance-destroyed",t,tr.Queued)}function yL(n){n.connection.beginListen("instance-destroyed",e=>{W0&&console.log("[Remote] Destroyed",n.scene,e);const t=mA(e.guid,n.scene);t&&kl(t)})}class rW{constructor(e,t,i){u(this,"filename");u(this,"hash");u(this,"size");this.filename=e,this.hash=t,this.size=i}}class oW{constructor(e,t){u(this,"guid");u(this,"originalGuid");u(this,"seed");u(this,"visible");u(this,"hostData");u(this,"dontSave");u(this,"parent");u(this,"position");u(this,"rotation");u(this,"scale");this.originalGuid=e,this.guid=t}}function T1(n,e,t,i){var l;const s=n;if(!s.guid)return console.warn("Can not instantiate: No guid",s),null;if(e.context||(e.context=_t.Current),!e.context)return console.error("Missing network instantiate options / reference to network connection in sync instantiate"),null;const r=e?{...e}:null,{instance:o,seed:a}=aW(s,e);if(o){const c=o;if(c.guid){W0&&console.log("[Local] new instance","gameobject:",o==null?void 0:o.guid);const h=new oW(s.guid,c.guid);h.seed=a,r&&(r.position&&(h.position={x:r.position.x,y:r.position.y,z:r.position.z}),r.rotation&&(h.rotation={x:r.rotation.x,y:r.rotation.y,z:r.rotation.z,w:r.rotation.w}),r.scale&&(h.scale={x:r.scale.x,y:r.scale.y,z:r.scale.z})),h.position||(h.position={x:c.position.x,y:c.position.y,z:c.position.z}),h.rotation||(h.rotation={x:c.quaternion.x,y:c.quaternion.y,z:c.quaternion.z,w:c.quaternion.w}),h.scale||(h.scale={x:c.scale.x,y:c.scale.y,z:c.scale.z}),h.visible=s.visible,r!=null&&r.parent&&(typeof r.parent=="string"?h.parent=r.parent:h.parent=r.parent.guid),h.hostData=t,i===!1&&(h.dontSave=!0),(l=e==null?void 0:e.context)==null||l.connection.send("new-instance-created",h)}else console.warn("Missing guid, can not send new instance event",c)}return o}function pb(){return Math.random()*9999999}function _L(n){n.connection.beginListen("new-instance-created",async e=>{const t=await lW(e.originalGuid,n.scene);if(!t){console.warn("could not find object that was instantiated: "+e.guid);return}const i=new Pa;e.position&&(i.position=new S(e.position.x,e.position.y,e.position.z)),e.rotation&&(i.rotation=new xe(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w)),e.scale&&(i.scale=new S(e.scale.x,e.scale.y,e.scale.z)),i.parent=e.parent,e.seed&&(i.idProvider=new Us(e.seed)),i.visible=e.visible,i.context=n,W0&&n.alias&&console.log("[Remote] instantiate in: "+n.alias);const s=AA(t,i);s&&(e.parent==="scene"&&n.scene.add(s),W0&&console.log("[Remote] new instance","gameobject:",s==null?void 0:s.guid,t))})}function aW(n,e){const t=pb(),i=e??new Pa;i.idProvider=new Us(t);const s=AA(n,i);return{seed:t,instance:s}}const bL={};function xL(n,e){bL[n]=e}async function lW(n,e){const t=bL[n];if(t!=null){const i=await t(n);if(i)return i}return wL(n,e)}function wL(n,e){if(e===null||!n)return null;if(e.guid===n)return e;if(e.children)for(const t of e.children){const i=wL(n,t);if(i)return i}return null}const CL=new Map;function cW(n,e){if(!n)return;if(!e){console.warn("No prototype found",n,n.prototype,n.constructor);return}let t=CL.get(e);t&&t.apply(n)}function hW(n){const e=uW(n.prototype);CL.set(n,e)}function uW(n){return new dW(n)}class dW{constructor(e){u(this,"$symbol");u(this,"extensions");u(this,"descriptors");this.$symbol=Symbol("prototype-extension"),this.extensions=Object.keys(e),this.descriptors=new Array;for(let t=0;t<this.extensions.length;t++){const i=this.extensions[t],s=Object.getOwnPropertyDescriptor(e,i);s&&this.descriptors.push(s)}}apply(e){if(!e[this.$symbol]){e[this.$symbol]=!0;for(let t=0;t<this.extensions.length;t++){const i=this.extensions[t],s=this.descriptors[t];s&&Object.defineProperty(e,i,s)}}}}var dA=(n=>(n.Added="component-added",n.Removing="removing-component",n))(dA||{});const hR=le("debugcomponentevents");class fA{static addComponentLifecylceEventListener(e,t){this.eventListeners.has(e)&&this.eventListeners.set(e,[]);let i=this.eventListeners.get(e);i||(i=[]),i.push(t),this.eventListeners.set(e,i),hR&&console.log("Added event listener for "+e,this.eventListeners)}static removeComponentLifecylceEventListener(e,t){const i=this.eventListeners.get(e);if(!i)return;const s=i.indexOf(t);s<0||i.splice(s,1)}static dispatchComponentLifecycleEvent(e,t){const i=this.eventListeners.get(e);if(hR&&console.log("Dispatching event "+e,i),!!i)for(const s of i)s(t)}}u(fA,"eventListeners",new Map);const Aw=le("debuggetcomponent");function fW(n){return n==null||n.isObject3D?n:n.object&&n.object.isObject3D?n.object:n}function P1(n,e){if(!n||!n.userData.components)return;const t=n.userData.components.indexOf(e);t<0||(fA.dispatchComponentLifecycleEvent(dA.Removing,e),e.gameObject=null,n.userData.components.splice(t,1))}function gb(n,e){const t=Vf(n,e);if(t)return t;const i=new e;return Iu(n,i)}const SL=new Us("addComponentIdProvider");function Iu(n,e,t=!0){n.userData||(n.userData={}),n.userData.components||(n.userData.components=[]),n.userData.components.push(e),e.gameObject=n,(e.guid===void 0||e.guid==="invalid")&&(e.guid=SL.generateUUID()),Ab(n),xb(e);try{t&&e.__internalAwake&&(kg(n),e.__internalAwake()),fA.dispatchComponentLifecycleEvent(dA.Added,e)}catch(i){console.error(i)}return e}function R1(n,e){if(e.gameObject===n)return e;if(e.gameObject&&e.gameObject.userData.components){const t=e.gameObject.userData.components.indexOf(e);e.gameObject.userData.components.splice(t,1)}if(!n.userData.components)n.userData.components=[];else if(n.userData.components.includes(e))return e;return n.userData.components.push(e),e.gameObject=n,(e.guid===void 0||e.guid==="invalid")&&(e.guid=SL.generateUUID()),xb(e),e}function EL(n){if(n.gameObject&&n.gameObject.userData.components){const e=n.gameObject.userData.components.indexOf(n);n.gameObject.userData.components.splice(e,1)}n.__internalDisable&&n.__internalDisable(),n.onDestroy&&n.onDestroy(),ml(n,n.context??_t.Current),n.__internalDestroy(),n.gameObject=null}let uR=!1;function IL(n,e,t){var i;if(n!=null){if(!n.isObject3D){console.error("Object is not object3D");return}if(!((i=n==null?void 0:n.userData)!=null&&i.components))return null;if(typeof e=="string"&&(uR||(uR=!0,console.warn(`Accessing components by name is not supported.
|
|
3340
|
+
`);const gL=NEEDLE_ENGINE_VERSION,qj="undefined",Ml="needle_isActiveInHierarchy",Qh="builtin_components",Rg="needle_editor_guid",Xj=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Yj(n){return typeof n=="string"&&Xj.test(n)}const $n=[];for(let n=0;n<256;++n)$n.push((n+256).toString(16).slice(1));function Jj(n,e=0){return($n[n[e+0]]+$n[n[e+1]]+$n[n[e+2]]+$n[n[e+3]]+"-"+$n[n[e+4]]+$n[n[e+5]]+"-"+$n[n[e+6]]+$n[n[e+7]]+"-"+$n[n[e+8]]+$n[n[e+9]]+"-"+$n[n[e+10]]+$n[n[e+11]]+$n[n[e+12]]+$n[n[e+13]]+$n[n[e+14]]+$n[n[e+15]]).toLowerCase()}function Kj(n){if(!Yj(n))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function Zj(n){n=unescape(encodeURIComponent(n));const e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}const $j="6ba7b810-9dad-11d1-80b4-00c04fd430c8",eW="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function tW(n,e,t){function i(s,r,o,a){var l;if(typeof s=="string"&&(s=Zj(s)),typeof r=="string"&&(r=Kj(r)),((l=r)===null||l===void 0?void 0:l.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+s.length);if(c.set(r),c.set(s,r.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,o){a=a||0;for(let h=0;h<16;++h)o[a+h]=c[h];return o}return Jj(c)}try{i.name=n}catch{}return i.DNS=$j,i.URL=eW,i}function iW(n,e,t,i){switch(n){case 0:return e&t^~e&i;case 1:return e^t^i;case 2:return e&t^e&i^t&i;case 3:return e^t^i}}function mw(n,e){return n<<e|n>>>32-e}function nW(n){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof n=="string"){const o=unescape(encodeURIComponent(n));n=[];for(let a=0;a<o.length;++a)n.push(o.charCodeAt(a))}else Array.isArray(n)||(n=Array.prototype.slice.call(n));n.push(128);const i=n.length/4+2,s=Math.ceil(i/16),r=new Array(s);for(let o=0;o<s;++o){const a=new Uint32Array(16);for(let l=0;l<16;++l)a[l]=n[o*64+l*4]<<24|n[o*64+l*4+1]<<16|n[o*64+l*4+2]<<8|n[o*64+l*4+3];r[o]=a}r[s-1][14]=(n.length-1)*8/Math.pow(2,32),r[s-1][14]=Math.floor(r[s-1][14]),r[s-1][15]=(n.length-1)*8&4294967295;for(let o=0;o<s;++o){const a=new Uint32Array(80);for(let p=0;p<16;++p)a[p]=r[o][p];for(let p=16;p<80;++p)a[p]=mw(a[p-3]^a[p-8]^a[p-14]^a[p-16],1);let l=t[0],c=t[1],h=t[2],d=t[3],f=t[4];for(let p=0;p<80;++p){const g=Math.floor(p/20),m=mw(l,5)+iW(g,c,h,d)+f+e[g]+a[p]>>>0;f=d,d=h,h=mw(c,30)>>>0,c=l,l=m}t[0]=t[0]+l>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+h>>>0,t[3]=t[3]+d>>>0,t[4]=t[4]+f>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const sW=tW("v5",80,nW),lR=sW;sn.registerCallback(to.ContextCreated,n=>{const e=n.context;_L(e),yL(e)});const W0=le("debugcomponents"),cR="eff8ba80-635d-11ec-90d6-0242ac120003";class Us{constructor(e){u(this,"_originalSeed");u(this,"_seed");typeof e=="string"&&(e=Us.hash(e)),this._originalSeed=e,this._seed=e}get seed(){return this._seed}set seed(e){this._seed=e}reset(){this._seed=this._originalSeed}generateUUID(e){if(typeof e=="string")return lR(e,cR);const t=this._seed;return this._seed-=1,lR(t.toString(),cR)}initialize(e){typeof e=="string"?this._seed=Us.hash(e):this._seed=e}static createFromString(e){return new Us(this.hash(e))}static hash(e){let t=0;for(let i=0;i<e.length;i++)t=e.charCodeAt(i)+((t<<5)-t);return t}}var mL=(n=>(n.NewInstanceCreated="new-instance-created",n.InstanceDestroyed="instance-destroyed",n))(mL||{});class AL{constructor(e){u(this,"guid");this.guid=e}}function fb(n,e,t=!0){if(!n)return;const i=n;if(kl(n,t),!e){console.warn("Can not send destroy: No networking connection provided",n.guid);return}if(!e.isConnected){console.warn("Can not send destroy: not connected",n.guid);return}let s=n.guid;if(!s&&i.uuid&&(s=i.uuid),!s){console.warn("Can not send destroy: failed to find guid",n);return}const r=new AL(s);e.send("instance-destroyed",r,tr.Queued)}function vL(n,e){const t=new AL(n);e.send("instance-destroyed",t,tr.Queued)}function yL(n){n.connection.beginListen("instance-destroyed",e=>{W0&&console.log("[Remote] Destroyed",n.scene,e);const t=mA(e.guid,n.scene);t&&kl(t)})}class rW{constructor(e,t,i){u(this,"filename");u(this,"hash");u(this,"size");this.filename=e,this.hash=t,this.size=i}}class oW{constructor(e,t){u(this,"guid");u(this,"originalGuid");u(this,"seed");u(this,"visible");u(this,"hostData");u(this,"dontSave");u(this,"parent");u(this,"position");u(this,"rotation");u(this,"scale");this.originalGuid=e,this.guid=t}}function T1(n,e,t,i){var l;const s=n;if(!s.guid)return console.warn("Can not instantiate: No guid",s),null;if(e.context||(e.context=_t.Current),!e.context)return console.error("Missing network instantiate options / reference to network connection in sync instantiate"),null;const r=e?{...e}:null,{instance:o,seed:a}=aW(s,e);if(o){const c=o;if(c.guid){W0&&console.log("[Local] new instance","gameobject:",o==null?void 0:o.guid);const h=new oW(s.guid,c.guid);h.seed=a,r&&(r.position&&(h.position={x:r.position.x,y:r.position.y,z:r.position.z}),r.rotation&&(h.rotation={x:r.rotation.x,y:r.rotation.y,z:r.rotation.z,w:r.rotation.w}),r.scale&&(h.scale={x:r.scale.x,y:r.scale.y,z:r.scale.z})),h.position||(h.position={x:c.position.x,y:c.position.y,z:c.position.z}),h.rotation||(h.rotation={x:c.quaternion.x,y:c.quaternion.y,z:c.quaternion.z,w:c.quaternion.w}),h.scale||(h.scale={x:c.scale.x,y:c.scale.y,z:c.scale.z}),h.visible=s.visible,r!=null&&r.parent&&(typeof r.parent=="string"?h.parent=r.parent:h.parent=r.parent.guid),h.hostData=t,i===!1&&(h.dontSave=!0),(l=e==null?void 0:e.context)==null||l.connection.send("new-instance-created",h)}else console.warn("Missing guid, can not send new instance event",c)}return o}function pb(){return Math.random()*9999999}function _L(n){n.connection.beginListen("new-instance-created",async e=>{const t=await lW(e.originalGuid,n.scene);if(!t){console.warn("could not find object that was instantiated: "+e.guid);return}const i=new Pa;e.position&&(i.position=new S(e.position.x,e.position.y,e.position.z)),e.rotation&&(i.rotation=new xe(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w)),e.scale&&(i.scale=new S(e.scale.x,e.scale.y,e.scale.z)),i.parent=e.parent,e.seed&&(i.idProvider=new Us(e.seed)),i.visible=e.visible,i.context=n,W0&&n.alias&&console.log("[Remote] instantiate in: "+n.alias);const s=AA(t,i);s&&(e.parent==="scene"&&n.scene.add(s),W0&&console.log("[Remote] new instance","gameobject:",s==null?void 0:s.guid,t))})}function aW(n,e){const t=pb(),i=e??new Pa;i.idProvider=new Us(t);const s=AA(n,i);return{seed:t,instance:s}}const bL={};function xL(n,e){bL[n]=e}async function lW(n,e){const t=bL[n];if(t!=null){const i=await t(n);if(i)return i}return wL(n,e)}function wL(n,e){if(e===null||!n)return null;if(e.guid===n)return e;if(e.children)for(const t of e.children){const i=wL(n,t);if(i)return i}return null}const CL=new Map;function cW(n,e){if(!n)return;if(!e){console.warn("No prototype found",n,n.prototype,n.constructor);return}let t=CL.get(e);t&&t.apply(n)}function hW(n){const e=uW(n.prototype);CL.set(n,e)}function uW(n){return new dW(n)}class dW{constructor(e){u(this,"$symbol");u(this,"extensions");u(this,"descriptors");this.$symbol=Symbol("prototype-extension"),this.extensions=Object.keys(e),this.descriptors=new Array;for(let t=0;t<this.extensions.length;t++){const i=this.extensions[t],s=Object.getOwnPropertyDescriptor(e,i);s&&this.descriptors.push(s)}}apply(e){if(!e[this.$symbol]){e[this.$symbol]=!0;for(let t=0;t<this.extensions.length;t++){const i=this.extensions[t],s=this.descriptors[t];s&&Object.defineProperty(e,i,s)}}}}var dA=(n=>(n.Added="component-added",n.Removing="removing-component",n))(dA||{});const hR=le("debugcomponentevents");class fA{static addComponentLifecylceEventListener(e,t){this.eventListeners.has(e)&&this.eventListeners.set(e,[]);let i=this.eventListeners.get(e);i||(i=[]),i.push(t),this.eventListeners.set(e,i),hR&&console.log("Added event listener for "+e,this.eventListeners)}static removeComponentLifecylceEventListener(e,t){const i=this.eventListeners.get(e);if(!i)return;const s=i.indexOf(t);s<0||i.splice(s,1)}static dispatchComponentLifecycleEvent(e,t){const i=this.eventListeners.get(e);if(hR&&console.log("Dispatching event "+e,i),!!i)for(const s of i)s(t)}}u(fA,"eventListeners",new Map);const Aw=le("debuggetcomponent");function fW(n){return n==null||n.isObject3D?n:n.object&&n.object.isObject3D?n.object:n}function P1(n,e){if(!n||!n.userData.components)return;const t=n.userData.components.indexOf(e);t<0||(fA.dispatchComponentLifecycleEvent(dA.Removing,e),e.gameObject=null,n.userData.components.splice(t,1))}function gb(n,e){const t=Vf(n,e);if(t)return t;const i=new e;return Iu(n,i)}const SL=new Us("addComponentIdProvider");function Iu(n,e,t=!0){n.userData||(n.userData={}),n.userData.components||(n.userData.components=[]),n.userData.components.push(e),e.gameObject=n,(e.guid===void 0||e.guid==="invalid")&&(e.guid=SL.generateUUID()),Ab(n),xb(e);try{t&&e.__internalAwake&&(kg(n),e.__internalAwake()),fA.dispatchComponentLifecycleEvent(dA.Added,e)}catch(i){console.error(i)}return e}function R1(n,e){if(e.gameObject===n)return e;if(e.gameObject&&e.gameObject.userData.components){const t=e.gameObject.userData.components.indexOf(e);e.gameObject.userData.components.splice(t,1)}if(!n.userData.components)n.userData.components=[];else if(n.userData.components.includes(e))return e;return n.userData.components.push(e),e.gameObject=n,(e.guid===void 0||e.guid==="invalid")&&(e.guid=SL.generateUUID()),xb(e),e}function EL(n){if(n.gameObject&&n.gameObject.userData.components){const e=n.gameObject.userData.components.indexOf(n);n.gameObject.userData.components.splice(e,1)}n.__internalDisable&&n.__internalDisable(),n.onDestroy&&n.onDestroy(),ml(n,n.context??_t.Current),n.__internalDestroy(),n.gameObject=null}let uR=!1;function IL(n,e,t){var i;if(n!=null){if(!n.isObject3D){console.error("Object is not object3D");return}if(!((i=n==null?void 0:n.userData)!=null&&i.components))return null;if(typeof e=="string"&&(uR||(uR=!0,console.warn(`Accessing components by name is not supported.
|
|
3341
3341
|
Please use the component type instead. This may keep working in local development but it will fail when bundling your application.
|
|
3342
3342
|
|
|
3343
3343
|
You can import other modules your main module to get access to types
|