Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

engine.io-as-websocket

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

engine.io-as-websocket - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/utils.js

32

dist/engine.io-as-websocket.min.js

@@ -45,7 +45,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.EngineIoSocket = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

function Polling(t){var e=t&&t.forceBase64;hasXHR2&&!e||(this.supportsBinary=!1),Transport.call(this,t)}var Transport=require("../transport"),parseqs=require("parseqs"),parser=require("engine.io-parser"),inherit=require("component-inherit"),yeast=require("yeast"),debug=require("debug")("engine.io-client:polling");module.exports=Polling;var hasXHR2=function(){var t=require("xmlhttprequest-ssl"),e=new t({xdomain:!1});return null!=e.responseType}();inherit(Polling,Transport),Polling.prototype.name="polling",Polling.prototype.doOpen=function(){this.poll()},Polling.prototype.pause=function(t){function e(){debug("paused"),i.readyState="paused",t()}var i=this;if(this.readyState="pausing",this.polling||!this.writable){var o=0;this.polling&&(debug("we are currently polling - waiting to pause"),o++,this.once("pollComplete",function(){debug("pre-pause polling complete"),--o||e()})),this.writable||(debug("we are currently writing - waiting to pause"),o++,this.once("drain",function(){debug("pre-pause writing complete"),--o||e()}))}else e()},Polling.prototype.poll=function(){debug("polling"),this.polling=!0,this.doPoll(),this.emit("poll")},Polling.prototype.onData=function(t){var e=this;debug("polling got data %s",t);var i=function(t,i,o){return"opening"==e.readyState&&e.onOpen(),"close"==t.type?(e.onClose(),!1):void e.onPacket(t)};parser.decodePayload(t,this.socket.binaryType,i),"closed"!=this.readyState&&(this.polling=!1,this.emit("pollComplete"),"open"==this.readyState?this.poll():debug('ignoring poll - transport state "%s"',this.readyState))},Polling.prototype.doClose=function(){function t(){debug("writing close packet"),e.write([{type:"close"}])}var e=this;"open"==this.readyState?(debug("transport open - closing"),t()):(debug("transport not open - deferring close"),this.once("open",t))},Polling.prototype.write=function(t){var e=this;this.writable=!1;var i=function(){e.writable=!0,e.emit("drain")},e=this;parser.encodePayload(t,this.supportsBinary,function(t){e.doWrite(t,i)})},Polling.prototype.uri=function(){var t=this.query||{},e=this.secure?"https":"http",i="";!1!==this.timestampRequests&&(t[this.timestampParam]=yeast()),this.supportsBinary||t.sid||(t.b64=1),t=parseqs.encode(t),this.port&&("https"==e&&443!=this.port||"http"==e&&80!=this.port)&&(i=":"+this.port),t.length&&(t="?"+t);var o=-1!==this.hostname.indexOf(":");return e+"://"+(o?"["+this.hostname+"]":this.hostname)+i+this.path+t};
},{"../transport":13,"component-inherit":7,"debug":8,"engine.io-parser":20,"parseqs":28,"xmlhttprequest-ssl":19,"yeast":31}],18:[function(require,module,exports){
},{"../transport":13,"component-inherit":7,"debug":8,"engine.io-parser":20,"parseqs":28,"xmlhttprequest-ssl":19,"yeast":37}],18:[function(require,module,exports){
(function (global){
function WS(e){var t=e&&e.forceBase64;t&&(this.supportsBinary=!1),this.perMessageDeflate=e.perMessageDeflate,Transport.call(this,e)}var Transport=require("../transport"),parser=require("engine.io-parser"),parseqs=require("parseqs"),inherit=require("component-inherit"),yeast=require("yeast"),debug=require("debug")("engine.io-client:websocket"),BrowserWebSocket=global.WebSocket||global.MozWebSocket,WebSocket=BrowserWebSocket;if(!WebSocket&&"undefined"==typeof window)try{WebSocket=require("ws")}catch(e){}module.exports=WS,inherit(WS,Transport),WS.prototype.name="websocket",WS.prototype.supportsBinary=!0,WS.prototype.doOpen=function(){if(this.check()){var e=this.uri(),t=void 0,s={agent:this.agent,perMessageDeflate:this.perMessageDeflate};s.pfx=this.pfx,s.key=this.key,s.passphrase=this.passphrase,s.cert=this.cert,s.ca=this.ca,s.ciphers=this.ciphers,s.rejectUnauthorized=this.rejectUnauthorized,this.extraHeaders&&(s.headers=this.extraHeaders),this.ws=BrowserWebSocket?new WebSocket(e):new WebSocket(e,t,s),void 0===this.ws.binaryType&&(this.supportsBinary=!1),this.ws.supports&&this.ws.supports.binary?(this.supportsBinary=!0,this.ws.binaryType="buffer"):this.ws.binaryType="arraybuffer",this.addEventListeners()}},WS.prototype.addEventListeners=function(){var e=this;this.ws.onopen=function(){e.onOpen()},this.ws.onclose=function(){e.onClose()},this.ws.onmessage=function(t){e.onData(t.data)},this.ws.onerror=function(t){e.onError("websocket error",t)}},"undefined"!=typeof navigator&&/iPad|iPhone|iPod/i.test(navigator.userAgent)&&(WS.prototype.onData=function(e){var t=this;setTimeout(function(){Transport.prototype.onData.call(t,e)},0)}),WS.prototype.write=function(e){function t(){s.emit("flush"),setTimeout(function(){s.writable=!0,s.emit("drain")},0)}var s=this;this.writable=!1;for(var r=e.length,o=0,i=r;i>o;o++)!function(e){parser.encodePacket(e,s.supportsBinary,function(o){if(!BrowserWebSocket){var i={};if(e.options&&(i.compress=e.options.compress),s.perMessageDeflate){var n="string"==typeof o?global.Buffer.byteLength(o):o.length;n<s.perMessageDeflate.threshold&&(i.compress=!1)}}try{BrowserWebSocket?s.ws.send(o):s.ws.send(o,i)}catch(a){debug("websocket closed before onclose event")}--r||t()})}(e[o])},WS.prototype.onClose=function(){Transport.prototype.onClose.call(this)},WS.prototype.doClose=function(){"undefined"!=typeof this.ws&&this.ws.close()},WS.prototype.uri=function(){var e=this.query||{},t=this.secure?"wss":"ws",s="";this.port&&("wss"==t&&443!=this.port||"ws"==t&&80!=this.port)&&(s=":"+this.port),this.timestampRequests&&(e[this.timestampParam]=yeast()),this.supportsBinary||(e.b64=1),e=parseqs.encode(e),e.length&&(e="?"+e);var r=-1!==this.hostname.indexOf(":");return t+"://"+(r?"["+this.hostname+"]":this.hostname)+s+this.path+e},WS.prototype.check=function(){return!(!WebSocket||"__initialize"in WebSocket&&this.name===WS.prototype.name)};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../transport":13,"component-inherit":7,"debug":8,"engine.io-parser":20,"parseqs":28,"ws":5,"yeast":31}],19:[function(require,module,exports){
},{"../transport":13,"component-inherit":7,"debug":8,"engine.io-parser":20,"parseqs":28,"ws":5,"yeast":37}],19:[function(require,module,exports){
var hasCORS=require("has-cors");module.exports=function(e){var t=e.xdomain,n=e.xscheme,r=e.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!t||hasCORS))return new XMLHttpRequest}catch(a){}try{if("undefined"!=typeof XDomainRequest&&!n&&r)return new XDomainRequest}catch(a){}if(!t)try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}};

@@ -56,3 +56,3 @@ },{"has-cors":24}],20:[function(require,module,exports){

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./keys":21,"after":1,"arraybuffer.slice":2,"base64-arraybuffer":3,"blob":4,"has-binary":22,"utf8":30}],21:[function(require,module,exports){
},{"./keys":21,"after":1,"arraybuffer.slice":2,"base64-arraybuffer":3,"blob":4,"has-binary":22,"utf8":36}],21:[function(require,module,exports){
module.exports=Object.keys||function(r){var e=[],t=Object.prototype.hasOwnProperty;for(var o in r)t.call(r,o)&&e.push(o);return e};

@@ -81,11 +81,27 @@ },{}],22:[function(require,module,exports){

(function (global){
!function(e){function o(e){throw new RangeError(T[e])}function n(e,o){for(var n=e.length,r=[];n--;)r[n]=o(e[n]);return r}function r(e,o){var r=e.split("@"),t="";r.length>1&&(t=r[0]+"@",e=r[1]),e=e.replace(S,".");var u=e.split("."),i=n(u,o).join(".");return t+i}function t(e){for(var o,n,r=[],t=0,u=e.length;u>t;)o=e.charCodeAt(t++),o>=55296&&56319>=o&&u>t?(n=e.charCodeAt(t++),56320==(64512&n)?r.push(((1023&o)<<10)+(1023&n)+65536):(r.push(o),t--)):r.push(o);return r}function u(e){return n(e,function(e){var o="";return e>65535&&(e-=65536,o+=P(e>>>10&1023|55296),e=56320|1023&e),o+=P(e)}).join("")}function i(e){return 10>e-48?e-22:26>e-65?e-65:26>e-97?e-97:b}function f(e,o){return e+22+75*(26>e)-((0!=o)<<5)}function c(e,o,n){var r=0;for(e=n?M(e/j):e>>1,e+=M(e/o);e>L*C>>1;r+=b)e=M(e/L);return M(r+(L+1)*e/(e+m))}function l(e){var n,r,t,f,l,s,d,a,p,h,v=[],g=e.length,w=0,m=I,j=A;for(r=e.lastIndexOf(E),0>r&&(r=0),t=0;r>t;++t)e.charCodeAt(t)>=128&&o("not-basic"),v.push(e.charCodeAt(t));for(f=r>0?r+1:0;g>f;){for(l=w,s=1,d=b;f>=g&&o("invalid-input"),a=i(e.charCodeAt(f++)),(a>=b||a>M((x-w)/s))&&o("overflow"),w+=a*s,p=j>=d?y:d>=j+C?C:d-j,!(p>a);d+=b)h=b-p,s>M(x/h)&&o("overflow"),s*=h;n=v.length+1,j=c(w-l,n,0==l),M(w/n)>x-m&&o("overflow"),m+=M(w/n),w%=n,v.splice(w++,0,m)}return u(v)}function s(e){var n,r,u,i,l,s,d,a,p,h,v,g,w,m,j,F=[];for(e=t(e),g=e.length,n=I,r=0,l=A,s=0;g>s;++s)v=e[s],128>v&&F.push(P(v));for(u=i=F.length,i&&F.push(E);g>u;){for(d=x,s=0;g>s;++s)v=e[s],v>=n&&d>v&&(d=v);for(w=u+1,d-n>M((x-r)/w)&&o("overflow"),r+=(d-n)*w,n=d,s=0;g>s;++s)if(v=e[s],n>v&&++r>x&&o("overflow"),v==n){for(a=r,p=b;h=l>=p?y:p>=l+C?C:p-l,!(h>a);p+=b)j=a-h,m=b-h,F.push(P(f(h+j%m,0))),a=M(j/m);F.push(P(f(a,0))),l=c(r,w,u==i),r=0,++u}++r,++n}return F.join("")}function d(e){return r(e,function(e){return F.test(e)?l(e.slice(4).toLowerCase()):e})}function a(e){return r(e,function(e){return O.test(e)?"xn--"+s(e):e})}var p="object"==typeof exports&&exports&&!exports.nodeType&&exports,h="object"==typeof module&&module&&!module.nodeType&&module,v="object"==typeof global&&global;v.global!==v&&v.window!==v&&v.self!==v||(e=v);var g,w,x=2147483647,b=36,y=1,C=26,m=38,j=700,A=72,I=128,E="-",F=/^xn--/,O=/[^\x20-\x7E]/,S=/[\x2E\u3002\uFF0E\uFF61]/g,T={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},L=b-y,M=Math.floor,P=String.fromCharCode;if(g={version:"1.4.1",ucs2:{decode:t,encode:u},decode:l,encode:s,toASCII:a,toUnicode:d},"function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return g});else if(p&&h)if(module.exports==p)h.exports=g;else for(w in g)g.hasOwnProperty(w)&&(p[w]=g[w]);else e.punycode=g}(this);
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],31:[function(require,module,exports){
"use strict";function hasOwnProperty(r,e){return Object.prototype.hasOwnProperty.call(r,e)}module.exports=function(r,e,t,n){e=e||"&",t=t||"=";var o={};if("string"!=typeof r||0===r.length)return o;var a=/\+/g;r=r.split(e);var s=1e3;n&&"number"==typeof n.maxKeys&&(s=n.maxKeys);var p=r.length;s>0&&p>s&&(p=s);for(var y=0;p>y;++y){var u,c,i,l,f=r[y].replace(a,"%20"),v=f.indexOf(t);v>=0?(u=f.substr(0,v),c=f.substr(v+1)):(u=f,c=""),i=decodeURIComponent(u),l=decodeURIComponent(c),hasOwnProperty(o,i)?isArray(o[i])?o[i].push(l):o[i]=[o[i],l]:o[i]=l}return o};var isArray=Array.isArray||function(r){return"[object Array]"===Object.prototype.toString.call(r)};
},{}],32:[function(require,module,exports){
"use strict";function map(r,e){if(r.map)return r.map(e);for(var t=[],n=0;n<r.length;n++)t.push(e(r[n],n));return t}var stringifyPrimitive=function(r){switch(typeof r){case"string":return r;case"boolean":return r?"true":"false";case"number":return isFinite(r)?r:"";default:return""}};module.exports=function(r,e,t,n){return e=e||"&",t=t||"=",null===r&&(r=void 0),"object"==typeof r?map(objectKeys(r),function(n){var i=encodeURIComponent(stringifyPrimitive(n))+t;return isArray(r[n])?map(r[n],function(r){return i+encodeURIComponent(stringifyPrimitive(r))}).join(e):i+encodeURIComponent(stringifyPrimitive(r[n]))}).join(e):n?encodeURIComponent(stringifyPrimitive(n))+t+encodeURIComponent(stringifyPrimitive(r)):""};var isArray=Array.isArray||function(r){return"[object Array]"===Object.prototype.toString.call(r)},objectKeys=Object.keys||function(r){var e=[];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&e.push(t);return e};
},{}],33:[function(require,module,exports){
"use strict";exports.decode=exports.parse=require("./decode"),exports.encode=exports.stringify=require("./encode");
},{"./decode":31,"./encode":32}],34:[function(require,module,exports){
"use strict";function Url(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function urlParse(t,s,e){if(t&&util.isObject(t)&&t instanceof Url)return t;var h=new Url;return h.parse(t,s,e),h}function urlFormat(t){return util.isString(t)&&(t=urlParse(t)),t instanceof Url?t.format():Url.prototype.format.call(t)}function urlResolve(t,s){return urlParse(t,!1,!0).resolve(s)}function urlResolveObject(t,s){return t?urlParse(t,!1,!0).resolveObject(s):s}var punycode=require("punycode"),util=require("./util");exports.parse=urlParse,exports.resolve=urlResolve,exports.resolveObject=urlResolveObject,exports.format=urlFormat,exports.Url=Url;var protocolPattern=/^([a-z0-9.+-]+:)/i,portPattern=/:[0-9]*$/,simplePathPattern=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,delims=["<",">",'"',"`"," ","\r","\n"," "],unwise=["{","}","|","\\","^","`"].concat(delims),autoEscape=["'"].concat(unwise),nonHostChars=["%","/","?",";","#"].concat(autoEscape),hostEndingChars=["/","?","#"],hostnameMaxLen=255,hostnamePartPattern=/^[+a-z0-9A-Z_-]{0,63}$/,hostnamePartStart=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,unsafeProtocol={javascript:!0,"javascript:":!0},hostlessProtocol={javascript:!0,"javascript:":!0},slashedProtocol={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},querystring=require("querystring");Url.prototype.parse=function(t,s,e){if(!util.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var h=t.indexOf("?"),r=-1!==h&&h<t.indexOf("#")?"?":"#",a=t.split(r),o=/\\/g;a[0]=a[0].replace(o,"/"),t=a.join(r);var n=t;if(n=n.trim(),!e&&1===t.split("#").length){var i=simplePathPattern.exec(n);if(i)return this.path=n,this.href=n,this.pathname=i[1],i[2]?(this.search=i[2],s?this.query=querystring.parse(this.search.substr(1)):this.query=this.search.substr(1)):s&&(this.search="",this.query={}),this}var l=protocolPattern.exec(n);if(l){l=l[0];var u=l.toLowerCase();this.protocol=u,n=n.substr(l.length)}if(e||l||n.match(/^\/\/[^@\/]+@[^@\/]+/)){var p="//"===n.substr(0,2);!p||l&&hostlessProtocol[l]||(n=n.substr(2),this.slashes=!0)}if(!hostlessProtocol[l]&&(p||l&&!slashedProtocol[l])){for(var c=-1,f=0;f<hostEndingChars.length;f++){var m=n.indexOf(hostEndingChars[f]);-1!==m&&(-1===c||c>m)&&(c=m)}var v,g;g=-1===c?n.lastIndexOf("@"):n.lastIndexOf("@",c),-1!==g&&(v=n.slice(0,g),n=n.slice(g+1),this.auth=decodeURIComponent(v)),c=-1;for(var f=0;f<nonHostChars.length;f++){var m=n.indexOf(nonHostChars[f]);-1!==m&&(-1===c||c>m)&&(c=m)}-1===c&&(c=n.length),this.host=n.slice(0,c),n=n.slice(c),this.parseHost(),this.hostname=this.hostname||"";var y="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!y)for(var P=this.hostname.split(/\./),f=0,d=P.length;d>f;f++){var q=P[f];if(q&&!q.match(hostnamePartPattern)){for(var b="",O=0,j=q.length;j>O;O++)b+=q.charCodeAt(O)>127?"x":q[O];if(!b.match(hostnamePartPattern)){var x=P.slice(0,f),U=P.slice(f+1),C=q.match(hostnamePartStart);C&&(x.push(C[1]),U.unshift(C[2])),U.length&&(n="/"+U.join(".")+n),this.hostname=x.join(".");break}}}this.hostname.length>hostnameMaxLen?this.hostname="":this.hostname=this.hostname.toLowerCase(),y||(this.hostname=punycode.toASCII(this.hostname));var A=this.port?":"+this.port:"",w=this.hostname||"";this.host=w+A,this.href+=this.host,y&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==n[0]&&(n="/"+n))}if(!unsafeProtocol[u])for(var f=0,d=autoEscape.length;d>f;f++){var E=autoEscape[f];if(-1!==n.indexOf(E)){var I=encodeURIComponent(E);I===E&&(I=escape(E)),n=n.split(E).join(I)}}var R=n.indexOf("#");-1!==R&&(this.hash=n.substr(R),n=n.slice(0,R));var S=n.indexOf("?");if(-1!==S?(this.search=n.substr(S),this.query=n.substr(S+1),s&&(this.query=querystring.parse(this.query)),n=n.slice(0,S)):s&&(this.search="",this.query={}),n&&(this.pathname=n),slashedProtocol[u]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var A=this.pathname||"",k=this.search||"";this.path=A+k}return this.href=this.format(),this},Url.prototype.format=function(){var t=this.auth||"";t&&(t=encodeURIComponent(t),t=t.replace(/%3A/i,":"),t+="@");var s=this.protocol||"",e=this.pathname||"",h=this.hash||"",r=!1,a="";this.host?r=t+this.host:this.hostname&&(r=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(r+=":"+this.port)),this.query&&util.isObject(this.query)&&Object.keys(this.query).length&&(a=querystring.stringify(this.query));var o=this.search||a&&"?"+a||"";return s&&":"!==s.substr(-1)&&(s+=":"),this.slashes||(!s||slashedProtocol[s])&&r!==!1?(r="//"+(r||""),e&&"/"!==e.charAt(0)&&(e="/"+e)):r||(r=""),h&&"#"!==h.charAt(0)&&(h="#"+h),o&&"?"!==o.charAt(0)&&(o="?"+o),e=e.replace(/[?#]/g,function(t){return encodeURIComponent(t)}),o=o.replace("#","%23"),s+r+e+o+h},Url.prototype.resolve=function(t){return this.resolveObject(urlParse(t,!1,!0)).format()},Url.prototype.resolveObject=function(t){if(util.isString(t)){var s=new Url;s.parse(t,!1,!0),t=s}for(var e=new Url,h=Object.keys(this),r=0;r<h.length;r++){var a=h[r];e[a]=this[a]}if(e.hash=t.hash,""===t.href)return e.href=e.format(),e;if(t.slashes&&!t.protocol){for(var o=Object.keys(t),n=0;n<o.length;n++){var i=o[n];"protocol"!==i&&(e[i]=t[i])}return slashedProtocol[e.protocol]&&e.hostname&&!e.pathname&&(e.path=e.pathname="/"),e.href=e.format(),e}if(t.protocol&&t.protocol!==e.protocol){if(!slashedProtocol[t.protocol]){for(var l=Object.keys(t),u=0;u<l.length;u++){var p=l[u];e[p]=t[p]}return e.href=e.format(),e}if(e.protocol=t.protocol,t.host||hostlessProtocol[t.protocol])e.pathname=t.pathname;else{for(var c=(t.pathname||"").split("/");c.length&&!(t.host=c.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==c[0]&&c.unshift(""),c.length<2&&c.unshift(""),e.pathname=c.join("/")}if(e.search=t.search,e.query=t.query,e.host=t.host||"",e.auth=t.auth,e.hostname=t.hostname||t.host,e.port=t.port,e.pathname||e.search){var f=e.pathname||"",m=e.search||"";e.path=f+m}return e.slashes=e.slashes||t.slashes,e.href=e.format(),e}var v=e.pathname&&"/"===e.pathname.charAt(0),g=t.host||t.pathname&&"/"===t.pathname.charAt(0),y=g||v||e.host&&t.pathname,P=y,d=e.pathname&&e.pathname.split("/")||[],c=t.pathname&&t.pathname.split("/")||[],q=e.protocol&&!slashedProtocol[e.protocol];if(q&&(e.hostname="",e.port=null,e.host&&(""===d[0]?d[0]=e.host:d.unshift(e.host)),e.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===c[0]?c[0]=t.host:c.unshift(t.host)),t.host=null),y=y&&(""===c[0]||""===d[0])),g)e.host=t.host||""===t.host?t.host:e.host,e.hostname=t.hostname||""===t.hostname?t.hostname:e.hostname,e.search=t.search,e.query=t.query,d=c;else if(c.length)d||(d=[]),d.pop(),d=d.concat(c),e.search=t.search,e.query=t.query;else if(!util.isNullOrUndefined(t.search)){if(q){e.hostname=e.host=d.shift();var b=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;b&&(e.auth=b.shift(),e.host=e.hostname=b.shift())}return e.search=t.search,e.query=t.query,util.isNull(e.pathname)&&util.isNull(e.search)||(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.href=e.format(),e}if(!d.length)return e.pathname=null,e.search?e.path="/"+e.search:e.path=null,e.href=e.format(),e;for(var O=d.slice(-1)[0],j=(e.host||t.host||d.length>1)&&("."===O||".."===O)||""===O,x=0,U=d.length;U>=0;U--)O=d[U],"."===O?d.splice(U,1):".."===O?(d.splice(U,1),x++):x&&(d.splice(U,1),x--);if(!y&&!P)for(;x--;x)d.unshift("..");!y||""===d[0]||d[0]&&"/"===d[0].charAt(0)||d.unshift(""),j&&"/"!==d.join("/").substr(-1)&&d.push("");var C=""===d[0]||d[0]&&"/"===d[0].charAt(0);if(q){e.hostname=e.host=C?"":d.length?d.shift():"";var b=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;b&&(e.auth=b.shift(),e.host=e.hostname=b.shift())}return y=y||e.host&&d.length,y&&!C&&d.unshift(""),d.length?e.pathname=d.join("/"):(e.pathname=null,e.path=null),util.isNull(e.pathname)&&util.isNull(e.search)||(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.auth=t.auth||e.auth,e.slashes=e.slashes||t.slashes,e.href=e.format(),e},Url.prototype.parseHost=function(){var t=this.host,s=portPattern.exec(t);s&&(s=s[0],":"!==s&&(this.port=s.substr(1)),t=t.substr(0,t.length-s.length)),t&&(this.hostname=t)};
},{"./util":35,"punycode":30,"querystring":33}],35:[function(require,module,exports){
"use strict";module.exports={isString:function(n){return"string"==typeof n},isObject:function(n){return"object"==typeof n&&null!==n},isNull:function(n){return null===n},isNullOrUndefined:function(n){return null==n}};
},{}],36:[function(require,module,exports){
(function (global){
!function(r){function e(r){for(var e,t,n=[],o=0,i=r.length;i>o;)e=r.charCodeAt(o++),e>=55296&&56319>=e&&i>o?(t=r.charCodeAt(o++),56320==(64512&t)?n.push(((1023&e)<<10)+(1023&t)+65536):(n.push(e),o--)):n.push(e);return n}function t(r){for(var e,t=r.length,n=-1,o="";++n<t;)e=r[n],e>65535&&(e-=65536,o+=b(e>>>10&1023|55296),e=56320|1023&e),o+=b(e);return o}function n(r){if(r>=55296&&57343>=r)throw Error("Lone surrogate U+"+r.toString(16).toUpperCase()+" is not a scalar value")}function o(r,e){return b(r>>e&63|128)}function i(r){if(0==(4294967168&r))return b(r);var e="";return 0==(4294965248&r)?e=b(r>>6&31|192):0==(4294901760&r)?(n(r),e=b(r>>12&15|224),e+=o(r,6)):0==(4292870144&r)&&(e=b(r>>18&7|240),e+=o(r,12),e+=o(r,6)),e+=b(63&r|128)}function f(r){for(var t,n=e(r),o=n.length,f=-1,u="";++f<o;)t=n[f],u+=i(t);return u}function u(){if(p>=s)throw Error("Invalid byte index");var r=255&v[p];if(p++,128==(192&r))return 63&r;throw Error("Invalid continuation byte")}function a(){var r,e,t,o,i;if(p>s)throw Error("Invalid byte index");if(p==s)return!1;if(r=255&v[p],p++,0==(128&r))return r;if(192==(224&r)){var e=u();if(i=(31&r)<<6|e,i>=128)return i;throw Error("Invalid continuation byte")}if(224==(240&r)){if(e=u(),t=u(),i=(15&r)<<12|e<<6|t,i>=2048)return n(i),i;throw Error("Invalid continuation byte")}if(240==(248&r)&&(e=u(),t=u(),o=u(),i=(15&r)<<18|e<<12|t<<6|o,i>=65536&&1114111>=i))return i;throw Error("Invalid UTF-8 detected")}function d(r){v=e(r),s=v.length,p=0;for(var n,o=[];(n=a())!==!1;)o.push(n);return t(o)}var l="object"==typeof exports&&exports,c="object"==typeof module&&module&&module.exports==l&&module,h="object"==typeof global&&global;h.global!==h&&h.window!==h||(r=h);var v,s,p,b=String.fromCharCode,y={version:"2.0.0",encode:f,decode:d};if("function"==typeof define&&"object"==typeof define.amd&&define.amd)define(function(){return y});else if(l&&!l.nodeType)if(c)c.exports=y;else{var g={},w=g.hasOwnProperty;for(var m in y)w.call(y,m)&&(l[m]=y[m])}else r.utf8=y}(this);
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],31:[function(require,module,exports){
},{}],37:[function(require,module,exports){
"use strict";function encode(e){var t="";do t=alphabet[e%length]+t,e=Math.floor(e/length);while(e>0);return t}function decode(e){var t=0;for(i=0;i<e.length;i++)t=t*length+map[e.charAt(i)];return t}function yeast(){var e=encode(+new Date);return e!==prev?(seed=0,prev=e):e+"."+encode(seed++)}for(var alphabet="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),length=64,map={},seed=0,i=0,prev;length>i;i++)map[alphabet[i]]=i;yeast.encode=encode,yeast.decode=decode,module.exports=yeast;
},{}],32:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),_engine=require("engine.io-client"),_engine2=_interopRequireDefault(_engine),readyStateStringToValue=new Map([["opening",0],["open",1],["closing",2],["closed",3]]),EngineIoSocket=function(){function e(t){var n=this;_classCallCheck(this,e),this.onopen=null,this.onclose=null,this.onmessage=null,this.onerror=null,this.eioSocket=new _engine2["default"](t),this.url=t,this.extensions="",this.protocol="",this.bufferedAmount=void 0,this.setReadyState(),this.eioSocket.on("open",function(){if(n.setReadyState(),null!=n.onopen){var e=new Event("open");n.onopen.call(n,e)}}),this.eioSocket.on("close",function(e,t){if(n.setReadyState(),null!=n.onclose){var o=new Event("close");o.reason=e,o.code=1001,o.wasClean=!1,n.onclose.call(n,o)}}),this.eioSocket.on("message",function(e){if(n.setReadyState(),null!=n.onmessage){var t=Object.assign(new Event("message"),{data:e});n.onmessage.call(n,t)}}),this.eioSocket.on("error",function(){if(n.setReadyState(),null!=n.onerror){var e=new Event("error");n.onerror.call(n,e)}})}return _createClass(e,[{key:"setReadyState",value:function(){this.readyState=readyStateStringToValue.get(this.eioSocket.readyState)}},{key:"send",value:function(e){this.eioSocket.send(e),this.setReadyState()}},{key:"close",value:function(){this.eioSocket.close(),this.setReadyState()}}]),e}();exports["default"]=EngineIoSocket;
},{"engine.io-client":10}],33:[function(require,module,exports){
},{}],38:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),_engine=require("engine.io-client"),_engine2=_interopRequireDefault(_engine),_utils=require("./utils"),readyStateStringToValue=new Map([["opening",0],["open",1],["closing",2],["closed",3]]),EngineIoSocket=function(){function e(t){var n=this;_classCallCheck(this,e);var o=(0,_utils.splitHref)(t),i=o.uri,a=o.path;this.onopen=null,this.onclose=null,this.onmessage=null,this.onerror=null,this.eioSocket=new _engine2["default"](i,{path:a}),this.url=t,this.extensions="",this.protocol="",this.bufferedAmount=void 0,this.setReadyState(),this.eioSocket.on("open",function(){if(n.setReadyState(),null!=n.onopen){var e=new Event("open");n.onopen.call(n,e)}}),this.eioSocket.on("close",function(e,t){if(n.setReadyState(),null!=n.onclose){var o=new Event("close");o.reason=e,o.code=1001,o.wasClean=!1,n.onclose.call(n,o)}}),this.eioSocket.on("message",function(e){if(n.setReadyState(),null!=n.onmessage){var t=Object.assign(new Event("message"),{data:e});n.onmessage.call(n,t)}}),this.eioSocket.on("error",function(){if(n.setReadyState(),null!=n.onerror){var e=new Event("error");n.onerror.call(n,e)}})}return _createClass(e,[{key:"setReadyState",value:function(){this.readyState=readyStateStringToValue.get(this.eioSocket.readyState)}},{key:"send",value:function(e){this.eioSocket.send(e),this.setReadyState()}},{key:"close",value:function(){this.eioSocket.close(),this.setReadyState()}}]),e}();exports["default"]=EngineIoSocket;
},{"./utils":40,"engine.io-client":10}],39:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}var _EngineIoSocket=require("./EngineIoSocket"),_EngineIoSocket2=_interopRequireDefault(_EngineIoSocket);module.exports=_EngineIoSocket2["default"];
},{"./EngineIoSocket":32}]},{},[33])(33)
},{"./EngineIoSocket":38}],40:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function splitHref(e){var r=_url2["default"].parse(e),t=r.protocol,u=r.slashes,l=r.auth,o=r.host,s=r.pathname,a=_url2["default"].format({protocol:t,slashes:u,auth:l,host:o}),i=null!=s?s:"/";return{uri:a,path:i}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitHref=splitHref;var _url=require("url"),_url2=_interopRequireDefault(_url);
},{"url":34}]},{},[39])(39)
});

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -9,6 +9,8 @@ Object.defineProperty(exports, "__esModule", {

var _engine = require('engine.io-client');
var _engine = require("engine.io-client");
var _engine2 = _interopRequireDefault(_engine);
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -26,2 +28,8 @@

var _splitHref = (0, _utils.splitHref)(url);
var uri = _splitHref.uri;
var path = _splitHref.path;
this.onopen = null;

@@ -31,3 +39,3 @@ this.onclose = null;

this.onerror = null;
this.eioSocket = new _engine2.default(url);
this.eioSocket = new _engine2.default(uri, { path: path });
this.url = url;

@@ -81,3 +89,3 @@ this.extensions = "";

_createClass(EngineIoSocket, [{
key: 'setReadyState',
key: "setReadyState",
value: function setReadyState() {

@@ -87,3 +95,3 @@ this.readyState = readyStateStringToValue.get(this.eioSocket.readyState);

}, {
key: 'send',
key: "send",
value: function send(message) {

@@ -94,3 +102,3 @@ this.eioSocket.send(message);

}, {
key: 'close',
key: "close",
value: function close() {

@@ -97,0 +105,0 @@ this.eioSocket.close();

{
"name": "engine.io-as-websocket",
"version": "1.0.0",
"version": "1.1.0",
"description": "Wraps Engine.IO to make it usable with the same API as WebSocket",

@@ -35,3 +35,4 @@ "main": "lib/index.js",

"build:umd:min": "mkdir -p dist && cross-env BABEL_ENV=browserify NODE_ENV=production browserify src/browser.js -s EngineIoSocket -o dist/engine.io-as-websocket.min.js -t [ babelify --presets [ es2015 ] ] -p [ minifyify --no-map ]",
"prepublish": "npm run clean && npm run build"
"prepublish": "npm run clean && npm run build",
"test": "babel-node --presets es2015 test/*.js"
},

@@ -46,4 +47,5 @@ "devDependencies": {

"minifyify": "^7.3.3",
"rimraf": "^2.5.2"
"rimraf": "^2.5.2",
"tape": "^4.6.2"
}
}
import EngineIoClient from "engine.io-client";
import { splitHref } from "./utils";
const readyStateStringToValue = new Map([

@@ -12,2 +14,5 @@ [ 'opening', 0 ],

constructor(url) {
const { uri, path } = splitHref(url);
this.onopen = null;

@@ -17,3 +22,3 @@ this.onclose = null;

this.onerror = null;
this.eioSocket = new EngineIoClient(url);
this.eioSocket = new EngineIoClient(uri, { path });
this.url = url;

@@ -20,0 +25,0 @@ this.extensions = "";

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc