清空
This commit is contained in:
1 parent
7c2ab0b7ad
commit
cff33ad7d1
6370 files changed
+378844
-82245
No files matched your search
+29
@@ -0,0 +1,29 @@
|
||||
# [2.5.0](https://github.com/socketio/socket.io-client/compare/2.4.0...2.5.0) (2022-06-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* ensure buffered events are sent in order ([991eb0b](https://github.com/Automattic/socket.io-client/commit/991eb0b0289bbbf680099e6d42b302beee7568b8))
|
||||
|
||||
|
||||
|
||||
# [2.4.0](https://github.com/socketio/socket.io-client/compare/2.3.1...2.4.0) (2021-01-04)
|
||||
|
||||
The minor bump is matching the bump of the server, but there is no new feature in this release.
|
||||
|
||||
|
||||
## [2.3.1](https://github.com/socketio/socket.io-client/compare/2.3.0...2.3.1) (2020-09-30)
|
||||
|
||||
The `debug` dependency has been reverted to `~3.1.0`, as the newer versions contains ES6 syntax which breaks in IE
|
||||
browsers.
|
||||
|
||||
Please note that this only applied to users that bundle the Socket.IO client in their application, with webpack for
|
||||
example, as the "official" bundles (in the dist/ folder) were already transpiled with babel.
|
||||
|
||||
For webpack users, you can also take a look at the [webpack-remove-debug](https://github.com/johngodley/webpack-remove-debug)
|
||||
plugin.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix reconnection after opening socket asynchronously ([#1253](https://github.com/socketio/socket.io-client/issues/1253)) ([050108b](https://github.com/Automattic/socket.io-client/commit/050108b2281effda086b197cf174ee2e8e1aad79))
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Guillermo Rauch
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
|
||||
# socket.io-client
|
||||
|
||||
[](https://github.com/socketio/socket.io-client/actions)
|
||||
[](https://david-dm.org/socketio/socket.io-client)
|
||||
[](https://david-dm.org/socketio/socket.io-client#info=devDependencies)
|
||||
[](https://www.npmjs.com/package/socket.io-client)
|
||||

|
||||
[](http://slack.socket.io)
|
||||
|
||||
[](https://saucelabs.com/u/socket)
|
||||
|
||||
## How to use
|
||||
|
||||
A standalone build of `socket.io-client` is exposed automatically by the
|
||||
socket.io server as `/socket.io/socket.io.js`. Alternatively you can
|
||||
serve the file `socket.io.js` found in the `dist` folder or include it via [CDN](https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js).
|
||||
|
||||
```html
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
var socket = io();
|
||||
socket.on('connect', function(){});
|
||||
socket.on('event', function(data){});
|
||||
socket.on('disconnect', function(){});
|
||||
</script>
|
||||
```
|
||||
|
||||
```js
|
||||
// with ES6 import
|
||||
import io from 'socket.io-client';
|
||||
|
||||
const socket = io();
|
||||
```
|
||||
|
||||
A slim build (without `JSON3`, a JSON polyfill for IE6/IE7, and `debug`) is also available: `socket.io.slim.js`.
|
||||
|
||||
Socket.IO is compatible with [browserify](http://browserify.org/) and [webpack](https://webpack.js.org/) (see example [there](https://github.com/socketio/socket.io/tree/2.0.3/examples/webpack-build)).
|
||||
|
||||
### Node.JS (server-side usage)
|
||||
|
||||
Add `socket.io-client` to your `package.json` and then:
|
||||
|
||||
```js
|
||||
var socket = require('socket.io-client')('http://localhost:3000');
|
||||
socket.on('connect', function(){});
|
||||
socket.on('event', function(data){});
|
||||
socket.on('disconnect', function(){});
|
||||
```
|
||||
|
||||
## Debug / logging
|
||||
|
||||
In order to see all the client debug output, run the following command on the browser console – including the desired scope – and reload your app page:
|
||||
|
||||
```
|
||||
localStorage.debug = '*';
|
||||
```
|
||||
|
||||
And then, filter by the scopes you're interested in. See also: https://socket.io/docs/logging-and-debugging/
|
||||
|
||||
## API
|
||||
|
||||
See [API](/docs/API.md)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](/LICENSE)
|
||||
+6667
File diff suppressed because it is too large.
Load diff
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 45a18098513ff5577057","webpack:///./lib/index.js","webpack:///./lib/url.js","webpack:///./~/parseuri/index.js","webpack:///./~/debug/src/browser.js","webpack:///./~/process/browser.js","webpack:///./~/debug/src/debug.js","webpack:///./~/ms/index.js","webpack:///./~/socket.io-parser/index.js","webpack:///./~/component-emitter/index.js","webpack:///./~/socket.io-parser/binary.js","webpack:///./~/isarray/index.js","webpack:///./~/socket.io-parser/is-buffer.js","webpack:///./lib/manager.js","webpack:///./~/engine.io-client/lib/index.js","webpack:///./~/engine.io-client/lib/socket.js","webpack:///./~/engine.io-client/lib/transports/index.js","webpack:///./~/engine.io-client/lib/xmlhttprequest.js","webpack:///./~/has-cors/index.js","webpack:///./~/engine.io-client/lib/globalThis.browser.js","webpack:///./~/engine.io-client/lib/transports/polling-xhr.js","webpack:///./~/engine.io-client/lib/transports/polling.js","webpack:///./~/engine.io-client/lib/transport.js","webpack:///./~/engine.io-parser/lib/browser.js","webpack:///./~/engine.io-parser/lib/keys.js","webpack:///./~/has-binary2/index.js","webpack:///./~/arraybuffer.slice/index.js","webpack:///./~/after/index.js","webpack:///./~/engine.io-parser/lib/utf8.js","webpack:///./~/engine.io-parser/~/base64-arraybuffer/lib/base64-arraybuffer.js","webpack:///./~/blob/index.js","webpack:///./~/parseqs/index.js","webpack:///./~/component-inherit/index.js","webpack:///./~/yeast/index.js","webpack:///./~/engine.io-client/lib/transports/polling-jsonp.js","webpack:///./~/engine.io-client/lib/transports/websocket.js","webpack:///ws (ignored)","webpack:///./~/indexof/index.js","webpack:///./lib/socket.js","webpack:///./~/to-array/index.js","webpack:///./lib/on.js","webpack:///./~/component-bind/index.js","webpack:///./~/backo2/index.js"],"names":["exports","module","require","log","formatArgs","save","load","useColors","storage","chrome","local","localstorage","colors","window","process","type","navigator","userAgent","toLowerCase","match","document","documentElement","style","WebkitAppearance","console","firebug","exception","table","parseInt","RegExp","$1","formatters","j","v","JSON","stringify","err","message","args","namespace","humanize","diff","c","color","splice","index","lastC","replace","Function","prototype","apply","call","arguments","namespaces","removeItem","debug","e","r","env","DEBUG","enable","localStorage","createDebug","coerce","disable","enabled","instances","names","skips","selectColor","hash","i","charCodeAt","Math","abs","length","prevTime","self","curr","Date","ms","prev","Array","unshift","format","formatter","val","logFn","bind","destroy","init","push","indexOf","split","len","substr","instance","name","test","Error","stack"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;ACrCA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,gCAA+B;AAC/B,gCAA+B;AAC/B;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA,IAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA,YAAW,OAAO;AAClB;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;;;;;;;AC5FA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA,YAAW,OAAO;AAClB,YAAW,OAAO;AAClB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,QAAO;AACP;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,QAAO;AACP;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAK;AACL;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;;;;;;AC1EA;AACA;AACA;AACA;AACA;AACA;;AAEA,0GAAyG,IAAI,GAAG,IAAI,SAAS,IAAI;;AAEjI;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,yEAAwE;AACxE;;AAEA;AACA,iBAAgB;AAChB;;AAEA;AACA;AACA;;AAEA;AACA;AACA,yEAAwE;AACxE,mFAAkF;AAClF;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA,oBAAmB,IAAI;AACvB;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAK;;AAEL;AACA;;;;;;;;;;;ACnEA;;;;;;AAMAA,WAAUC,OAAOD,OAAP,GAAiB,mBAAAE,CAAQ,CAAR,CAA3B;AACAF,SAAQG,GAAR,GAAcA,GAAd;AACAH,SAAQI,UAAR,GAAqBA,UAArB;AACAJ,SAAQK,IAAR,GAAeA,IAAf;AACAL,SAAQM,IAAR,GAAeA,IAAf;AACAN,SAAQO,SAAR,GAAoBA,SAApB;AACAP,SAAQQ,OAAR,GAAkB,eAAe,OAAOC,MAAtB,IACA,eAAe,OAAOA,OAAOD,OAD7B,GAEEC,OAAOD,OAAP,CAAeE,KAFjB,GAGEC,cAHpB;;AAKA;;;;AAIAX,SAAQY,MAAR,GAAiB,CACf,SADe,EACJ,SADI,EACO,SADP,EACkB,SADlB,EAC6B,SAD7B,EACwC,SADxC,EACmD,SADnD,EAEf,SAFe,EAEJ,SAFI,EAEO,SAFP,EAEkB,SAFlB,EAE6B,SAF7B,EAEwC,SAFxC,EAEmD,SAFnD,EAGf,SAHe,EAGJ,SAHI,EAGO,SAHP,EAGkB,SAHlB,EAG6B,SAH7B,EAGwC,SAHxC,EAGmD,SAHnD,EAIf,SAJe,EAIJ,SAJI,EAIO,SAJP,EAIkB,SAJlB,EAI6B,SAJ7B,EAIwC,SAJxC,EAImD,SAJnD,EAKf,SALe,EAKJ,SALI,EAKO,SALP,EAKkB,SALlB,EAK6B,SAL7B,EAKwC,SALxC,EAKmD,SALnD,EAMf,SANe,EAMJ,SANI,EALine truncated
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/*!
|
||||
* Socket.IO v2.5.0
|
||||
* (c) 2014-2021 Guillermo Rauch
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.io=e():t.io=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(t,e){"object"==typeof t&&(e=t,t=void 0),e=e||{};var n,r=o(t),i=r.source,p=r.id,u=r.path,h=c[p]&&u in c[p].nsps,f=e.forceNew||e["force new connection"]||!1===e.multiplex||h;return f?(a("ignoring socket cache for %s",i),n=s(i,e)):(c[p]||(a("new io instance for %s",i),c[p]=s(i,e)),n=c[p]),r.query&&!e.query&&(e.query=r.query),n.socket(r.path,e)}var o=n(1),i=n(7),s=n(12),a=n(3)("socket.io-client");t.exports=e=r;var c=e.managers={};e.protocol=i.protocol,e.connect=r,e.Manager=n(12),e.Socket=n(37)},function(t,e,n){function r(t,e){var n=t;e=e||"undefined"!=typeof location&&location,null==t&&(t=e.protocol+"//"+e.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?e.protocol+t:e.host+t),/^(https?|wss?):\/\//.test(t)||(i("protocol-less url %s",t),t="undefined"!=typeof e?e.protocol+"//"+t:"https://"+t),i("parse %s",t),n=o(t)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";var r=n.host.indexOf(":")!==-1,s=r?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+s+":"+n.port,n.href=n.protocol+"://"+s+(e&&e.port===n.port?"":":"+n.port),n}var o=n(2),i=n(3)("socket.io-client:url");t.exports=r},function(t,e){function n(t,e){var n=/\/{2,9}/g,r=e.replace(n,"/").split("/");return"/"!=e.substr(0,1)&&0!==e.length||r.splice(0,1),"/"==e.substr(e.length-1,1)&&r.splice(r.length-1,1),r}function r(t,e){var n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(t,e,r){e&&(n[e]=r)}),n}var o=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,i=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];t.exports=function(t){var e=t,s=t.indexOf("["),a=t.indexOf("]");s!=-1&&a!=-1&&(t=t.substring(0,s)+t.substring(s,a).replace(/:/g,";")+t.substring(a,t.length));for(var c=o.exec(t||""),p={},u=14;u--;)p[i[u]]=c[u]||"";return s!=-1&&a!=-1&&(p.source=e,p.host=p.host.substring(1,p.host.length-1).replace(/;/g,":"),p.authority=p.authority.replace("[","").replace("]","").replace(/;/g,":"),p.ipv6uri=!0),p.pathNames=n(p,p.path),p.queryKey=r(p,p.query),p}},function(t,e,n){(function(r){"use strict";function o(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function i(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),n){var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var o=0,i=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&(o++,"%c"===t&&(i=o))}),t.splice(i,0,r)}}function s(){return"object"===("undefined"==typeof console?"undefined":u(console))&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function a(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(n){}}function c(){var t;try{t=e.storage.debug}catch(n){}return!t&&"undefined"!=typeof r&&"env"in r&&(t=r.env.DEBUG),t}function p(){try{return window.localStorage}catch(t){}}var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};e=t.exports=n(5),e.log=s,e.formatArgs=i,e.save=a,e.load=c,e.useColors=o,e.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:p(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#Line truncated
|
||||
this.transport.removeAllListeners(),this.readyState="closed",this.id=null,this.emit("close",t,e),n.writeBuffer=[],n.prevBufferLen=0}},r.prototype.filterUpgrades=function(t){for(var e=[],n=0,r=t.length;n<r;n++)~c(this.transports,t[n])&&e.push(t[n]);return e}},function(t,e,n){function r(t){var e,n=!1,r=!1,a=!1!==t.jsonp;if("undefined"!=typeof location){var c="https:"===location.protocol,p=location.port;p||(p=c?443:80),n=t.hostname!==location.hostname||p!==t.port,r=t.secure!==c}if(t.xdomain=n,t.xscheme=r,e=new o(t),"open"in e&&!t.forceJSONP)return new i(t);if(!a)throw new Error("JSONP disabled");return new s(t)}var o=n(16),i=n(19),s=n(33),a=n(34);e.polling=r,e.websocket=a},function(t,e,n){var r=n(17),o=n(18);t.exports=function(t){var e=t.xdomain,n=t.xscheme,i=t.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!e||r))return new XMLHttpRequest}catch(s){}try{if("undefined"!=typeof XDomainRequest&&!n&&i)return new XDomainRequest}catch(s){}if(!e)try{return new(o[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(s){}}},function(t,e){try{t.exports="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(n){t.exports=!1}},function(t,e){t.exports=function(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")()}()},function(t,e,n){function r(){}function o(t){if(c.call(this,t),this.requestTimeout=t.requestTimeout,this.extraHeaders=t.extraHeaders,"undefined"!=typeof location){var e="https:"===location.protocol,n=location.port;n||(n=e?443:80),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||n!==t.port,this.xs=t.secure!==e}}function i(t){this.method=t.method||"GET",this.uri=t.uri,this.xd=!!t.xd,this.xs=!!t.xs,this.async=!1!==t.async,this.data=void 0!==t.data?t.data:null,this.agent=t.agent,this.isBinary=t.isBinary,this.supportsBinary=t.supportsBinary,this.enablesXDR=t.enablesXDR,this.withCredentials=t.withCredentials,this.requestTimeout=t.requestTimeout,this.pfx=t.pfx,this.key=t.key,this.passphrase=t.passphrase,this.cert=t.cert,this.ca=t.ca,this.ciphers=t.ciphers,this.rejectUnauthorized=t.rejectUnauthorized,this.extraHeaders=t.extraHeaders,this.create()}function s(){for(var t in i.requests)i.requests.hasOwnProperty(t)&&i.requests[t].abort()}var a=n(16),c=n(20),p=n(8),u=n(31),h=n(3)("engine.io-client:polling-xhr"),f=n(18);if(t.exports=o,t.exports.Request=i,u(o,c),o.prototype.supportsBinary=!0,o.prototype.request=function(t){return t=t||{},t.uri=this.uri(),t.xd=this.xd,t.xs=this.xs,t.agent=this.agent||!1,t.supportsBinary=this.supportsBinary,t.enablesXDR=this.enablesXDR,t.withCredentials=this.withCredentials,t.pfx=this.pfx,t.key=this.key,t.passphrase=this.passphrase,t.cert=this.cert,t.ca=this.ca,t.ciphers=this.ciphers,t.rejectUnauthorized=this.rejectUnauthorized,t.requestTimeout=this.requestTimeout,t.extraHeaders=this.extraHeaders,new i(t)},o.prototype.doWrite=function(t,e){var n="string"!=typeof t&&void 0!==t,r=this.request({method:"POST",data:t,isBinary:n}),o=this;r.on("success",e),r.on("error",function(t){o.onError("xhr post error",t)}),this.sendXhr=r},o.prototype.doPoll=function(){h("xhr poll");var t=this.request(),e=this;t.on("data",function(t){e.onData(t)}),t.on("error",function(t){e.onError("xhr poll error",t)}),this.pollXhr=t},p(i.prototype),i.prototype.create=function(){var t={agent:this.agent,xdomain:this.xd,xscheme:this.xs,enablesXDR:this.enablesXDR};t.pfx=this.pfx,t.key=this.key,t.passphrase=this.passphrase,t.cert=this.cert,t.ca=this.ca,t.ciphers=this.ciphers,t.rejectUnauthorized=this.rejectUnauthorized;var e=this.xhr=new a(t),n=this;try{h("xhr open %s: %s",this.method,this.uri),e.open(this.method,this.uri,this.async);try{if(this.extraHeaders){e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0);for(var r in this.extraHeaders)this.extraHeaders.hasOwnProperty(r)&&e.setRequestHeader(r,this.extraHeaders[r])}}catch(o){}if("POST"===this.method)try{this.isBinary?e.setRequestHeader("Content-type","application/octet-stream"):e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(o){}try{e.setRequestHeader("Accept","*/*")}catch(o){}"withCredentials"in e&&(e.withCredentials=this.withCredentials),this.requestTimeout&&(e.timeout=this.requestTimeout),this.hasXDR()?(e.onload=function(){n.onLoad()},e.onerror=function(){n.onError(e.responseText)}):e.onreadystatechange=function(){if(2===e.readyState)try{var t=e.getResponseHeader("Content-Type");(n.supportsBinary&&"application/octet-stream"===t||"application/octet-stream; charset=UTF-8"===t)&&(e.responseType="arraybuffer")}catch(r){}4===e.readyState&&(200===e.status||1223===e.status?n.onLoad():setTimeout(function(){n.onError("number"==typeof e.status?e.status:0)},0))},h("xhr data %s",this.data),e.send(this.data)}catch(o){return void setTimeout(function(){n.onError(o)},0)}"undefined"!=typeof document&&(this.index=i.requestsCount++,i.requests[this.index]=this)},i.prototype.onSuccess=function(){this.emit("success"),this.cleanup()},i.prototype.onData=function(t){thiLine truncated
|
||||
var h,f,l,d=String.fromCharCode;t.exports={version:"2.1.2",encode:a,decode:u}},function(t,e){!function(t){"use strict";e.encode=function(e){var n,r=new Uint8Array(e),o=r.length,i="";for(n=0;n<o;n+=3)i+=t[r[n]>>2],i+=t[(3&r[n])<<4|r[n+1]>>4],i+=t[(15&r[n+1])<<2|r[n+2]>>6],i+=t[63&r[n+2]];return o%3===2?i=i.substring(0,i.length-1)+"=":o%3===1&&(i=i.substring(0,i.length-2)+"=="),i},e.decode=function(e){var n,r,o,i,s,a=.75*e.length,c=e.length,p=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var u=new ArrayBuffer(a),h=new Uint8Array(u);for(n=0;n<c;n+=4)r=t.indexOf(e[n]),o=t.indexOf(e[n+1]),i=t.indexOf(e[n+2]),s=t.indexOf(e[n+3]),h[p++]=r<<2|o>>4,h[p++]=(15&o)<<4|i>>2,h[p++]=(3&i)<<6|63&s;return u}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},function(t,e){function n(t){return t.map(function(t){if(t.buffer instanceof ArrayBuffer){var e=t.buffer;if(t.byteLength!==e.byteLength){var n=new Uint8Array(t.byteLength);n.set(new Uint8Array(e,t.byteOffset,t.byteLength)),e=n.buffer}return e}return t})}function r(t,e){e=e||{};var r=new i;return n(t).forEach(function(t){r.append(t)}),e.type?r.getBlob(e.type):r.getBlob()}function o(t,e){return new Blob(n(t),e||{})}var i="undefined"!=typeof i?i:"undefined"!=typeof WebKitBlobBuilder?WebKitBlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder&&MozBlobBuilder,s=function(){try{var t=new Blob(["hi"]);return 2===t.size}catch(e){return!1}}(),a=s&&function(){try{var t=new Blob([new Uint8Array([1,2])]);return 2===t.size}catch(e){return!1}}(),c=i&&i.prototype.append&&i.prototype.getBlob;"undefined"!=typeof Blob&&(r.prototype=Blob.prototype,o.prototype=Blob.prototype),t.exports=function(){return s?a?Blob:o:c?r:void 0}()},function(t,e){e.encode=function(t){var e="";for(var n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e},e.decode=function(t){for(var e={},n=t.split("&"),r=0,o=n.length;r<o;r++){var i=n[r].split("=");e[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return e}},function(t,e){t.exports=function(t,e){var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},function(t,e){"use strict";function n(t){var e="";do e=s[t%a]+e,t=Math.floor(t/a);while(t>0);return e}function r(t){var e=0;for(u=0;u<t.length;u++)e=e*a+c[t.charAt(u)];return e}function o(){var t=n(+new Date);return t!==i?(p=0,i=t):t+"."+n(p++)}for(var i,s="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),a=64,c={},p=0,u=0;u<a;u++)c[s[u]]=u;o.encode=n,o.decode=r,t.exports=o},function(t,e,n){function r(){}function o(t){i.call(this,t),this.query=this.query||{},c||(c=a.___eio=a.___eio||[]),this.index=c.length;var e=this;c.push(function(t){e.onData(t)}),this.query.j=this.index,"function"==typeof addEventListener&&addEventListener("beforeunload",function(){e.script&&(e.script.onerror=r)},!1)}var i=n(20),s=n(31),a=n(18);t.exports=o;var c,p=/\n/g,u=/\\n/g;s(o,i),o.prototype.supportsBinary=!1,o.prototype.doClose=function(){this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),this.form&&(this.form.parentNode.removeChild(this.form),this.form=null,this.iframe=null),i.prototype.doClose.call(this)},o.prototype.doPoll=function(){var t=this,e=document.createElement("script");this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),e.async=!0,e.src=this.uri(),e.onerror=function(e){t.onError("jsonp poll error",e)};var n=document.getElementsByTagName("script")[0];n?n.parentNode.insertBefore(e,n):(document.head||document.body).appendChild(e),this.script=e;var r="undefined"!=typeof navigator&&/gecko/i.test(navigator.userAgent);r&&setTimeout(function(){var t=document.createElement("iframe");document.body.appendChild(t),document.body.removeChild(t)},100)},o.prototype.doWrite=function(t,e){function n(){r(),e()}function r(){if(o.iframe)try{o.form.removeChild(o.iframe)}catch(t){o.onError("jsonp polling iframe removal error",t)}try{var e='<iframe src="javascript:0" name="'+o.iframeId+'">';i=document.createElement(e)}catch(t){i=document.createElement("iframe"),i.name=o.iframeId,i.src="javascript:0"}i.id=o.iframeId,o.form.appendChild(i),o.iframe=i}var o=this;if(!this.form){var i,s=document.createElement("form"),a=document.createElement("textarea"),c=this.iframeId="eio_iframe_"+this.index;s.className="socketio",s.style.position="absolute",s.style.top="-1000px",s.style.left="-1000px",s.target=c,s.method="POST",s.setAttribute("accept-charset","utf-8"),a.name="d",s.appendChild(a),document.body.appendChild(s),this.form=s,this.area=a}this.form.action=this.uri(),r(),t=t.replace(u,"\\\n"),this.area.value=t.replace(p,"\\n");try{this.form.submit()}catch(h){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"===o.iframe.readyState&&n()}:this.iframe.onload=n}},function(t,e,n){function r(t){var e=t&&t.forceBase64;e&&(this.supportsBinary=!1),this.perMessageDeflate=t.perMessageDeflate,this.usingBrowLine truncated
|
||||
//# sourceMappingURL=socket.io.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///socket.io.js","webpack:///webpack/bootstrap 4d09ce79f1f3f18ae255","webpack:///./lib/index.js","webpack:///./lib/url.js","webpack:///./~/parseuri/index.js","webpack:///./~/debug/src/browser.js","webpack:///./~/process/browser.js","webpack:///./~/debug/src/debug.js","webpack:///./~/ms/index.js","webpack:///./~/socket.io-parser/index.js","webpack:///./~/component-emitter/index.js","webpack:///./~/socket.io-parser/binary.js","webpack:///./~/isarray/index.js","webpack:///./~/socket.io-parser/is-buffer.js","webpack:///./lib/manager.js","webpack:///./~/engine.io-client/lib/index.js","webpack:///./~/engine.io-client/lib/socket.js","webpack:///./~/engine.io-client/lib/transports/index.js","webpack:///./~/engine.io-client/lib/xmlhttprequest.js","webpack:///./~/has-cors/index.js","webpack:///./~/engine.io-client/lib/globalThis.browser.js","webpack:///./~/engine.io-client/lib/transports/polling-xhr.js","webpack:///./~/engine.io-client/lib/transports/polling.js","webpack:///./~/engine.io-client/lib/transport.js","webpack:///./~/engine.io-parser/lib/browser.js","webpack:///./~/engine.io-parser/lib/keys.js","webpack:///./~/has-binary2/index.js","webpack:///./~/arraybuffer.slice/index.js","webpack:///./~/after/index.js","webpack:///./~/engine.io-parser/lib/utf8.js","webpack:///./~/engine.io-parser/~/base64-arraybuffer/lib/base64-arraybuffer.js","webpack:///./~/blob/index.js","webpack:///./~/parseqs/index.js","webpack:///./~/component-inherit/index.js","webpack:///./~/yeast/index.js","webpack:///./~/engine.io-client/lib/transports/polling-jsonp.js","webpack:///./~/engine.io-client/lib/transports/websocket.js","webpack:///./~/indexof/index.js","webpack:///./lib/socket.js","webpack:///./~/to-array/index.js","webpack:///./lib/on.js","webpack:///./~/component-bind/index.js","webpack:///./~/backo2/index.js"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","id","loaded","call","m","c","p","lookup","uri","opts","undefined","io","parsed","url","source","path","sameNamespace","cache","nsps","newConnection","forceNew","multiplex","debug","Manager","query","socket","parser","managers","protocol","connect","Socket","loc","obj","location","host","charAt","test","parseuri","port","ipv6","indexOf","href","pathNames","regx","names","replace","split","substr","length","splice","queryKey","data","$0","$1","$2","re","parts","str","src","b","e","substring","exec","i","authority","ipv6uri","process","useColors","window","type","navigator","userAgent","toLowerCase","match","document","documentElement","style","WebkitAppearance","console","firebug","exception","table","parseInt","RegExp","formatArgs","args","namespace","humanize","diff","color","index","lastC","log","_typeof","Function","prototype","apply","arguments","save","namespaces","storage","removeItem","load","r","env","DEBUG","localstorage","localStorage","Symbol","iterator","constructor","chrome","local","colors","formatters","j","v","JSON","stringify","err","message","enable","defaultSetTimout","Error","defaultClearTimeout","runTimeout","fun","cachedSetTimeout","setTimeout","runClearTimeout","marker","cachedClearTimeout","clearTimeout","cleanUpNextTick","draining","currentQueue","queue","concat","queueIndex","drainQueue","timeout","len","run","Item","array","noop","nextTick","Array","push","title","browser","argv","version","versions","on","addListener","once","off","removeListener","removeAllListeners","emit","prependListener","prependOnceListener","listeners","name","binding","cwd","chdir","dir","umask","selectColor","hash","charCodeAt","Math","abs","createDebug","enabled","self","curr","Date","ms","prevTime","prev","coerce","unshift","format","formatter","val","logFn","bind","destroy","init","instances","skips","instance","disable","stack","parse","String","n","parseFloat","y","d","h","s","fmtShort","round","fmtLong","plural","floor","ceil","options","isNaN","Encoder","encodeAsString","BINARY_EVENT","BINARY_ACK","attachments","nsp","payload","tryStringify","ERROR_PACKET","encodeAsBinary","callback","writeEncoding","bloblessData","deconstruction","binary","deconstructPacket","pack","packet","buffers","removeBlobs","Decoder","reconstructor","decodeString","Number","types","error","buf","next","tryParse","isPayloadValid","ERROR","isArray","BinaryReconstructor","reconPack","msg","Emitter","isBuf","CONNECT","DISCONNECT","EVENT","ACK","encode","encoding","add","base64","takeBinaryData","finishedReconstruction","binData","reconstructPacket","mixin","key","addEventListener","event","fn","_callbacks","removeEventListener","callbacks","cb","slice","hasListeners","_deconstructPacket","placeholder","_placeholder","num","newData","_reconstructPacket","toString","Object","withNativeBlob","Blob","withNativeFile","File","packetData","_removeBlobs","curKey","containingObject","pendingBlobs","fileReader","FileReader","onload","result","reLine truncated
|
||||
+5901
File diff suppressed because it is too large.
Load diff
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 46c68a0009a152ba3192","webpack:///./lib/index.js","webpack:///./lib/url.js","webpack:///./~/parseuri/index.js","webpack:///./support/noop.js","webpack:///./~/socket.io-parser/index.js","webpack:///./~/component-emitter/index.js","webpack:///./~/socket.io-parser/binary.js","webpack:///./~/isarray/index.js","webpack:///./~/socket.io-parser/is-buffer.js","webpack:///./lib/manager.js","webpack:///./~/engine.io-client/lib/index.js","webpack:///./~/engine.io-client/lib/socket.js","webpack:///./~/engine.io-client/lib/transports/index.js","webpack:///./~/engine.io-client/lib/xmlhttprequest.js","webpack:///./~/has-cors/index.js","webpack:///./~/engine.io-client/lib/globalThis.browser.js","webpack:///./~/engine.io-client/lib/transports/polling-xhr.js","webpack:///./~/engine.io-client/lib/transports/polling.js","webpack:///./~/engine.io-client/lib/transport.js","webpack:///./~/engine.io-parser/lib/browser.js","webpack:///./~/engine.io-parser/lib/keys.js","webpack:///./~/has-binary2/index.js","webpack:///./~/arraybuffer.slice/index.js","webpack:///./~/after/index.js","webpack:///./~/engine.io-parser/lib/utf8.js","webpack:///./~/engine.io-parser/~/base64-arraybuffer/lib/base64-arraybuffer.js","webpack:///./~/blob/index.js","webpack:///./~/parseqs/index.js","webpack:///./~/component-inherit/index.js","webpack:///./~/yeast/index.js","webpack:///./~/engine.io-client/lib/transports/polling-jsonp.js","webpack:///./~/engine.io-client/lib/transports/websocket.js","webpack:///ws (ignored)","webpack:///./~/indexof/index.js","webpack:///./lib/socket.js","webpack:///./~/to-array/index.js","webpack:///./lib/on.js","webpack:///./~/component-bind/index.js","webpack:///./~/backo2/index.js"],"names":["url","require","parser","Manager","debug","module","exports","lookup","cache","managers","uri","opts","undefined","parsed","source","id","path","sameNamespace","nsps","newConnection","forceNew","multiplex","io","query","socket","protocol","connect","Socket","parseuri","loc","obj","location","host","charAt","test","port","ipv6","indexOf","href","eio","Emitter","on","bind","Backoff","has","Object","prototype","hasOwnProperty","subs","reconnection","reconnectionAttempts","Infinity","reconnectionDelay","reconnectionDelayMax","randomizationFactor","backoff","min","max","jitter","timeout","readyState","connecting","lastPing","encoding","packetBuffer","_parser","encoder","Encoder","decoder","Decoder","autoConnect","open","emitAll","emit","apply","arguments","nsp","call","updateSocketIds","generateId","engine","v","length","_reconnection","_reconnectionAttempts","_reconnectionDelay","setMin","_randomizationFactor","setJitter","_reconnectionDelayMax","setMax","_timeout","maybeReconnectOnOpen","reconnecting","attempts","reconnect","fn","self","skipReconnect","openSub","onopen","errorSub","data","cleanup","err","Error","destroy","timer","setTimeout","close","push","clearTimeout","onping","Date","onpong","ondata","add","ondecoded","packet","onerror","onConnecting","index","splice","type","encode","encodedPackets","i","write","options","processPacketQueue","pack","shift","subsLength","sub","disconnect","reset","onclose","reason","delay","duration","onreconnect","attempt","toArray","parseqs","hasBin","events","connect_error","connect_timeout","error","reconnect_attempt","reconnect_failed","reconnect_error","ping","pong","json","ids","acks","receiveBuffer","sendBuffer","connected","disconnected","flags","subEvents","send","args","unshift","ev","binary","BINARY_EVENT","EVENT","compress","pop","CONNECT","onpacket","rootNamespaceError","ERROR","onconnect","onevent","ACK","onack","BINARY_ACK","DISCONNECT","ondisconnect","ack","sent","emitBuffered","removeListener"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;ACrCA;;;;AAIA,KAAIA,MAAM,mBAAAC,CAAQ,CAAR,CAAV;AACA,KAAIC,SAAS,mBAAAD,CAAQ,CAAR,CAAb;AACA,KAAIE,UAAU,mBAAAF,CAAQ,CAAR,CAAd;AACA,KAAIG,QAAQ,mBAAAH,CAAQ,CAAR,EAAiB,kBAAjB,CAAZ;;AAEA;;;;AAIAI,QAAOC,OAAP,GAAiBA,UAAUC,MAA3B;;AAEA;;;;AAIA,KAAIC,QAAQF,QAAQG,QAAR,GAAmB,EAA/B;;AAEA;;;;;;;;;;;;;AAaA,UAASF,MAAT,CAAiBG,GAAjB,EAAsBC,IAAtB,EAA4B;AAC1B,OAAI,QAAOD,GAAP,yCAAOA,GAAP,OAAe,QAAnB,EAA6B;AAC3BC,YAAOD,GAAP;AACAA,WAAME,SAAN;AACD;;AAEDD,UAAOA,QAAQ,EAAf;;AAEA,OAAIE,SAASb,IAAIU,GAAJ,CAAb;AACA,OAAII,SAASD,OAAOC,MAApB;AACA,OAAIC,KAAKF,OAAOE,EAAhB;AACA,OAAIC,OAAOH,OAAOG,IAAlB;AACA,OAAIC,gBAAgBT,MAAMO,EAAN,KAAaC,QAAQR,MAAMO,EAAN,EAAUG,IAAnD;AACA,OAAIC,gBAAgBR,KAAKS,QAAL,IAAiBT,KAAK,sBAAL,CAAjB,IACA,UAAUA,KAAKU,SADf,IAC4BJ,aADhD;;AAGA,OAAIK,EAAJ;;AAEA,OAAIH,aAAJ,EAAmB;;AAEjBG,UAAKnB,QAAQW,MAAR,EAAgBH,IAAhB,CAAL;AACD,IAHD,MAGO;AACL,SAAI,CAACH,MAAMO,EAAN,CAAL,EAAgB;;AAEdP,aAAMO,EAAN,IAAYZ,QAAQW,MAAR,EAAgBH,IAAhB,CAAZ;AACD;AACDW,UAAKd,MAAMO,EAAN,CAAL;AACD;AACD,OAAIF,OAAOU,KAAP,ILine truncated
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/*!
|
||||
* Socket.IO v2.5.0
|
||||
* (c) 2014-2021 Guillermo Rauch
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.io=e():t.io=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t,e){"object"===("undefined"==typeof t?"undefined":o(t))&&(e=t,t=void 0),e=e||{};var r,n=i(t),s=n.source,p=n.id,h=n.path,u=c[p]&&h in c[p].nsps,f=e.forceNew||e["force new connection"]||!1===e.multiplex||u;return f?r=a(s,e):(c[p]||(c[p]=a(s,e)),r=c[p]),n.query&&!e.query&&(e.query=n.query),r.socket(n.path,e)}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=r(1),s=r(4),a=r(9);r(3)("socket.io-client");t.exports=e=n;var c=e.managers={};e.protocol=s.protocol,e.connect=n,e.Manager=r(9),e.Socket=r(34)},function(t,e,r){"use strict";function n(t,e){var r=t;e=e||"undefined"!=typeof location&&location,null==t&&(t=e.protocol+"//"+e.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?e.protocol+t:e.host+t),/^(https?|wss?):\/\//.test(t)||(t="undefined"!=typeof e?e.protocol+"//"+t:"https://"+t),r=o(t)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";var n=r.host.indexOf(":")!==-1,i=n?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+i+":"+r.port,r.href=r.protocol+"://"+i+(e&&e.port===r.port?"":":"+r.port),r}var o=r(2);r(3)("socket.io-client:url");t.exports=n},function(t,e){function r(t,e){var r=/\/{2,9}/g,n=e.replace(r,"/").split("/");return"/"!=e.substr(0,1)&&0!==e.length||n.splice(0,1),"/"==e.substr(e.length-1,1)&&n.splice(n.length-1,1),n}function n(t,e){var r={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(t,e,n){e&&(r[e]=n)}),r}var o=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,i=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];t.exports=function(t){var e=t,s=t.indexOf("["),a=t.indexOf("]");s!=-1&&a!=-1&&(t=t.substring(0,s)+t.substring(s,a).replace(/:/g,";")+t.substring(a,t.length));for(var c=o.exec(t||""),p={},h=14;h--;)p[i[h]]=c[h]||"";return s!=-1&&a!=-1&&(p.source=e,p.host=p.host.substring(1,p.host.length-1).replace(/;/g,":"),p.authority=p.authority.replace("[","").replace("]","").replace(/;/g,":"),p.ipv6uri=!0),p.pathNames=r(p,p.path),p.queryKey=n(p,p.query),p}},function(t,e){"use strict";t.exports=function(){return function(){}}},function(t,e,r){function n(){}function o(t){var r=""+t.type;if(e.BINARY_EVENT!==t.type&&e.BINARY_ACK!==t.type||(r+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(r+=t.nsp+","),null!=t.id&&(r+=t.id),null!=t.data){var n=i(t.data);if(n===!1)return m;r+=n}return r}function i(t){try{return JSON.stringify(t)}catch(t){return!1}}function s(t,e){function r(t){var r=l.deconstructPacket(t),n=o(r.packet),i=r.buffers;i.unshift(n),e(i)}l.removeBlobs(t,r)}function a(){this.reconstructor=null}function c(t){var r=0,n={type:Number(t.charAt(0))};if(null==e.types[n.type])return u("unknown packet type "+n.type);if(e.BINARY_EVENT===n.type||e.BINARY_ACK===n.type){for(var o="";"-"!==t.charAt(++r)&&(o+=t.charAt(r),r!=t.length););if(o!=Number(o)||"-"!==t.charAt(r))throw new Error("Illegal attachments");n.attachments=Number(o)}if("/"===t.charAt(r+1))for(n.nsp="";++r;){var i=t.charAt(r);if(","===i)break;if(n.nsp+=i,r===t.length)break}else n.nsp="/";var s=t.charAt(r+1);if(""!==s&&Number(s)==s){for(n.id="";++r;){var i=t.charAt(r);if(null==i||Number(i)!=i){--r;break}if(n.id+=t.charAt(r),r===t.length)break}n.id=Number(n.id)}if(t.charAt(++r)){var a=p(t.substr(r)),c=a!==!1&&(n.type===e.ERROR||d(a));if(!c)return u("invalid payload");n.data=a}return n}function p(t){try{return JSON.parse(t)}catch(t){return!1}}function h(t){this.reconPack=t,this.buffers=[]}function u(t){return{type:e.ERROR,data:"parser error: "+t}}var f=(r(3)("socket.io-parser"),r(5)),l=r(6),d=r(7),y=r(8);e.protocol=4,e.types=["CONNECT","DISCONNECT","EVENT","ACK","ERROR","BINARY_EVENT","BINARY_ACK"],e.CONNECT=0,e.DISCONNECT=1,e.EVENT=2,e.ACK=3,e.ERROR=4,e.BINARY_EVENT=5,e.BINARY_ACK=6,e.Encoder=n,e.Decoder=a;var m=e.ERROR+'"encode error"';n.prototype.encode=function(t,r){if(e.BINARY_EVENT===t.type||e.BINARY_ACK===t.type)s(t,r);else{var n=o(t);r([n])}},f(a.prototype),a.prototype.add=function(t){var r;if("string"==typeof t)r=c(t),e.BINARY_EVENT===r.type||e.BINARY_ACK===r.type?(this.reconstructor=new h(r),0===this.reconstructor.reconPack.attachments&&this.emit("decoded",r)):this.emit("decoded",r);else{if(!y(t)Line truncated
|
||||
this.isReactNative=t.isReactNative,this.extraHeaders=t.extraHeaders,this.localAddress=t.localAddress}var o=r(19),i=r(5);t.exports=n,i(n.prototype),n.prototype.onError=function(t,e){var r=new Error(t);return r.type="TransportError",r.description=e,this.emit("error",r),this},n.prototype.open=function(){return"closed"!==this.readyState&&""!==this.readyState||(this.readyState="opening",this.doOpen()),this},n.prototype.close=function(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this},n.prototype.send=function(t){if("open"!==this.readyState)throw new Error("Transport not open");this.write(t)},n.prototype.onOpen=function(){this.readyState="open",this.writable=!0,this.emit("open")},n.prototype.onData=function(t){var e=o.decodePacket(t,this.socket.binaryType);this.onPacket(e)},n.prototype.onPacket=function(t){this.emit("packet",t)},n.prototype.onClose=function(){this.readyState="closed",this.emit("close")}},function(t,e,r){function n(t,r){var n="b"+e.packets[t.type]+t.data.data;return r(n)}function o(t,r,n){if(!r)return e.encodeBase64Packet(t,n);var o=t.data,i=new Uint8Array(o),s=new Uint8Array(1+o.byteLength);s[0]=v[t.type];for(var a=0;a<i.length;a++)s[a+1]=i[a];return n(s.buffer)}function i(t,r,n){if(!r)return e.encodeBase64Packet(t,n);var o=new FileReader;return o.onload=function(){e.encodePacket({type:t.type,data:o.result},r,!0,n)},o.readAsArrayBuffer(t.data)}function s(t,r,n){if(!r)return e.encodeBase64Packet(t,n);if(g)return i(t,r,n);var o=new Uint8Array(1);o[0]=v[t.type];var s=new w([o.buffer,t.data]);return n(s)}function a(t){try{t=d.decode(t,{strict:!1})}catch(t){return!1}return t}function c(t,e,r){for(var n=new Array(t.length),o=l(t.length,r),i=function(t,r,o){e(r,function(e,r){n[t]=r,o(e,n)})},s=0;s<t.length;s++)i(s,t[s],o)}var p,h=r(20),u=r(21),f=r(22),l=r(23),d=r(24);"undefined"!=typeof ArrayBuffer&&(p=r(25));var y="undefined"!=typeof navigator&&/Android/i.test(navigator.userAgent),m="undefined"!=typeof navigator&&/PhantomJS/i.test(navigator.userAgent),g=y||m;e.protocol=3;var v=e.packets={open:0,close:1,ping:2,pong:3,message:4,upgrade:5,noop:6},b=h(v),k={type:"error",data:"parser error"},w=r(26);e.encodePacket=function(t,e,r,i){"function"==typeof e&&(i=e,e=!1),"function"==typeof r&&(i=r,r=null);var a=void 0===t.data?void 0:t.data.buffer||t.data;if("undefined"!=typeof ArrayBuffer&&a instanceof ArrayBuffer)return o(t,e,i);if("undefined"!=typeof w&&a instanceof w)return s(t,e,i);if(a&&a.base64)return n(t,i);var c=v[t.type];return void 0!==t.data&&(c+=r?d.encode(String(t.data),{strict:!1}):String(t.data)),i(""+c)},e.encodeBase64Packet=function(t,r){var n="b"+e.packets[t.type];if("undefined"!=typeof w&&t.data instanceof w){var o=new FileReader;return o.onload=function(){var t=o.result.split(",")[1];r(n+t)},o.readAsDataURL(t.data)}var i;try{i=String.fromCharCode.apply(null,new Uint8Array(t.data))}catch(e){for(var s=new Uint8Array(t.data),a=new Array(s.length),c=0;c<s.length;c++)a[c]=s[c];i=String.fromCharCode.apply(null,a)}return n+=btoa(i),r(n)},e.decodePacket=function(t,r,n){if(void 0===t)return k;if("string"==typeof t){if("b"===t.charAt(0))return e.decodeBase64Packet(t.substr(1),r);if(n&&(t=a(t),t===!1))return k;var o=t.charAt(0);return Number(o)==o&&b[o]?t.length>1?{type:b[o],data:t.substring(1)}:{type:b[o]}:k}var i=new Uint8Array(t),o=i[0],s=f(t,1);return w&&"blob"===r&&(s=new w([s])),{type:b[o],data:s}},e.decodeBase64Packet=function(t,e){var r=b[t.charAt(0)];if(!p)return{type:r,data:{base64:!0,data:t.substr(1)}};var n=p.decode(t.substr(1));return"blob"===e&&w&&(n=new w([n])),{type:r,data:n}},e.encodePayload=function(t,r,n){function o(t){return t.length+":"+t}function i(t,n){e.encodePacket(t,!!s&&r,!1,function(t){n(null,o(t))})}"function"==typeof r&&(n=r,r=null);var s=u(t);return r&&s?w&&!g?e.encodePayloadAsBlob(t,n):e.encodePayloadAsArrayBuffer(t,n):t.length?void c(t,i,function(t,e){return n(e.join(""))}):n("0:")},e.decodePayload=function(t,r,n){if("string"!=typeof t)return e.decodePayloadAsBinary(t,r,n);"function"==typeof r&&(n=r,r=null);var o;if(""===t)return n(k,0,1);for(var i,s,a="",c=0,p=t.length;c<p;c++){var h=t.charAt(c);if(":"===h){if(""===a||a!=(i=Number(a)))return n(k,0,1);if(s=t.substr(c+1,i),a!=s.length)return n(k,0,1);if(s.length){if(o=e.decodePacket(s,r,!1),k.type===o.type&&k.data===o.data)return n(k,0,1);var u=n(o,c+i,p);if(!1===u)return}c+=i,a=""}else a+=h}return""!==a?n(k,0,1):void 0},e.encodePayloadAsArrayBuffer=function(t,r){function n(t,r){e.encodePacket(t,!0,!0,function(t){return r(null,t)})}return t.length?void c(t,n,function(t,e){var n=e.reduce(function(t,e){var r;return r="string"==typeof e?e.length:e.byteLength,t+r.toString().length+r+2},0),o=new Uint8Array(n),i=0;return e.forEach(function(t){var e="string"==typeof t,r=t;if(e){for(var n=new Uint8Array(t.length),s=0;s<t.length;s++)n[s]=t.charCodeAt(s);r=n.buffer}e?o[i++]=0:o[i++]=1;for(var a=r.byteLength.toString(),s=0;s<a.length;s++)o[i++]=parseInt(a[s]);o[i++]=255;for(var n=newLine truncated
|
||||
var u,f,l,d=String.fromCharCode;t.exports={version:"2.1.2",encode:a,decode:h}},function(t,e){!function(t){"use strict";e.encode=function(e){var r,n=new Uint8Array(e),o=n.length,i="";for(r=0;r<o;r+=3)i+=t[n[r]>>2],i+=t[(3&n[r])<<4|n[r+1]>>4],i+=t[(15&n[r+1])<<2|n[r+2]>>6],i+=t[63&n[r+2]];return o%3===2?i=i.substring(0,i.length-1)+"=":o%3===1&&(i=i.substring(0,i.length-2)+"=="),i},e.decode=function(e){var r,n,o,i,s,a=.75*e.length,c=e.length,p=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var h=new ArrayBuffer(a),u=new Uint8Array(h);for(r=0;r<c;r+=4)n=t.indexOf(e[r]),o=t.indexOf(e[r+1]),i=t.indexOf(e[r+2]),s=t.indexOf(e[r+3]),u[p++]=n<<2|o>>4,u[p++]=(15&o)<<4|i>>2,u[p++]=(3&i)<<6|63&s;return h}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},function(t,e){function r(t){return t.map(function(t){if(t.buffer instanceof ArrayBuffer){var e=t.buffer;if(t.byteLength!==e.byteLength){var r=new Uint8Array(t.byteLength);r.set(new Uint8Array(e,t.byteOffset,t.byteLength)),e=r.buffer}return e}return t})}function n(t,e){e=e||{};var n=new i;return r(t).forEach(function(t){n.append(t)}),e.type?n.getBlob(e.type):n.getBlob()}function o(t,e){return new Blob(r(t),e||{})}var i="undefined"!=typeof i?i:"undefined"!=typeof WebKitBlobBuilder?WebKitBlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder&&MozBlobBuilder,s=function(){try{var t=new Blob(["hi"]);return 2===t.size}catch(t){return!1}}(),a=s&&function(){try{var t=new Blob([new Uint8Array([1,2])]);return 2===t.size}catch(t){return!1}}(),c=i&&i.prototype.append&&i.prototype.getBlob;"undefined"!=typeof Blob&&(n.prototype=Blob.prototype,o.prototype=Blob.prototype),t.exports=function(){return s?a?Blob:o:c?n:void 0}()},function(t,e){e.encode=function(t){var e="";for(var r in t)t.hasOwnProperty(r)&&(e.length&&(e+="&"),e+=encodeURIComponent(r)+"="+encodeURIComponent(t[r]));return e},e.decode=function(t){for(var e={},r=t.split("&"),n=0,o=r.length;n<o;n++){var i=r[n].split("=");e[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return e}},function(t,e){t.exports=function(t,e){var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}},function(t,e){"use strict";function r(t){var e="";do e=s[t%a]+e,t=Math.floor(t/a);while(t>0);return e}function n(t){var e=0;for(h=0;h<t.length;h++)e=e*a+c[t.charAt(h)];return e}function o(){var t=r(+new Date);return t!==i?(p=0,i=t):t+"."+r(p++)}for(var i,s="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),a=64,c={},p=0,h=0;h<a;h++)c[s[h]]=h;o.encode=r,o.decode=n,t.exports=o},function(t,e,r){function n(){}function o(t){i.call(this,t),this.query=this.query||{},c||(c=a.___eio=a.___eio||[]),this.index=c.length;var e=this;c.push(function(t){e.onData(t)}),this.query.j=this.index,"function"==typeof addEventListener&&addEventListener("beforeunload",function(){e.script&&(e.script.onerror=n)},!1)}var i=r(17),s=r(28),a=r(15);t.exports=o;var c,p=/\n/g,h=/\\n/g;s(o,i),o.prototype.supportsBinary=!1,o.prototype.doClose=function(){this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),this.form&&(this.form.parentNode.removeChild(this.form),this.form=null,this.iframe=null),i.prototype.doClose.call(this)},o.prototype.doPoll=function(){var t=this,e=document.createElement("script");this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),e.async=!0,e.src=this.uri(),e.onerror=function(e){t.onError("jsonp poll error",e)};var r=document.getElementsByTagName("script")[0];r?r.parentNode.insertBefore(e,r):(document.head||document.body).appendChild(e),this.script=e;var n="undefined"!=typeof navigator&&/gecko/i.test(navigator.userAgent);n&&setTimeout(function(){var t=document.createElement("iframe");document.body.appendChild(t),document.body.removeChild(t)},100)},o.prototype.doWrite=function(t,e){function r(){n(),e()}function n(){if(o.iframe)try{o.form.removeChild(o.iframe)}catch(t){o.onError("jsonp polling iframe removal error",t)}try{var t='<iframe src="javascript:0" name="'+o.iframeId+'">';i=document.createElement(t)}catch(t){i=document.createElement("iframe"),i.name=o.iframeId,i.src="javascript:0"}i.id=o.iframeId,o.form.appendChild(i),o.iframe=i}var o=this;if(!this.form){var i,s=document.createElement("form"),a=document.createElement("textarea"),c=this.iframeId="eio_iframe_"+this.index;s.className="socketio",s.style.position="absolute",s.style.top="-1000px",s.style.left="-1000px",s.target=c,s.method="POST",s.setAttribute("accept-charset","utf-8"),a.name="d",s.appendChild(a),document.body.appendChild(s),this.form=s,this.area=a}this.form.action=this.uri(),n(),t=t.replace(h,"\\\n"),this.area.value=t.replace(p,"\\n");try{this.form.submit()}catch(t){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"===o.iframe.readyState&&r()}:this.iframe.onload=r}},function(t,e,r){function n(t){var e=t&&t.forceBase64;e&&(this.supportsBinary=!1),this.perMessageDeflate=t.perMessageDeflate,this.usingBrowLine truncated
|
||||
//# sourceMappingURL=socket.io.slim.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///socket.io.slim.js","webpack:///webpack/bootstrap 7863bcd206341bc7952a","webpack:///./lib/index.js","webpack:///./lib/url.js","webpack:///./~/parseuri/index.js","webpack:///./support/noop.js","webpack:///./~/socket.io-parser/index.js","webpack:///./~/component-emitter/index.js","webpack:///./~/socket.io-parser/binary.js","webpack:///./~/isarray/index.js","webpack:///./~/socket.io-parser/is-buffer.js","webpack:///./lib/manager.js","webpack:///./~/engine.io-client/lib/index.js","webpack:///./~/engine.io-client/lib/socket.js","webpack:///./~/engine.io-client/lib/transports/index.js","webpack:///./~/engine.io-client/lib/xmlhttprequest.js","webpack:///./~/has-cors/index.js","webpack:///./~/engine.io-client/lib/globalThis.browser.js","webpack:///./~/engine.io-client/lib/transports/polling-xhr.js","webpack:///./~/engine.io-client/lib/transports/polling.js","webpack:///./~/engine.io-client/lib/transport.js","webpack:///./~/engine.io-parser/lib/browser.js","webpack:///./~/engine.io-parser/lib/keys.js","webpack:///./~/has-binary2/index.js","webpack:///./~/arraybuffer.slice/index.js","webpack:///./~/after/index.js","webpack:///./~/engine.io-parser/lib/utf8.js","webpack:///./~/engine.io-parser/~/base64-arraybuffer/lib/base64-arraybuffer.js","webpack:///./~/blob/index.js","webpack:///./~/parseqs/index.js","webpack:///./~/component-inherit/index.js","webpack:///./~/yeast/index.js","webpack:///./~/engine.io-client/lib/transports/polling-jsonp.js","webpack:///./~/engine.io-client/lib/transports/websocket.js","webpack:///./~/indexof/index.js","webpack:///./lib/socket.js","webpack:///./~/to-array/index.js","webpack:///./lib/on.js","webpack:///./~/component-bind/index.js","webpack:///./~/backo2/index.js"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","id","loaded","call","m","c","p","lookup","uri","opts","_typeof","undefined","io","parsed","url","source","path","sameNamespace","cache","nsps","newConnection","forceNew","multiplex","Manager","query","socket","Symbol","iterator","obj","constructor","prototype","parser","managers","protocol","connect","Socket","loc","location","host","charAt","test","parseuri","port","ipv6","indexOf","href","pathNames","regx","names","replace","split","substr","length","splice","queryKey","data","$0","$1","$2","re","parts","str","src","b","e","substring","exec","i","authority","ipv6uri","Encoder","encodeAsString","type","BINARY_EVENT","BINARY_ACK","attachments","nsp","payload","tryStringify","ERROR_PACKET","JSON","stringify","encodeAsBinary","callback","writeEncoding","bloblessData","deconstruction","binary","deconstructPacket","pack","packet","buffers","unshift","removeBlobs","Decoder","reconstructor","decodeString","Number","types","error","buf","Error","next","tryParse","isPayloadValid","ERROR","isArray","parse","BinaryReconstructor","reconPack","msg","Emitter","isBuf","CONNECT","DISCONNECT","EVENT","ACK","encode","encoding","add","emit","base64","takeBinaryData","destroy","finishedReconstruction","binData","push","reconstructPacket","mixin","key","on","addEventListener","event","fn","_callbacks","once","off","apply","arguments","removeListener","removeAllListeners","removeEventListener","callbacks","cb","args","Array","slice","len","listeners","hasListeners","_deconstructPacket","placeholder","_placeholder","num","newData","Date","_reconstructPacket","toString","Object","withNativeBlob","Blob","withNativeFile","File","packetData","_removeBlobs","curKey","containingObject","pendingBlobs","fileReader","FileReader","onload","result","readAsArrayBuffer","arr","withNativeBuffer","Buffer","isBuffer","withNativeArrayBuffer","ArrayBuffer","isView","buffer","subs","reconnection","reconnectionAttempts","Infinity","reconnectionDelay","reconnectionDelayMax","randomizationFactor","backoff","Backoff","min","max","jitter","timeout","readyState","connecting","lastPing","packetBuffer","_parser","encoder","decoder","autoConnect","open","eio","bind","has","hasOwnProperty","emitAll","updateSocketIds","generateId","engine","v","_reconnection","_reconnectionAttempts","_reconnectionDelay","setMin","_randomizationFactor","setJitter","_reconnectionDelayMax","setMax","_timeout","maybeReconnectOnOpen","reconnecting","attempts","reconnect","self","skipReconnect","openSub","onopen","errorSub","cleanup","err","timer","setTimeout","close","clearTimeout","onping","onpong","ondata","ondecoded","onerror","onConnecting","index","encodedPackets","write","options","processPacketQueue","shift","subsLength","sub","disconnect","reset","onclose","reason","delay","duration","onreconnect","attempt","hostname","secure","agent","parseqs","decode","upgrade","forceJSONP","jsonp","forceBase64","enablesXDR","withCredentials","timestampParam","timestampRequests","transports","transportOptions","writeBuffer","prevBufferLen","policyPort","rememberUpgrade","binaryType","onlyBinaryULine truncated
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var url = require('./url');
|
||||
var parser = require('socket.io-parser');
|
||||
var Manager = require('./manager');
|
||||
var debug = require('debug')('socket.io-client');
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = exports = lookup;
|
||||
|
||||
/**
|
||||
* Managers cache.
|
||||
*/
|
||||
|
||||
var cache = exports.managers = {};
|
||||
|
||||
/**
|
||||
* Looks up an existing `Manager` for multiplexing.
|
||||
* If the user summons:
|
||||
*
|
||||
* `io('http://localhost/a');`
|
||||
* `io('http://localhost/b');`
|
||||
*
|
||||
* We reuse the existing instance based on same scheme/port/host,
|
||||
* and we initialize sockets for each namespace.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function lookup (uri, opts) {
|
||||
if (typeof uri === 'object') {
|
||||
opts = uri;
|
||||
uri = undefined;
|
||||
}
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
var parsed = url(uri);
|
||||
var source = parsed.source;
|
||||
var id = parsed.id;
|
||||
var path = parsed.path;
|
||||
var sameNamespace = cache[id] && path in cache[id].nsps;
|
||||
var newConnection = opts.forceNew || opts['force new connection'] ||
|
||||
false === opts.multiplex || sameNamespace;
|
||||
|
||||
var io;
|
||||
|
||||
if (newConnection) {
|
||||
debug('ignoring socket cache for %s', source);
|
||||
io = Manager(source, opts);
|
||||
} else {
|
||||
if (!cache[id]) {
|
||||
debug('new io instance for %s', source);
|
||||
cache[id] = Manager(source, opts);
|
||||
}
|
||||
io = cache[id];
|
||||
}
|
||||
if (parsed.query && !opts.query) {
|
||||
opts.query = parsed.query;
|
||||
}
|
||||
return io.socket(parsed.path, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protocol version.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.protocol = parser.protocol;
|
||||
|
||||
/**
|
||||
* `connect`.
|
||||
*
|
||||
* @param {String} uri
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.connect = lookup;
|
||||
|
||||
/**
|
||||
* Expose constructors for standalone build.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.Manager = require('./manager');
|
||||
exports.Socket = require('./socket');
|
||||
+577
@@ -0,0 +1,577 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var eio = require('engine.io-client');
|
||||
var Socket = require('./socket');
|
||||
var Emitter = require('component-emitter');
|
||||
var parser = require('socket.io-parser');
|
||||
var on = require('./on');
|
||||
var bind = require('component-bind');
|
||||
var debug = require('debug')('socket.io-client:manager');
|
||||
var indexOf = require('indexof');
|
||||
var Backoff = require('backo2');
|
||||
|
||||
/**
|
||||
* IE6+ hasOwnProperty
|
||||
*/
|
||||
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Module exports
|
||||
*/
|
||||
|
||||
module.exports = Manager;
|
||||
|
||||
/**
|
||||
* `Manager` constructor.
|
||||
*
|
||||
* @param {String} engine instance or engine uri/opts
|
||||
* @param {Object} options
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Manager (uri, opts) {
|
||||
if (!(this instanceof Manager)) return new Manager(uri, opts);
|
||||
if (uri && ('object' === typeof uri)) {
|
||||
opts = uri;
|
||||
uri = undefined;
|
||||
}
|
||||
opts = opts || {};
|
||||
|
||||
opts.path = opts.path || '/socket.io';
|
||||
this.nsps = {};
|
||||
this.subs = [];
|
||||
this.opts = opts;
|
||||
this.reconnection(opts.reconnection !== false);
|
||||
this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
|
||||
this.reconnectionDelay(opts.reconnectionDelay || 1000);
|
||||
this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
|
||||
this.randomizationFactor(opts.randomizationFactor || 0.5);
|
||||
this.backoff = new Backoff({
|
||||
min: this.reconnectionDelay(),
|
||||
max: this.reconnectionDelayMax(),
|
||||
jitter: this.randomizationFactor()
|
||||
});
|
||||
this.timeout(null == opts.timeout ? 20000 : opts.timeout);
|
||||
this.readyState = 'closed';
|
||||
this.uri = uri;
|
||||
this.connecting = [];
|
||||
this.lastPing = null;
|
||||
this.encoding = false;
|
||||
this.packetBuffer = [];
|
||||
var _parser = opts.parser || parser;
|
||||
this.encoder = new _parser.Encoder();
|
||||
this.decoder = new _parser.Decoder();
|
||||
this.autoConnect = opts.autoConnect !== false;
|
||||
if (this.autoConnect) this.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Propagate given event to sockets and emit on `this`
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.emitAll = function () {
|
||||
this.emit.apply(this, arguments);
|
||||
for (var nsp in this.nsps) {
|
||||
if (has.call(this.nsps, nsp)) {
|
||||
this.nsps[nsp].emit.apply(this.nsps[nsp], arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update `socket.id` of all sockets
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.updateSocketIds = function () {
|
||||
for (var nsp in this.nsps) {
|
||||
if (has.call(this.nsps, nsp)) {
|
||||
this.nsps[nsp].id = this.generateId(nsp);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* generate `socket.id` for the given `nsp`
|
||||
*
|
||||
* @param {String} nsp
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.generateId = function (nsp) {
|
||||
return (nsp === '/' ? '' : (nsp + '#')) + this.engine.id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mix in `Emitter`.
|
||||
*/
|
||||
|
||||
Emitter(Manager.prototype);
|
||||
|
||||
/**
|
||||
* Sets the `reconnection` config.
|
||||
*
|
||||
* @param {Boolean} true/false if it should automatically reconnect
|
||||
* @return {Manager} self or value
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Manager.prototype.reconnection = function (v) {
|
||||
if (!arguments.length) return this._reconnection;
|
||||
this._reconnection = !!v;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the reconnection attempts config.
|
||||
*
|
||||
* @param {Number} max reconnection attempts before giving up
|
||||
* @return {Manager} self or value
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Manager.prototype.reconnectionAttempts = function (v) {
|
||||
if (!arguments.length) return this._reconnectionAttempts;
|
||||
this._reconnectionAttempts = v;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the delay between reconnections.
|
||||
*
|
||||
* @param {Number} delay
|
||||
* @return {Manager} self or value
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Manager.prototype.reconnectionDelay = function (v) {
|
||||
if (!arguments.length) return this._reconnectionDelay;
|
||||
this._reconnectionDelay = v;
|
||||
this.backoff && this.backoff.setMin(v);
|
||||
return this;
|
||||
};
|
||||
|
||||
Manager.prototype.randomizationFactor = function (v) {
|
||||
if (!arguments.length) return this._randomizationFactor;
|
||||
this._randomizationFactor = v;
|
||||
this.backoff && this.backoff.setJitter(v);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the maximum delay between reconnections.
|
||||
*
|
||||
* @param {Number} delay
|
||||
* @return {Manager} self or value
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Manager.prototype.reconnectionDelayMax = function (v) {
|
||||
if (!arguments.length) return this._reconnectionDelayMax;
|
||||
this._reconnectionDelayMax = v;
|
||||
this.backoff && this.backoff.setMax(v);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the connection timeout. `false` to disable
|
||||
*
|
||||
* @return {Manager} self or value
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Manager.prototype.timeout = function (v) {
|
||||
if (!arguments.length) return this._timeout;
|
||||
this._timeout = v;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts trying to reconnect if reconnection is enabled and we have not
|
||||
* started reconnecting yet
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.maybeReconnectOnOpen = function () {
|
||||
// Only try to reconnect if it's the first time we're connecting
|
||||
if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) {
|
||||
// keeps reconnection from firing twice for the same reconnection loop
|
||||
this.reconnect();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the current transport `socket`.
|
||||
*
|
||||
* @param {Function} optional, callback
|
||||
* @return {Manager} self
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Manager.prototype.open =
|
||||
Manager.prototype.connect = function (fn, opts) {
|
||||
debug('readyState %s', this.readyState);
|
||||
if (~this.readyState.indexOf('open')) return this;
|
||||
|
||||
debug('opening %s', this.uri);
|
||||
this.engine = eio(this.uri, this.opts);
|
||||
var socket = this.engine;
|
||||
var self = this;
|
||||
this.readyState = 'opening';
|
||||
this.skipReconnect = false;
|
||||
|
||||
// emit `open`
|
||||
var openSub = on(socket, 'open', function () {
|
||||
self.onopen();
|
||||
fn && fn();
|
||||
});
|
||||
|
||||
// emit `connect_error`
|
||||
var errorSub = on(socket, 'error', function (data) {
|
||||
debug('connect_error');
|
||||
self.cleanup();
|
||||
self.readyState = 'closed';
|
||||
self.emitAll('connect_error', data);
|
||||
if (fn) {
|
||||
var err = new Error('Connection error');
|
||||
err.data = data;
|
||||
fn(err);
|
||||
} else {
|
||||
// Only do this if there is no fn to handle the error
|
||||
self.maybeReconnectOnOpen();
|
||||
}
|
||||
});
|
||||
|
||||
// emit `connect_timeout`
|
||||
if (false !== this._timeout) {
|
||||
var timeout = this._timeout;
|
||||
debug('connect attempt will timeout after %d', timeout);
|
||||
|
||||
if (timeout === 0) {
|
||||
openSub.destroy(); // prevents a race condition with the 'open' event
|
||||
}
|
||||
|
||||
// set timer
|
||||
var timer = setTimeout(function () {
|
||||
debug('connect attempt timed out after %d', timeout);
|
||||
openSub.destroy();
|
||||
socket.close();
|
||||
socket.emit('error', 'timeout');
|
||||
self.emitAll('connect_timeout', timeout);
|
||||
}, timeout);
|
||||
|
||||
this.subs.push({
|
||||
destroy: function () {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.subs.push(openSub);
|
||||
this.subs.push(errorSub);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon transport open.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.onopen = function () {
|
||||
debug('open');
|
||||
|
||||
// clear old subs
|
||||
this.cleanup();
|
||||
|
||||
// mark as open
|
||||
this.readyState = 'open';
|
||||
this.emit('open');
|
||||
|
||||
// add new subs
|
||||
var socket = this.engine;
|
||||
this.subs.push(on(socket, 'data', bind(this, 'ondata')));
|
||||
this.subs.push(on(socket, 'ping', bind(this, 'onping')));
|
||||
this.subs.push(on(socket, 'pong', bind(this, 'onpong')));
|
||||
this.subs.push(on(socket, 'error', bind(this, 'onerror')));
|
||||
this.subs.push(on(socket, 'close', bind(this, 'onclose')));
|
||||
this.subs.push(on(this.decoder, 'decoded', bind(this, 'ondecoded')));
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon a ping.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.onping = function () {
|
||||
this.lastPing = new Date();
|
||||
this.emitAll('ping');
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon a packet.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.onpong = function () {
|
||||
this.emitAll('pong', new Date() - this.lastPing);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called with data.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.ondata = function (data) {
|
||||
this.decoder.add(data);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when parser fully decodes a packet.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.ondecoded = function (packet) {
|
||||
this.emit('packet', packet);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon socket error.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.onerror = function (err) {
|
||||
debug('error', err);
|
||||
this.emitAll('error', err);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new socket for the given `nsp`.
|
||||
*
|
||||
* @return {Socket}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Manager.prototype.socket = function (nsp, opts) {
|
||||
var socket = this.nsps[nsp];
|
||||
if (!socket) {
|
||||
socket = new Socket(this, nsp, opts);
|
||||
this.nsps[nsp] = socket;
|
||||
var self = this;
|
||||
socket.on('connecting', onConnecting);
|
||||
socket.on('connect', function () {
|
||||
socket.id = self.generateId(nsp);
|
||||
});
|
||||
|
||||
if (this.autoConnect) {
|
||||
// manually call here since connecting event is fired before listening
|
||||
onConnecting();
|
||||
}
|
||||
}
|
||||
|
||||
function onConnecting () {
|
||||
if (!~indexOf(self.connecting, socket)) {
|
||||
self.connecting.push(socket);
|
||||
}
|
||||
}
|
||||
|
||||
return socket;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon a socket close.
|
||||
*
|
||||
* @param {Socket} socket
|
||||
*/
|
||||
|
||||
Manager.prototype.destroy = function (socket) {
|
||||
var index = indexOf(this.connecting, socket);
|
||||
if (~index) this.connecting.splice(index, 1);
|
||||
if (this.connecting.length) return;
|
||||
|
||||
this.close();
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a packet.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.packet = function (packet) {
|
||||
debug('writing packet %j', packet);
|
||||
var self = this;
|
||||
if (packet.query && packet.type === 0) packet.nsp += '?' + packet.query;
|
||||
|
||||
if (!self.encoding) {
|
||||
// encode, then write to engine with result
|
||||
self.encoding = true;
|
||||
this.encoder.encode(packet, function (encodedPackets) {
|
||||
for (var i = 0; i < encodedPackets.length; i++) {
|
||||
self.engine.write(encodedPackets[i], packet.options);
|
||||
}
|
||||
self.encoding = false;
|
||||
self.processPacketQueue();
|
||||
});
|
||||
} else { // add packet to the queue
|
||||
self.packetBuffer.push(packet);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If packet buffer is non-empty, begins encoding the
|
||||
* next packet in line.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.processPacketQueue = function () {
|
||||
if (this.packetBuffer.length > 0 && !this.encoding) {
|
||||
var pack = this.packetBuffer.shift();
|
||||
this.packet(pack);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up transport subscriptions and packet buffer.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.cleanup = function () {
|
||||
debug('cleanup');
|
||||
|
||||
var subsLength = this.subs.length;
|
||||
for (var i = 0; i < subsLength; i++) {
|
||||
var sub = this.subs.shift();
|
||||
sub.destroy();
|
||||
}
|
||||
|
||||
this.packetBuffer = [];
|
||||
this.encoding = false;
|
||||
this.lastPing = null;
|
||||
|
||||
this.decoder.destroy();
|
||||
};
|
||||
|
||||
/**
|
||||
* Close the current socket.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.close =
|
||||
Manager.prototype.disconnect = function () {
|
||||
debug('disconnect');
|
||||
this.skipReconnect = true;
|
||||
this.reconnecting = false;
|
||||
if ('opening' === this.readyState) {
|
||||
// `onclose` will not fire because
|
||||
// an open event never happened
|
||||
this.cleanup();
|
||||
}
|
||||
this.backoff.reset();
|
||||
this.readyState = 'closed';
|
||||
if (this.engine) this.engine.close();
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon engine close.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.onclose = function (reason) {
|
||||
debug('onclose');
|
||||
|
||||
this.cleanup();
|
||||
this.backoff.reset();
|
||||
this.readyState = 'closed';
|
||||
this.emit('close', reason);
|
||||
|
||||
if (this._reconnection && !this.skipReconnect) {
|
||||
this.reconnect();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempt a reconnection.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.reconnect = function () {
|
||||
if (this.reconnecting || this.skipReconnect) return this;
|
||||
|
||||
var self = this;
|
||||
|
||||
if (this.backoff.attempts >= this._reconnectionAttempts) {
|
||||
debug('reconnect failed');
|
||||
this.backoff.reset();
|
||||
this.emitAll('reconnect_failed');
|
||||
this.reconnecting = false;
|
||||
} else {
|
||||
var delay = this.backoff.duration();
|
||||
debug('will wait %dms before reconnect attempt', delay);
|
||||
|
||||
this.reconnecting = true;
|
||||
var timer = setTimeout(function () {
|
||||
if (self.skipReconnect) return;
|
||||
|
||||
debug('attempting reconnect');
|
||||
self.emitAll('reconnect_attempt', self.backoff.attempts);
|
||||
self.emitAll('reconnecting', self.backoff.attempts);
|
||||
|
||||
// check again for the case socket closed in above events
|
||||
if (self.skipReconnect) return;
|
||||
|
||||
self.open(function (err) {
|
||||
if (err) {
|
||||
debug('reconnect attempt error');
|
||||
self.reconnecting = false;
|
||||
self.reconnect();
|
||||
self.emitAll('reconnect_error', err.data);
|
||||
} else {
|
||||
debug('reconnect success');
|
||||
self.onreconnect();
|
||||
}
|
||||
});
|
||||
}, delay);
|
||||
|
||||
this.subs.push({
|
||||
destroy: function () {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon successful reconnect.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.onreconnect = function () {
|
||||
var attempt = this.backoff.attempts;
|
||||
this.reconnecting = false;
|
||||
this.backoff.reset();
|
||||
this.updateSocketIds();
|
||||
this.emitAll('reconnect', attempt);
|
||||
};
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = on;
|
||||
|
||||
/**
|
||||
* Helper for subscriptions.
|
||||
*
|
||||
* @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter`
|
||||
* @param {String} event name
|
||||
* @param {Function} callback
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function on (obj, ev, fn) {
|
||||
obj.on(ev, fn);
|
||||
return {
|
||||
destroy: function () {
|
||||
obj.removeListener(ev, fn);
|
||||
}
|
||||
};
|
||||
}
|
||||
+438
@@ -0,0 +1,438 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var parser = require('socket.io-parser');
|
||||
var Emitter = require('component-emitter');
|
||||
var toArray = require('to-array');
|
||||
var on = require('./on');
|
||||
var bind = require('component-bind');
|
||||
var debug = require('debug')('socket.io-client:socket');
|
||||
var parseqs = require('parseqs');
|
||||
var hasBin = require('has-binary2');
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = exports = Socket;
|
||||
|
||||
/**
|
||||
* Internal events (blacklisted).
|
||||
* These events can't be emitted by the user.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var events = {
|
||||
connect: 1,
|
||||
connect_error: 1,
|
||||
connect_timeout: 1,
|
||||
connecting: 1,
|
||||
disconnect: 1,
|
||||
error: 1,
|
||||
reconnect: 1,
|
||||
reconnect_attempt: 1,
|
||||
reconnect_failed: 1,
|
||||
reconnect_error: 1,
|
||||
reconnecting: 1,
|
||||
ping: 1,
|
||||
pong: 1
|
||||
};
|
||||
|
||||
/**
|
||||
* Shortcut to `Emitter#emit`.
|
||||
*/
|
||||
|
||||
var emit = Emitter.prototype.emit;
|
||||
|
||||
/**
|
||||
* `Socket` constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Socket (io, nsp, opts) {
|
||||
this.io = io;
|
||||
this.nsp = nsp;
|
||||
this.json = this; // compat
|
||||
this.ids = 0;
|
||||
this.acks = {};
|
||||
this.receiveBuffer = [];
|
||||
this.sendBuffer = [];
|
||||
this.connected = false;
|
||||
this.disconnected = true;
|
||||
this.flags = {};
|
||||
if (opts && opts.query) {
|
||||
this.query = opts.query;
|
||||
}
|
||||
if (this.io.autoConnect) this.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mix in `Emitter`.
|
||||
*/
|
||||
|
||||
Emitter(Socket.prototype);
|
||||
|
||||
/**
|
||||
* Subscribe to open, close and packet events
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.subEvents = function () {
|
||||
if (this.subs) return;
|
||||
|
||||
var io = this.io;
|
||||
this.subs = [
|
||||
on(io, 'open', bind(this, 'onopen')),
|
||||
on(io, 'packet', bind(this, 'onpacket')),
|
||||
on(io, 'close', bind(this, 'onclose'))
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* "Opens" the socket.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.open =
|
||||
Socket.prototype.connect = function () {
|
||||
if (this.connected) return this;
|
||||
|
||||
this.subEvents();
|
||||
if (!this.io.reconnecting) this.io.open(); // ensure open
|
||||
if ('open' === this.io.readyState) this.onopen();
|
||||
this.emit('connecting');
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a `message` event.
|
||||
*
|
||||
* @return {Socket} self
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.send = function () {
|
||||
var args = toArray(arguments);
|
||||
args.unshift('message');
|
||||
this.emit.apply(this, args);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Override `emit`.
|
||||
* If the event is in `events`, it's emitted normally.
|
||||
*
|
||||
* @param {String} event name
|
||||
* @return {Socket} self
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.emit = function (ev) {
|
||||
if (events.hasOwnProperty(ev)) {
|
||||
emit.apply(this, arguments);
|
||||
return this;
|
||||
}
|
||||
|
||||
var args = toArray(arguments);
|
||||
var packet = {
|
||||
type: (this.flags.binary !== undefined ? this.flags.binary : hasBin(args)) ? parser.BINARY_EVENT : parser.EVENT,
|
||||
data: args
|
||||
};
|
||||
|
||||
packet.options = {};
|
||||
packet.options.compress = !this.flags || false !== this.flags.compress;
|
||||
|
||||
// event ack callback
|
||||
if ('function' === typeof args[args.length - 1]) {
|
||||
debug('emitting packet with ack id %d', this.ids);
|
||||
this.acks[this.ids] = args.pop();
|
||||
packet.id = this.ids++;
|
||||
}
|
||||
|
||||
if (this.connected) {
|
||||
this.packet(packet);
|
||||
} else {
|
||||
this.sendBuffer.push(packet);
|
||||
}
|
||||
|
||||
this.flags = {};
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a packet.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.packet = function (packet) {
|
||||
packet.nsp = this.nsp;
|
||||
this.io.packet(packet);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon engine `open`.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.onopen = function () {
|
||||
debug('transport is open - connecting');
|
||||
|
||||
// write connect packet if necessary
|
||||
if ('/' !== this.nsp) {
|
||||
if (this.query) {
|
||||
var query = typeof this.query === 'object' ? parseqs.encode(this.query) : this.query;
|
||||
debug('sending connect packet with query %s', query);
|
||||
this.packet({type: parser.CONNECT, query: query});
|
||||
} else {
|
||||
this.packet({type: parser.CONNECT});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon engine `close`.
|
||||
*
|
||||
* @param {String} reason
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.onclose = function (reason) {
|
||||
debug('close (%s)', reason);
|
||||
this.connected = false;
|
||||
this.disconnected = true;
|
||||
delete this.id;
|
||||
this.emit('disconnect', reason);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called with socket packet.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.onpacket = function (packet) {
|
||||
var sameNamespace = packet.nsp === this.nsp;
|
||||
var rootNamespaceError = packet.type === parser.ERROR && packet.nsp === '/';
|
||||
|
||||
if (!sameNamespace && !rootNamespaceError) return;
|
||||
|
||||
switch (packet.type) {
|
||||
case parser.CONNECT:
|
||||
this.onconnect();
|
||||
break;
|
||||
|
||||
case parser.EVENT:
|
||||
this.onevent(packet);
|
||||
break;
|
||||
|
||||
case parser.BINARY_EVENT:
|
||||
this.onevent(packet);
|
||||
break;
|
||||
|
||||
case parser.ACK:
|
||||
this.onack(packet);
|
||||
break;
|
||||
|
||||
case parser.BINARY_ACK:
|
||||
this.onack(packet);
|
||||
break;
|
||||
|
||||
case parser.DISCONNECT:
|
||||
this.ondisconnect();
|
||||
break;
|
||||
|
||||
case parser.ERROR:
|
||||
this.emit('error', packet.data);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon a server event.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.onevent = function (packet) {
|
||||
var args = packet.data || [];
|
||||
debug('emitting event %j', args);
|
||||
|
||||
if (null != packet.id) {
|
||||
debug('attaching ack callback to event');
|
||||
args.push(this.ack(packet.id));
|
||||
}
|
||||
|
||||
if (this.connected) {
|
||||
emit.apply(this, args);
|
||||
} else {
|
||||
this.receiveBuffer.push(args);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Produces an ack callback to emit with an event.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.ack = function (id) {
|
||||
var self = this;
|
||||
var sent = false;
|
||||
return function () {
|
||||
// prevent double callbacks
|
||||
if (sent) return;
|
||||
sent = true;
|
||||
var args = toArray(arguments);
|
||||
debug('sending ack %j', args);
|
||||
|
||||
self.packet({
|
||||
type: hasBin(args) ? parser.BINARY_ACK : parser.ACK,
|
||||
id: id,
|
||||
data: args
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon a server acknowlegement.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.onack = function (packet) {
|
||||
var ack = this.acks[packet.id];
|
||||
if ('function' === typeof ack) {
|
||||
debug('calling ack %s with %j', packet.id, packet.data);
|
||||
ack.apply(this, packet.data);
|
||||
delete this.acks[packet.id];
|
||||
} else {
|
||||
debug('bad ack %s', packet.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon server connect.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.onconnect = function () {
|
||||
this.connected = true;
|
||||
this.disconnected = false;
|
||||
this.emitBuffered();
|
||||
this.emit('connect');
|
||||
};
|
||||
|
||||
/**
|
||||
* Emit buffered events (received and emitted).
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.emitBuffered = function () {
|
||||
var i;
|
||||
for (i = 0; i < this.receiveBuffer.length; i++) {
|
||||
emit.apply(this, this.receiveBuffer[i]);
|
||||
}
|
||||
this.receiveBuffer = [];
|
||||
|
||||
for (i = 0; i < this.sendBuffer.length; i++) {
|
||||
this.packet(this.sendBuffer[i]);
|
||||
}
|
||||
this.sendBuffer = [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon server disconnect.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.ondisconnect = function () {
|
||||
debug('server disconnect (%s)', this.nsp);
|
||||
this.destroy();
|
||||
this.onclose('io server disconnect');
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon forced client/server side disconnections,
|
||||
* this method ensures the manager stops tracking us and
|
||||
* that reconnections don't get triggered for this.
|
||||
*
|
||||
* @api private.
|
||||
*/
|
||||
|
||||
Socket.prototype.destroy = function () {
|
||||
if (this.subs) {
|
||||
// clean subscriptions to avoid reconnections
|
||||
for (var i = 0; i < this.subs.length; i++) {
|
||||
this.subs[i].destroy();
|
||||
}
|
||||
this.subs = null;
|
||||
}
|
||||
|
||||
this.io.destroy(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Disconnects the socket manually.
|
||||
*
|
||||
* @return {Socket} self
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.close =
|
||||
Socket.prototype.disconnect = function () {
|
||||
if (this.connected) {
|
||||
debug('performing disconnect (%s)', this.nsp);
|
||||
this.packet({ type: parser.DISCONNECT });
|
||||
}
|
||||
|
||||
// remove socket from pool
|
||||
this.destroy();
|
||||
|
||||
if (this.connected) {
|
||||
// fire events
|
||||
this.onclose('io client disconnect');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the compress flag.
|
||||
*
|
||||
* @param {Boolean} if `true`, compresses the sending data
|
||||
* @return {Socket} self
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.compress = function (compress) {
|
||||
this.flags.compress = compress;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the binary flag
|
||||
*
|
||||
* @param {Boolean} whether the emitted data contains binary
|
||||
* @return {Socket} self
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.binary = function (binary) {
|
||||
this.flags.binary = binary;
|
||||
return this;
|
||||
};
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var parseuri = require('parseuri');
|
||||
var debug = require('debug')('socket.io-client:url');
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = url;
|
||||
|
||||
/**
|
||||
* URL parser.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Object} An object meant to mimic window.location.
|
||||
* Defaults to window.location.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function url (uri, loc) {
|
||||
var obj = uri;
|
||||
|
||||
// default to window.location
|
||||
loc = loc || (typeof location !== 'undefined' && location);
|
||||
if (null == uri) uri = loc.protocol + '//' + loc.host;
|
||||
|
||||
// relative path support
|
||||
if ('string' === typeof uri) {
|
||||
if ('/' === uri.charAt(0)) {
|
||||
if ('/' === uri.charAt(1)) {
|
||||
uri = loc.protocol + uri;
|
||||
} else {
|
||||
uri = loc.host + uri;
|
||||
}
|
||||
}
|
||||
|
||||
if (!/^(https?|wss?):\/\//.test(uri)) {
|
||||
debug('protocol-less url %s', uri);
|
||||
if ('undefined' !== typeof loc) {
|
||||
uri = loc.protocol + '//' + uri;
|
||||
} else {
|
||||
uri = 'https://' + uri;
|
||||
}
|
||||
}
|
||||
|
||||
// parse
|
||||
debug('parse %s', uri);
|
||||
obj = parseuri(uri);
|
||||
}
|
||||
|
||||
// make sure we treat `localhost:80` and `localhost` equally
|
||||
if (!obj.port) {
|
||||
if (/^(http|ws)$/.test(obj.protocol)) {
|
||||
obj.port = '80';
|
||||
} else if (/^(http|ws)s$/.test(obj.protocol)) {
|
||||
obj.port = '443';
|
||||
}
|
||||
}
|
||||
|
||||
obj.path = obj.path || '/';
|
||||
|
||||
var ipv6 = obj.host.indexOf(':') !== -1;
|
||||
var host = ipv6 ? '[' + obj.host + ']' : obj.host;
|
||||
|
||||
// define unique id
|
||||
obj.id = obj.protocol + '://' + host + ':' + obj.port;
|
||||
// define href
|
||||
obj.href = obj.protocol + '://' + host + (loc && loc.port === obj.port ? '' : (':' + obj.port));
|
||||
|
||||
return obj;
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"name": "socket.io-client",
|
||||
"version": "2.5.0",
|
||||
"keywords": [
|
||||
"realtime",
|
||||
"framework",
|
||||
"websocket",
|
||||
"tcp",
|
||||
"events",
|
||||
"client"
|
||||
],
|
||||
"main": "./lib/index",
|
||||
"files": [
|
||||
"lib/",
|
||||
"dist/"
|
||||
],
|
||||
"dependencies": {
|
||||
"backo2": "1.0.2",
|
||||
"component-bind": "1.0.0",
|
||||
"component-emitter": "~1.3.0",
|
||||
"debug": "~3.1.0",
|
||||
"engine.io-client": "~3.5.0",
|
||||
"has-binary2": "~1.0.2",
|
||||
"indexof": "0.0.1",
|
||||
"parseqs": "0.0.6",
|
||||
"parseuri": "0.0.6",
|
||||
"socket.io-parser": "~3.3.0",
|
||||
"to-array": "0.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.24.1",
|
||||
"babel-eslint": "4.1.7",
|
||||
"babel-loader": "7.0.0",
|
||||
"babel-preset-es2015": "6.24.1",
|
||||
"base64-arraybuffer": "^0.1.5",
|
||||
"concat-stream": "^1.6.0",
|
||||
"derequire": "^2.0.6",
|
||||
"eslint-config-standard": "4.4.0",
|
||||
"eslint-plugin-standard": "1.3.1",
|
||||
"expect.js": "0.3.1",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-eslint": "1.1.1",
|
||||
"gulp-file": "^0.3.0",
|
||||
"gulp-istanbul": "^1.1.1",
|
||||
"gulp-mocha": "^4.3.1",
|
||||
"gulp-task-listing": "1.0.1",
|
||||
"has-cors": "^1.1.0",
|
||||
"imports-loader": "^0.7.1",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^3.3.0",
|
||||
"socket.io": "2.3.0",
|
||||
"socket.io-browsers": "^1.0.0",
|
||||
"strip-loader": "0.1.2",
|
||||
"text-blob-builder": "0.0.1",
|
||||
"webpack-merge": "4.1.2",
|
||||
"webpack-stream": "3.2.0",
|
||||
"zuul": "~3.11.1",
|
||||
"zuul-builder-webpack": "^1.2.0",
|
||||
"zuul-ngrok": "4.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "gulp test"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Guillermo Rauch",
|
||||
"email": "rauchg@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Arnout Kazemier",
|
||||
"email": "info@3rd-eden.com"
|
||||
},
|
||||
{
|
||||
"name": "Vladimir Dronnikov",
|
||||
"email": "dronnikov@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Einar Otto Stangvik",
|
||||
"email": "einaros@gmail.com"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Automattic/socket.io-client.git"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
Reference in new issue
Block a user