websocket-async
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,1 +0,1 @@ | ||
function createCommonjsModule(e,t){return t={exports:{}},e(t,t.exports),t.exports}var runtime=createCommonjsModule(function(e){!function(t){"use strict";function r(e,t,r,n){var i=t&&t.prototype instanceof o?t:o,a=Object.create(i.prototype),u=new v(n||[]);return a._invoke=s(e,r,u),a}function n(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}function o(){}function i(){}function a(){}function u(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function c(e){function t(r,o,i,a){var u=n(e[r],e,o);if("throw"!==u.type){var c=u.arg,s=c.value;return s&&"object"==typeof s&&m.call(s,"__await")?Promise.resolve(s.__await).then(function(e){t("next",e,i,a)},function(e){t("throw",e,i,a)}):Promise.resolve(s).then(function(e){c.value=e,i(c)},a)}a(u.arg)}var r;this._invoke=function(e,n){function o(){return new Promise(function(r,o){t(e,n,r,o)})}return r=r?r.then(o,o):o()}}function s(e,t,r){var o=E;return function(i,a){if(o===C)throw new Error("Generator is already running");if(o===j){if("throw"===i)throw a;return y()}for(r.method=i,r.arg=a;;){var u=r.delegate;if(u){var c=h(u,r);if(c){if(c===O)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===E)throw o=j,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=C;var s=n(e,t,r);if("normal"===s.type){if(o=r.done?j:L,s.arg===O)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(o=j,r.method="throw",r.arg=s.arg)}}}function h(e,t){var r=e.iterator[t.method];if(r===d){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=d,h(e,t),"throw"===t.method))return O;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return O}var o=n(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,O;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=d),t.delegate=null,O):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,O)}function l(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function f(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function v(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(l,this),this.reset(!0)}function p(e){if(e){var t=e[k];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(m.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=d,t.done=!0,t};return n.next=n}}return{next:y}}function y(){return{value:d,done:!0}}var d,g=Object.prototype,m=g.hasOwnProperty,w="function"==typeof Symbol?Symbol:{},k=w.iterator||"@@iterator",x=w.asyncIterator||"@@asyncIterator",b=w.toStringTag||"@@toStringTag",_=t.regeneratorRuntime;if(_)e.exports=_;else{(_=t.regeneratorRuntime=e.exports).wrap=r;var E="suspendedStart",L="suspendedYield",C="executing",j="completed",O={},P={};P[k]=function(){return this};var G=Object.getPrototypeOf,R=G&&G(G(p([])));R&&R!==g&&m.call(R,k)&&(P=R);var S=a.prototype=o.prototype=Object.create(P);i.prototype=S.constructor=a,a.constructor=i,a[b]=i.displayName="GeneratorFunction",_.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===i||"GeneratorFunction"===(t.displayName||t.name))},_.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,a):(e.__proto__=a,b in e||(e[b]="GeneratorFunction")),e.prototype=Object.create(S),e},_.awrap=function(e){return{__await:e}},u(c.prototype),c.prototype[x]=function(){return this},_.AsyncIterator=c,_.async=function(e,t,n,o){var i=new c(r(e,t,n,o));return _.isGeneratorFunction(t)?i:i.next().then(function(e){return e.done?e.value:i.next()})},u(S),S[b]="Generator",S[k]=function(){return this},S.toString=function(){return"[object Generator]"},_.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},_.values=p,v.prototype={constructor:v,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=d,this.done=!1,this.delegate=null,this.method="next",this.arg=d,this.tryEntries.forEach(f),!e)for(var t in this)"t"===t.charAt(0)&&m.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=d)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=d),!!n}if(this.done)throw e;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=m.call(o,"catchLoc"),u=m.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&m.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,O):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),O},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),f(r),O}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;f(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:p(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=d),O}}}}(function(){return this}()||Function("return this")())}),g=function(){return this}()||Function("return this")(),hadRuntime=g.regeneratorRuntime&&Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime")>=0,oldRuntime=hadRuntime&&g.regeneratorRuntime;g.regeneratorRuntime=void 0;var runtimeModule=runtime;if(hadRuntime)g.regeneratorRuntime=oldRuntime;else try{delete g.regeneratorRuntime}catch(e){g.regeneratorRuntime=void 0}var regenerator=runtimeModule,asyncGenerator=function(){function e(e){this.value=e}function t(t){function r(o,i){try{var a=t[o](i),u=a.value;u instanceof e?Promise.resolve(u.value).then(function(e){r("next",e)},function(e){r("throw",e)}):n(a.done?"return":"normal",a.value)}catch(e){n("throw",e)}}function n(e,t){switch(e){case"return":o.resolve({value:t,done:!0});break;case"throw":o.reject(t);break;default:o.resolve({value:t,done:!1})}(o=o.next)?r(o.key,o.arg):i=null}var o,i;this._invoke=function(e,t){return new Promise(function(n,a){var u={key:e,arg:t,resolve:n,reject:a,next:null};i?i=i.next=u:(o=i=u,r(e,t))})},"function"!=typeof t.return&&(this.return=void 0)}return"function"==typeof Symbol&&Symbol.asyncIterator&&(t.prototype[Symbol.asyncIterator]=function(){return this}),t.prototype.next=function(e){return this._invoke("next",e)},t.prototype.throw=function(e){return this._invoke("throw",e)},t.prototype.return=function(e){return this._invoke("return",e)},{wrap:function(e){return function(){return new t(e.apply(this,arguments))}},await:function(t){return new e(t)}}}(),asyncToGenerator=function(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,r){function n(o,i){try{var a=t[o](i),u=a.value}catch(e){return void r(e)}if(!a.done)return Promise.resolve(u).then(function(e){n("next",e)},function(e){n("throw",e)});e(u)}return n("next")})}},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),WebSocketClient=function(){function e(){classCallCheck(this,e),this._reset()}return createClass(e,[{key:"connect",value:function(){var e=asyncToGenerator(regenerator.mark(function e(t,r){return regenerator.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.disconnect();case 2:return this._reset(),this._socket=new WebSocket(t,r),this._socket.binaryType="arraybuffer",e.next=7,this._setupListenersOnConnect();case 7:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"send",value:function(e){if(!this.connected)throw this._closeEvent||new Error("Not connected.");this._socket.send(e)}},{key:"receive",value:function(){var e=asyncToGenerator(regenerator.mark(function e(){var t,r=this;return regenerator.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(0===this._receiveDataQueue.length){e.next=2;break}return e.abrupt("return",this._receiveDataQueue.shift());case 2:if(this.connected){e.next=4;break}throw this._closeEvent||new Error("Not connected.");case 4:return t=new Promise(function(e,t){r._receiveCallbacksQueue.push({resolve:e,reject:t})}),e.next=7,t;case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"disconnect",value:function(){var e=asyncToGenerator(regenerator.mark(function e(t,r){var n=this;return regenerator.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connected){e.next=2;break}return e.abrupt("return",this._closeEvent);case 2:return e.next=4,new Promise(function(e,o){var i={resolve:function(e){n._receiveCallbacksQueue.push(i)},reject:e};n._receiveCallbacksQueue.push(i),n._socket.close(t,r)});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"_setupListenersOnConnect",value:function(){var e=asyncToGenerator(regenerator.mark(function e(){var t,r=this;return regenerator.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this._socket,e.next=3,new Promise(function(e,n){var o=function(e){var t=e;0===r._receiveCallbacksQueue.length?r._receiveDataQueue.push(t.data):r._receiveCallbacksQueue.shift().resolve(t.data)};t.addEventListener("error",n),t.addEventListener("open",function(n){t.addEventListener("message",o),t.addEventListener("close",function(e){for(r._closeEvent=e;0!==r._receiveCallbacksQueue.length;)r._receiveCallbacksQueue.shift().reject(r._closeEvent)}),e()})});case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"_reset",value:function(){this._receiveDataQueue=[],this._receiveCallbacksQueue=[],this._closeEvent=null}},{key:"connected",get:function(){return null!=this._socket&&this._socket.readyState===WebSocket.OPEN}},{key:"dataAvailable",get:function(){return this._receiveDataQueue.length}}]),e}();export default WebSocketClient; | ||
function createCommonjsModule(e,t){return t={exports:{}},e(t,t.exports),t.exports}function _asyncToGenerator(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,r){function n(o,i){try{var a=t[o](i),c=a.value}catch(e){return void r(e)}if(!a.done)return Promise.resolve(c).then(function(e){n("next",e)},function(e){n("throw",e)});e(c)}return n("next")})}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var runtime=createCommonjsModule(function(e){!function(t){"use strict";function r(e,t,r,n){var i=t&&t.prototype instanceof o?t:o,a=Object.create(i.prototype),c=new p(n||[]);return a._invoke=s(e,r,c),a}function n(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}function o(){}function i(){}function a(){}function c(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function u(e){function t(r,o,i,a){var c=n(e[r],e,o);if("throw"!==c.type){var u=c.arg,s=u.value;return s&&"object"==typeof s&&m.call(s,"__await")?Promise.resolve(s.__await).then(function(e){t("next",e,i,a)},function(e){t("throw",e,i,a)}):Promise.resolve(s).then(function(e){u.value=e,i(u)},a)}a(c.arg)}var r;this._invoke=function(e,n){function o(){return new Promise(function(r,o){t(e,n,r,o)})}return r=r?r.then(o,o):o()}}function s(e,t,r){var o=E;return function(i,a){if(o===C)throw new Error("Generator is already running");if(o===O){if("throw"===i)throw a;return y()}for(r.method=i,r.arg=a;;){var c=r.delegate;if(c){var u=h(c,r);if(u){if(u===j)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===E)throw o=O,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=C;var s=n(e,t,r);if("normal"===s.type){if(o=r.done?O:L,s.arg===j)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(o=O,r.method="throw",r.arg=s.arg)}}}function h(e,t){var r=e.iterator[t.method];if(r===d){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=d,h(e,t),"throw"===t.method))return j;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return j}var o=n(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,j;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=d),t.delegate=null,j):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,j)}function l(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function f(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function p(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(l,this),this.reset(!0)}function v(e){if(e){var t=e[_];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(m.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=d,t.done=!0,t};return n.next=n}}return{next:y}}function y(){return{value:d,done:!0}}var d,g=Object.prototype,m=g.hasOwnProperty,w="function"==typeof Symbol?Symbol:{},_=w.iterator||"@@iterator",x=w.asyncIterator||"@@asyncIterator",b=w.toStringTag||"@@toStringTag",k=t.regeneratorRuntime;if(k)e.exports=k;else{(k=t.regeneratorRuntime=e.exports).wrap=r;var E="suspendedStart",L="suspendedYield",C="executing",O="completed",j={},P={};P[_]=function(){return this};var R=Object.getPrototypeOf,G=R&&R(R(v([])));G&&G!==g&&m.call(G,_)&&(P=G);var Q=a.prototype=o.prototype=Object.create(P);i.prototype=Q.constructor=a,a.constructor=i,a[b]=i.displayName="GeneratorFunction",k.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===i||"GeneratorFunction"===(t.displayName||t.name))},k.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,a):(e.__proto__=a,b in e||(e[b]="GeneratorFunction")),e.prototype=Object.create(Q),e},k.awrap=function(e){return{__await:e}},c(u.prototype),u.prototype[x]=function(){return this},k.AsyncIterator=u,k.async=function(e,t,n,o){var i=new u(r(e,t,n,o));return k.isGeneratorFunction(t)?i:i.next().then(function(e){return e.done?e.value:i.next()})},c(Q),Q[b]="Generator",Q[_]=function(){return this},Q.toString=function(){return"[object Generator]"},k.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},k.values=v,p.prototype={constructor:p,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=d,this.done=!1,this.delegate=null,this.method="next",this.arg=d,this.tryEntries.forEach(f),!e)for(var t in this)"t"===t.charAt(0)&&m.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=d)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=d),!!n}if(this.done)throw e;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=m.call(o,"catchLoc"),c=m.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&m.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,j):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),j},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),f(r),j}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;f(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:v(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=d),j}}}}(function(){return this}()||Function("return this")())}),g=function(){return this}()||Function("return this")(),hadRuntime=g.regeneratorRuntime&&Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime")>=0,oldRuntime=hadRuntime&&g.regeneratorRuntime;g.regeneratorRuntime=void 0;var runtimeModule=runtime;if(hadRuntime)g.regeneratorRuntime=oldRuntime;else try{delete g.regeneratorRuntime}catch(e){g.regeneratorRuntime=void 0}var regenerator=runtimeModule,_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),WebSocketClient=function(){function e(){_classCallCheck(this,e),this._reset()}return _createClass(e,[{key:"connect",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(t,r){return regenerator.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.disconnect();case 2:return this._reset(),this._socket=new WebSocket(t,r),this._socket.binaryType="arraybuffer",e.next=7,this._setupListenersOnConnect();case 7:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"send",value:function(e){if(!this.connected)throw this._closeEvent||new Error("Not connected.");this._socket.send(e)}},{key:"receive",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,r=this;return regenerator.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(0===this._receiveDataQueue.length){e.next=2;break}return e.abrupt("return",this._receiveDataQueue.shift());case 2:if(this.connected){e.next=4;break}throw this._closeEvent||new Error("Not connected.");case 4:return t=new Promise(function(e,t){r._receiveCallbacksQueue.push({resolve:e,reject:t})}),e.next=7,t;case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"disconnect",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(t,r){var n=this;return regenerator.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connected){e.next=2;break}return e.abrupt("return",this._closeEvent);case 2:return e.next=4,new Promise(function(e,o){var i={resolve:function(e){n._receiveCallbacksQueue.push(i)},reject:e};n._receiveCallbacksQueue.push(i),n._socket.close(t,r)});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"_setupListenersOnConnect",value:function(){var e=_asyncToGenerator(regenerator.mark(function e(){var t,r=this;return regenerator.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this._socket,e.next=3,new Promise(function(e,n){var o=function(e){var t=e;0===r._receiveCallbacksQueue.length?r._receiveDataQueue.push(t.data):r._receiveCallbacksQueue.shift().resolve(t.data)};t.addEventListener("error",n),t.addEventListener("open",function(n){t.addEventListener("message",o),t.addEventListener("close",function(e){for(r._closeEvent=e;0!==r._receiveCallbacksQueue.length;)r._receiveCallbacksQueue.shift().reject(r._closeEvent)}),e()})});case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"_reset",value:function(){this._receiveDataQueue=[],this._receiveCallbacksQueue=[],this._closeEvent=null}},{key:"connected",get:function(){return null!=this._socket&&this._socket.readyState===WebSocket.OPEN}},{key:"dataAvailable",get:function(){return this._receiveDataQueue.length}}]),e}();export default WebSocketClient; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.WebSocketClient=e()}(this,function(){"use strict";var t=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t){!function(e){function r(t,e,r,n){var i=e&&e.prototype instanceof o?e:o,a=Object.create(i.prototype),u=new v(n||[]);return a._invoke=s(t,r,u),a}function n(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}function o(){}function i(){}function a(){}function u(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function c(t){function e(r,o,i,a){var u=n(t[r],t,o);if("throw"!==u.type){var c=u.arg,s=c.value;return s&&"object"==typeof s&&g.call(s,"__await")?Promise.resolve(s.__await).then(function(t){e("next",t,i,a)},function(t){e("throw",t,i,a)}):Promise.resolve(s).then(function(t){c.value=t,i(c)},a)}a(u.arg)}var r;this._invoke=function(t,n){function o(){return new Promise(function(r,o){e(t,n,r,o)})}return r=r?r.then(o,o):o()}}function s(t,e,r){var o=E;return function(i,a){if(o===j)throw new Error("Generator is already running");if(o===O){if("throw"===i)throw a;return y()}for(r.method=i,r.arg=a;;){var u=r.delegate;if(u){var c=f(u,r);if(c){if(c===P)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===E)throw o=O,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=j;var s=n(t,e,r);if("normal"===s.type){if(o=r.done?O:L,s.arg===P)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(o=O,r.method="throw",r.arg=s.arg)}}}function f(t,e){var r=t.iterator[e.method];if(r===d){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=d,f(t,e),"throw"===e.method))return P;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return P}var o=n(r,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,P;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=d),e.delegate=null,P):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,P)}function h(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function l(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function v(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(h,this),this.reset(!0)}function p(t){if(t){var e=t[x];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r<t.length;)if(g.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=d,e.done=!0,e};return n.next=n}}return{next:y}}function y(){return{value:d,done:!0}}var d,m=Object.prototype,g=m.hasOwnProperty,w="function"==typeof Symbol?Symbol:{},x=w.iterator||"@@iterator",b=w.asyncIterator||"@@asyncIterator",k=w.toStringTag||"@@toStringTag",_=e.regeneratorRuntime;if(_)t.exports=_;else{(_=e.regeneratorRuntime=t.exports).wrap=r;var E="suspendedStart",L="suspendedYield",j="executing",O="completed",P={},Q={};Q[x]=function(){return this};var S=Object.getPrototypeOf,C=S&&S(S(p([])));C&&C!==m&&g.call(C,x)&&(Q=C);var N=a.prototype=o.prototype=Object.create(Q);i.prototype=N.constructor=a,a.constructor=i,a[k]=i.displayName="GeneratorFunction",_.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===i||"GeneratorFunction"===(e.displayName||e.name))},_.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,a):(t.__proto__=a,k in t||(t[k]="GeneratorFunction")),t.prototype=Object.create(N),t},_.awrap=function(t){return{__await:t}},u(c.prototype),c.prototype[b]=function(){return this},_.AsyncIterator=c,_.async=function(t,e,n,o){var i=new c(r(t,e,n,o));return _.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},u(N),N[k]="Generator",N[x]=function(){return this},N.toString=function(){return"[object Generator]"},_.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},_.values=p,v.prototype={constructor:v,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=d,this.done=!1,this.delegate=null,this.method="next",this.arg=d,this.tryEntries.forEach(l),!t)for(var e in this)"t"===e.charAt(0)&&g.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=d)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){function e(e,n){return i.type="throw",i.arg=t,r.next=e,n&&(r.method="next",r.arg=d),!!n}if(this.done)throw t;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],i=o.completion;if("root"===o.tryLoc)return e("end");if(o.tryLoc<=this.prev){var a=g.call(o,"catchLoc"),u=g.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return e(o.catchLoc,!0);if(this.prev<o.finallyLoc)return e(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return e(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return e(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&g.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,P):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),P},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),l(r),P}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;l(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:p(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=d),P}}}}(function(){return this}()||Function("return this")())}),e=function(){return this}()||Function("return this")(),r=e.regeneratorRuntime&&Object.getOwnPropertyNames(e).indexOf("regeneratorRuntime")>=0,n=r&&e.regeneratorRuntime;e.regeneratorRuntime=void 0;var o=t;if(r)e.regeneratorRuntime=n;else try{delete e.regeneratorRuntime}catch(t){e.regeneratorRuntime=void 0}var i=o,a=(function(){function t(t){this.value=t}function e(e){function r(o,i){try{var a=e[o](i),u=a.value;u instanceof t?Promise.resolve(u.value).then(function(t){r("next",t)},function(t){r("throw",t)}):n(a.done?"return":"normal",a.value)}catch(t){n("throw",t)}}function n(t,e){switch(t){case"return":o.resolve({value:e,done:!0});break;case"throw":o.reject(e);break;default:o.resolve({value:e,done:!1})}(o=o.next)?r(o.key,o.arg):i=null}var o,i;this._invoke=function(t,e){return new Promise(function(n,a){var u={key:t,arg:e,resolve:n,reject:a,next:null};i?i=i.next=u:(o=i=u,r(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t){return function(){var e=t.apply(this,arguments);return new Promise(function(t,r){function n(o,i){try{var a=e[o](i),u=a.value}catch(t){return void r(t)}if(!a.done)return Promise.resolve(u).then(function(t){n("next",t)},function(t){n("throw",t)});t(u)}return n("next")})}}),u=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},c=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();return function(){function t(){u(this,t),this._reset()}return c(t,[{key:"connect",value:function(){var t=a(i.mark(function t(e,r){return i.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.disconnect();case 2:return this._reset(),this._socket=new WebSocket(e,r),this._socket.binaryType="arraybuffer",t.next=7,this._setupListenersOnConnect();case 7:case"end":return t.stop()}},t,this)}));return function(e,r){return t.apply(this,arguments)}}()},{key:"send",value:function(t){if(!this.connected)throw this._closeEvent||new Error("Not connected.");this._socket.send(t)}},{key:"receive",value:function(){var t=a(i.mark(function t(){var e,r=this;return i.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(0===this._receiveDataQueue.length){t.next=2;break}return t.abrupt("return",this._receiveDataQueue.shift());case 2:if(this.connected){t.next=4;break}throw this._closeEvent||new Error("Not connected.");case 4:return e=new Promise(function(t,e){r._receiveCallbacksQueue.push({resolve:t,reject:e})}),t.next=7,e;case 7:return t.abrupt("return",t.sent);case 8:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"disconnect",value:function(){var t=a(i.mark(function t(e,r){var n=this;return i.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.connected){t.next=2;break}return t.abrupt("return",this._closeEvent);case 2:return t.next=4,new Promise(function(t,o){var i={resolve:function(t){n._receiveCallbacksQueue.push(i)},reject:t};n._receiveCallbacksQueue.push(i),n._socket.close(e,r)});case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}},t,this)}));return function(e,r){return t.apply(this,arguments)}}()},{key:"_setupListenersOnConnect",value:function(){var t=a(i.mark(function t(){var e,r=this;return i.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=this._socket,t.next=3,new Promise(function(t,n){var o=function(t){var e=t;0===r._receiveCallbacksQueue.length?r._receiveDataQueue.push(e.data):r._receiveCallbacksQueue.shift().resolve(e.data)};e.addEventListener("error",n),e.addEventListener("open",function(n){e.addEventListener("message",o),e.addEventListener("close",function(t){for(r._closeEvent=t;0!==r._receiveCallbacksQueue.length;)r._receiveCallbacksQueue.shift().reject(r._closeEvent)}),t()})});case 3:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"_reset",value:function(){this._receiveDataQueue=[],this._receiveCallbacksQueue=[],this._closeEvent=null}},{key:"connected",get:function(){return null!=this._socket&&this._socket.readyState===WebSocket.OPEN}},{key:"dataAvailable",get:function(){return this._receiveDataQueue.length}}]),t}()}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.WebSocketClient=e()}(this,function(){"use strict";function t(t){return function(){var e=t.apply(this,arguments);return new Promise(function(t,r){function n(o,i){try{var a=e[o](i),c=a.value}catch(t){return void r(t)}if(!a.done)return Promise.resolve(c).then(function(t){n("next",t)},function(t){n("throw",t)});t(c)}return n("next")})}}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t){!function(e){function r(t,e,r,n){var i=e&&e.prototype instanceof o?e:o,a=Object.create(i.prototype),c=new p(n||[]);return a._invoke=s(t,r,c),a}function n(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}function o(){}function i(){}function a(){}function c(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function u(t){function e(r,o,i,a){var c=n(t[r],t,o);if("throw"!==c.type){var u=c.arg,s=u.value;return s&&"object"==typeof s&&m.call(s,"__await")?Promise.resolve(s.__await).then(function(t){e("next",t,i,a)},function(t){e("throw",t,i,a)}):Promise.resolve(s).then(function(t){u.value=t,i(u)},a)}a(c.arg)}var r;this._invoke=function(t,n){function o(){return new Promise(function(r,o){e(t,n,r,o)})}return r=r?r.then(o,o):o()}}function s(t,e,r){var o=E;return function(i,a){if(o===O)throw new Error("Generator is already running");if(o===j){if("throw"===i)throw a;return y()}for(r.method=i,r.arg=a;;){var c=r.delegate;if(c){var u=f(c,r);if(u){if(u===P)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===E)throw o=j,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=O;var s=n(t,e,r);if("normal"===s.type){if(o=r.done?j:L,s.arg===P)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(o=j,r.method="throw",r.arg=s.arg)}}}function f(t,e){var r=t.iterator[e.method];if(r===d){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=d,f(t,e),"throw"===e.method))return P;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return P}var o=n(r,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,P;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=d),e.delegate=null,P):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,P)}function h(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function l(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function p(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(h,this),this.reset(!0)}function v(t){if(t){var e=t[x];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r<t.length;)if(m.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=d,e.done=!0,e};return n.next=n}}return{next:y}}function y(){return{value:d,done:!0}}var d,g=Object.prototype,m=g.hasOwnProperty,w="function"==typeof Symbol?Symbol:{},x=w.iterator||"@@iterator",_=w.asyncIterator||"@@asyncIterator",b=w.toStringTag||"@@toStringTag",k=e.regeneratorRuntime;if(k)t.exports=k;else{(k=e.regeneratorRuntime=t.exports).wrap=r;var E="suspendedStart",L="suspendedYield",O="executing",j="completed",P={},Q={};Q[x]=function(){return this};var C=Object.getPrototypeOf,N=C&&C(C(v([])));N&&N!==g&&m.call(N,x)&&(Q=N);var S=a.prototype=o.prototype=Object.create(Q);i.prototype=S.constructor=a,a.constructor=i,a[b]=i.displayName="GeneratorFunction",k.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===i||"GeneratorFunction"===(e.displayName||e.name))},k.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,a):(t.__proto__=a,b in t||(t[b]="GeneratorFunction")),t.prototype=Object.create(S),t},k.awrap=function(t){return{__await:t}},c(u.prototype),u.prototype[_]=function(){return this},k.AsyncIterator=u,k.async=function(t,e,n,o){var i=new u(r(t,e,n,o));return k.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},c(S),S[b]="Generator",S[x]=function(){return this},S.toString=function(){return"[object Generator]"},k.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},k.values=v,p.prototype={constructor:p,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=d,this.done=!1,this.delegate=null,this.method="next",this.arg=d,this.tryEntries.forEach(l),!t)for(var e in this)"t"===e.charAt(0)&&m.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=d)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){function e(e,n){return i.type="throw",i.arg=t,r.next=e,n&&(r.method="next",r.arg=d),!!n}if(this.done)throw t;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],i=o.completion;if("root"===o.tryLoc)return e("end");if(o.tryLoc<=this.prev){var a=m.call(o,"catchLoc"),c=m.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return e(o.catchLoc,!0);if(this.prev<o.finallyLoc)return e(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return e(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return e(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&m.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,P):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),P},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),l(r),P}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;l(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:v(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=d),P}}}}(function(){return this}()||Function("return this")())}),n=function(){return this}()||Function("return this")(),o=n.regeneratorRuntime&&Object.getOwnPropertyNames(n).indexOf("regeneratorRuntime")>=0,i=o&&n.regeneratorRuntime;n.regeneratorRuntime=void 0;var a=r;if(o)n.regeneratorRuntime=i;else try{delete n.regeneratorRuntime}catch(t){n.regeneratorRuntime=void 0}var c=a,u=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();return function(){function r(){e(this,r),this._reset()}return u(r,[{key:"connect",value:function(){var e=t(c.mark(function t(e,r){return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.disconnect();case 2:return this._reset(),this._socket=new WebSocket(e,r),this._socket.binaryType="arraybuffer",t.next=7,this._setupListenersOnConnect();case 7:case"end":return t.stop()}},t,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"send",value:function(t){if(!this.connected)throw this._closeEvent||new Error("Not connected.");this._socket.send(t)}},{key:"receive",value:function(){var e=t(c.mark(function t(){var e,r=this;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(0===this._receiveDataQueue.length){t.next=2;break}return t.abrupt("return",this._receiveDataQueue.shift());case 2:if(this.connected){t.next=4;break}throw this._closeEvent||new Error("Not connected.");case 4:return e=new Promise(function(t,e){r._receiveCallbacksQueue.push({resolve:t,reject:e})}),t.next=7,e;case 7:return t.abrupt("return",t.sent);case 8:case"end":return t.stop()}},t,this)}));return function(){return e.apply(this,arguments)}}()},{key:"disconnect",value:function(){var e=t(c.mark(function t(e,r){var n=this;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.connected){t.next=2;break}return t.abrupt("return",this._closeEvent);case 2:return t.next=4,new Promise(function(t,o){var i={resolve:function(t){n._receiveCallbacksQueue.push(i)},reject:t};n._receiveCallbacksQueue.push(i),n._socket.close(e,r)});case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}},t,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"_setupListenersOnConnect",value:function(){var e=t(c.mark(function t(){var e,r=this;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=this._socket,t.next=3,new Promise(function(t,n){var o=function(t){var e=t;0===r._receiveCallbacksQueue.length?r._receiveDataQueue.push(e.data):r._receiveCallbacksQueue.shift().resolve(e.data)};e.addEventListener("error",n),e.addEventListener("open",function(n){e.addEventListener("message",o),e.addEventListener("close",function(t){for(r._closeEvent=t;0!==r._receiveCallbacksQueue.length;)r._receiveCallbacksQueue.shift().reject(r._closeEvent)}),t()})});case 3:case"end":return t.stop()}},t,this)}));return function(){return e.apply(this,arguments)}}()},{key:"_reset",value:function(){this._receiveDataQueue=[],this._receiveCallbacksQueue=[],this._closeEvent=null}},{key:"connected",get:function(){return null!=this._socket&&this._socket.readyState===WebSocket.OPEN}},{key:"dataAvailable",get:function(){return this._receiveDataQueue.length}}]),r}()}); |
{ | ||
"name": "websocket-async", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "An async/await WebSocket client for browsers", | ||
"module": "dist/websocket-async.esm.js", | ||
"browser": "dist/websocket-async.umd.js", | ||
"main": "lib/websocket-client.js", | ||
"author": "Jimmy Cao", | ||
@@ -14,18 +15,21 @@ "repository": { | ||
"scripts": { | ||
"build": "rollup -c", | ||
"docs": "documentation build src/** -f md -o README.md && documentation build src/** -f html -o docs" | ||
"build": "yarn run build:dist && yarn run build:lib && yarn run build:flow && yarn run build:docs", | ||
"build:dist": "rollup -c", | ||
"build:lib": "babel -d lib src", | ||
"build:flow": "flow-copy-source -v src lib", | ||
"build:docs": "documentation build src/** -f md -o README.md && documentation build src/** -f html -o docs" | ||
}, | ||
"files": [ | ||
"dist/*.js", | ||
"lib/*.js", | ||
"lib/*.js.flow", | ||
"README.md" | ||
], | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "6", | ||
"babel-eslint": "^8.0.1", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-transform-regenerator": "^6.26.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-flow": "^6.23.0", | ||
"babel-runtime": "^6.26.0", | ||
"documentation": "^5.3.3", | ||
@@ -35,2 +39,3 @@ "eslint": "^4.9.0", | ||
"flow-bin": "^0.57.3", | ||
"flow-copy-source": "^1.2.1", | ||
"rollup": "^0.50.0", | ||
@@ -44,3 +49,5 @@ "rollup-plugin-babel": "^3.0.2", | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
45003
18
52
7
342
1
1
+ Addedbabel-runtime@^6.26.0
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)