/
geckos.io-client.1.1.0.min.js
1 lines (1 loc) 路 14.5 KB
/
geckos.io-client.1.1.0.min.js
1
var geckos=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.EVENTS={SEND_OVER_DATA_CHANNEL:"sendOverDataChannel",RECEIVED_FROM_DATA_CHANNEL:"receiveFromDataChannel",DISCONNECTED:"disconnected",DISCONNECT:"disconnect",CONNECTION:"connection",CONNECT:"connect",ERROR:"error",DATA_CHANNEL_IS_OPEN:"dataChannelIsOpen",SEND_TO_ROOM:"sendToRoom",SEND_TO_ALL:"sendToAll",FORWARD_MESSAGE:"forwardMessage",BROADCAST_MESSAGE:"broadcastMessage",RAW_MESSAGE:"rawMessage"};t.ERRORS={BROWSER_NOT_SUPPORTED:"BROWSER_NOT_SUPPORTED",COULD_NOT_PARSE_MESSAGE:"COULD_NOT_PARSE_MESSAGE"}},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=r(n(5)),i=function(){function e(){this.eventEmitter=new o.default}return e.prototype.emit=function(e,t,n){void 0===n&&(n={}),this.eventEmitter.emit(e,t,n)},e.prototype.on=function(e,t){return this.eventEmitter.on(e,function(e,n){t(e,n)})},e.prototype.removeListener=function(e,t,n){void 0===n&&(n=void 0),this.eventEmitter.removeListener(e,t,n)},e}();t.Bridge=i;var c=new i;t.default=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(9);t.isRawMessage=function(e){return"string"==typeof e||e instanceof ArrayBuffer||e instanceof r.ArrayBufferView};t.isObject=function(e){return"object"==typeof e};t.isJSONString=function(e){try{return"string"==typeof e&&(JSON.parse(e),!0)}catch(e){return!1}}},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=r(n(4));t.default=o.default},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function c(e){try{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(c,a)}s((r=r.apply(e,t||[])).next())})},o=this&&this.__generator||function(e,t){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=(o=c.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=t.call(e,c)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var c=i(n(1)),a=n(0),s=i(n(6)),u=i(n(7)),l=function(){function e(e,t,n){this.url=e+":"+t,this.connectionsManager=new u.default(this.url,n)}return e.prototype.onconnectionstatechange=function(){var e=this.peerConnection.localPeerConnection;e.onconnectionstatechange=function(){"disconnected"!==e.connectionState&&"closed"!==e.connectionState||c.default.emit(a.EVENTS.DISCONNECTED)}},Object.defineProperty(e.prototype,"id",{get:function(){return this.peerConnection.id},enumerable:!0,configurable:!0}),e.prototype.emit=function(e,t){void 0===t&&(t=null),this.connectionsManager.emit(e,t)},Object.defineProperty(e.prototype,"raw",{get:function(){var e=this;return{emit:function(t){return e.emit(a.EVENTS.RAW_MESSAGE,t)}}},enumerable:!0,configurable:!0}),e.prototype.onRaw=function(e){c.default.on(a.EVENTS.RAW_MESSAGE,function(t){!function(t){e(t)}(t)})},e.prototype.onConnect=function(e){return r(this,void 0,void 0,function(){var t;return o(this,function(n){switch(n.label){case 0:return c.default.on(a.EVENTS.DATA_CHANNEL_IS_OPEN,function(){e()}),this.peerConnection=new s.default,[4,this.peerConnection.connect(this.connectionsManager)];case 1:return(t=n.sent())?e(t):this.onconnectionstatechange(),[2]}})})},e.prototype.onDisconnect=function(e){c.default.on(a.EVENTS.DISCONNECTED,e)},e.prototype.on=function(e,t){c.default.on(e,function(e){t(e)})},e}();t.ClientChannel=l;t.default=function(e){void 0===e&&(e={});var t=e.url,n=void 0===t?location.protocol+"//"+location.hostname:t,r=e.port,o=void 0===r?9208:r,i=e.label;return new l(n,o,void 0===i?"geckos.io":i)}},function(e,t,n){"use strict";var r=Object.prototype.hasOwnProperty,o="~";function i(){}function c(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function a(e,t,n,r,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new c(n,r||e,i),s=o?o+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],a]:e._events[s].push(a):(e._events[s]=a,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new i:delete e._events[t]}function u(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(o=!1)),u.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)r.call(e,t)&&n.push(o?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},u.prototype.listeners=function(e){var t=o?o+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,i=n.length,c=new Array(i);r<i;r++)c[r]=n[r].fn;return c},u.prototype.listenerCount=function(e){var t=o?o+e:e,n=this._events[t];return n?n.fn?1:n.length:0},u.prototype.emit=function(e,t,n,r,i,c){var a=o?o+e:e;if(!this._events[a])return!1;var s,u,l=this._events[a],f=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),f){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,n),!0;case 4:return l.fn.call(l.context,t,n,r),!0;case 5:return l.fn.call(l.context,t,n,r,i),!0;case 6:return l.fn.call(l.context,t,n,r,i,c),!0}for(u=1,s=new Array(f-1);u<f;u++)s[u-1]=arguments[u];l.fn.apply(l.context,s)}else{var h,p=l.length;for(u=0;u<p;u++)switch(l[u].once&&this.removeListener(e,l[u].fn,void 0,!0),f){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,t);break;case 3:l[u].fn.call(l[u].context,t,n);break;case 4:l[u].fn.call(l[u].context,t,n,r);break;default:if(!s)for(h=1,s=new Array(f-1);h<f;h++)s[h-1]=arguments[h];l[u].fn.apply(l[u].context,s)}}return!0},u.prototype.on=function(e,t,n){return a(this,e,t,n,!1)},u.prototype.once=function(e,t,n){return a(this,e,t,n,!0)},u.prototype.removeListener=function(e,t,n,r){var i=o?o+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var c=this._events[i];if(c.fn)c.fn!==t||r&&!c.once||n&&c.context!==n||s(this,i);else{for(var a=0,u=[],l=c.length;a<l;a++)(c[a].fn!==t||r&&!c[a].once||n&&c[a].context!==n)&&u.push(c[a]);u.length?this._events[i]=1===u.length?u[0]:u:s(this,i)}return this},u.prototype.removeAllListeners=function(e){var t;return e?(t=o?o+e:e,this._events[t]&&s(this,t)):(this._events=new i,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=o,u.EventEmitter=u,e.exports=u},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function c(e){try{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(c,a)}s((r=r.apply(e,t||[])).next())})},o=this&&this.__generator||function(e,t){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=(o=c.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=t.call(e,c)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(t,"__esModule",{value:!0});var i=n(0),c=function(){function e(){}return e.prototype.connect=function(e){return r(this,void 0,void 0,function(){var t,n,r,c,a;return o(this,function(o){switch(o.label){case 0:return RTCPeerConnection||webkitRTCPeerConnection||mozRTCPeerConnection?[4,e.connect()]:[3,2];case 1:return t=o.sent(),n=t.localPeerConnection,r=t.dataChannel,c=t.id,this.localPeerConnection=n,this.dataChannel=r,this.id=c,[2,null];case 2:return a=new Error(i.ERRORS.BROWSER_NOT_SUPPORTED),console.error(a.message),[2,a]}})})},e}();t.default=c},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function c(e){try{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(c,a)}s((r=r.apply(e,t||[])).next())})},o=this&&this.__generator||function(e,t){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=(o=c.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=t.call(e,c)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var c=i(n(1)),a=n(0),s=i(n(8)),u=i(n(10)),l=function(){function e(e,t){var n=this;this.url=e,this.label=t,this.onDataChannel=function(e){var t=e.channel;t.label===n.label&&(n.dataChannel=t,n.dataChannel.onmessage=function(e){var t=s.default(e),n=t.key,r=t.data;c.default.emit(n,r)},c.default.emit(a.EVENTS.DATA_CHANNEL_IS_OPEN))}}return e.prototype.emit=function(e,t){void 0===t&&(t=null),u.default(this.dataChannel,e,t)},e.prototype.connect=function(){return r(this,void 0,void 0,function(){var e,t,n,r,i,c,a,s,u,l,f,h,p;return o(this,function(o){switch(o.label){case 0:e=this.url+"/.wrtc/v1",o.label=1;case 1:return o.trys.push([1,4,,5]),[4,fetch(e+"/connections",{method:"POST",headers:{"Content-Type":"application/json"}})];case 2:return t=o.sent(),n=this,[4,t.json()];case 3:return n.remotePeerConnection=o.sent(),[3,5];case 4:return r=o.sent(),console.error(r.message),[3,5];case 5:i=this.remotePeerConnection,c=i.id,a=i.localDescription,s={},u=RTCPeerConnection||webkitRTCPeerConnection||mozRTCPeerConnection,this.localPeerConnection=new u(s),o.label=6;case 6:return o.trys.push([6,14,,15]),[4,this.localPeerConnection.setRemoteDescription(a)];case 7:return o.sent(),this.localPeerConnection.addEventListener("datachannel",this.onDataChannel),[4,this.localPeerConnection.createAnswer()];case 8:return l=o.sent(),f=new RTCSessionDescription({type:"answer",sdp:l.sdp}),[4,this.localPeerConnection.setLocalDescription(f)];case 9:o.sent(),o.label=10;case 10:return o.trys.push([10,12,,13]),[4,fetch(e+"/connections/"+c+"/remote-description",{method:"POST",body:JSON.stringify(this.localPeerConnection.localDescription),headers:{"Content-Type":"application/json"}})];case 11:return o.sent(),[3,13];case 12:return h=o.sent(),console.error(h.message),[3,13];case 13:return[2,{localPeerConnection:this.localPeerConnection,dataChannel:this.dataChannel,id:c}];case 14:throw p=o.sent(),console.error(p.message),this.localPeerConnection.close(),p;case 15:return[2]}})})},e}();t.default=l},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),o=n(2);t.default=function(e){var t,n,i=e.data,c=o.isJSONString(i);return!c&&o.isRawMessage(i)?(t=r.EVENTS.RAW_MESSAGE,n=i):c?n=(i=JSON.parse(i))[t=Object.keys(i)[0]]:(t="error",n=new Error(r.ERRORS.COULD_NOT_PARSE_MESSAGE)),{key:t,data:n}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array)).constructor;t.ArrayBufferView=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),o=n(0);t.default=function(e,t,n){var i;if(void 0===n&&(n=null),"open"===e.readyState)try{t===o.EVENTS.RAW_MESSAGE&&null!==n&&r.isRawMessage(n)?e.send(n):e.send(JSON.stringify(((i={})[t]=n,i)))}catch(e){console.error("Error => dataChannel.send: ",e.message)}}}]).default;