simple-websocket
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -70,8 +70,7 @@ module.exports = Socket | ||
Socket.prototype._onmessage = function (event) { | ||
var message = event.data | ||
try { | ||
var message = JSON.parse(event.data) | ||
this.emit('message', message) | ||
} catch (err) { | ||
this.emit('message', event.data) | ||
} | ||
message = JSON.parse(event.data) | ||
} catch (err) {} | ||
this.emit('message', message) | ||
} | ||
@@ -78,0 +77,0 @@ |
{ | ||
"name": "simple-websocket", | ||
"description": "Simple, EventEmitter API for WebSockets (browser)", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Feross Aboukhadijeh", |
@@ -1,5 +0,7 @@ | ||
# simple-websocket [![travis](https://img.shields.io/travis/feross/simple-websocket.svg)](https://travis-ci.org/feross/simple-websocket) [![npm](https://img.shields.io/npm/v/simple-websocket.svg)](https://npmjs.org/package/simple-websocket) [![Sauce Test Status](https://saucelabs.com/browser-matrix/simple-websocket.svg)](https://saucelabs.com/u/simple-websocket) | ||
# simple-websocket [![travis](https://img.shields.io/travis/feross/simple-websocket.svg)](https://travis-ci.org/feross/simple-websocket) [![npm](https://img.shields.io/npm/v/simple-websocket.svg)](https://npmjs.org/package/simple-websocket) | ||
#### Simple, EventEmitter API for WebSockets | ||
[![Sauce Test Status](https://saucelabs.com/browser-matrix/simple-websocket.svg)](https://saucelabs.com/u/simple-websocket) | ||
## features | ||
@@ -6,0 +8,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.SimpleWebsocket=e()}}(function(){return function e(t,n,s){function r(o,h){if(!n[o]){if(!t[o]){var u="function"==typeof require&&require;if(!h&&u)return u(o,!0);if(i)return i(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return r(n?n:e)},l,l.exports,e,t,n,s)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<s.length;o++)r(s[o]);return r}({"./":[function(e,t){function n(e,t){return this instanceof n?(s.call(this),t||(t={}),this._url=e,this._reconnect=void 0!==t.reconnect?t.reconnect:o,void this._init()):new n(e,t)}t.exports=n;var s=e("events").EventEmitter,r=e("inherits"),i=e("once"),o=5e3;r(n,s),n.prototype.send=function(e){this._ws&&this._ws.readyState===WebSocket.OPEN&&("object"==typeof e&&(e=JSON.stringify(e)),this._ws.send(e))},n.prototype.destroy=function(e){e&&this.once("close",e);try{this._ws.close()}catch(t){this._onclose()}},n.prototype._init=function(){this._errored=!1,this._ws=new WebSocket(this._url),this._ws.onopen=this._onopen.bind(this),this._ws.onmessage=this._onmessage.bind(this),this._ws.onclose=this._onclose.bind(this),this._ws.onerror=i(this._onerror.bind(this))},n.prototype._onopen=function(){this.emit("ready")},n.prototype._onerror=function(e){this._errored=!0,this.close(),this._reconnect?(this._timeout=setTimeout(this._init.bind(this),this._reconnect),this.emit("warning",e)):this.emit("error",e)},n.prototype._onmessage=function(e){try{var t=JSON.parse(e.data);this.emit("message",t)}catch(n){this.emit("message",e.data)}},n.prototype._onclose=function(){clearTimeout(this._timeout),this._ws&&(this._ws.onopen=null,this._ws.onerror=null,this._ws.onmessage=null,this._ws.onclose=null),this._ws=null,this._errored||this.emit("close")}},{events:1,inherits:2,once:3}],1:[function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function s(e){return"function"==typeof e}function r(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!r(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,r,h,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length))throw t=arguments[1],t instanceof Error?t:TypeError('Uncaught, unspecified "error" event.');if(n=this._events[e],o(n))return!1;if(s(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(r=arguments.length,h=new Array(r-1),u=1;r>u;u++)h[u-1]=arguments[u];n.apply(this,h)}else if(i(n)){for(r=arguments.length,h=new Array(r-1),u=1;r>u;u++)h[u-1]=arguments[u];for(c=n.slice(),r=c.length,u=0;r>u;u++)c[u].apply(this,h)}return!0},n.prototype.addListener=function(e,t){var r;if(!s(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,s(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned){var r;r=o(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!s(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,r,o,h;if(!s(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||s(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(n)){for(h=o;h-->0;)if(n[h]===t||n[h].listener&&n[h].listener===t){r=h;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],s(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?s(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?s(e._events[t])?1:e._events[t].length:0}},{}],2:[function(e,t){t.exports="function"==typeof Object.create?function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],3:[function(e,t){function n(e){var t=function(){return t.called?t.value:(t.called=!0,t.value=e.apply(this,arguments))};return t.called=!1,t}t.exports=n,n.proto=n(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return n(this)},configurable:!0})})},{}]},{},[])("./")}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.SimpleWebsocket=e()}}(function(){return function e(t,n,s){function r(o,h){if(!n[o]){if(!t[o]){var u="function"==typeof require&&require;if(!h&&u)return u(o,!0);if(i)return i(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return r(n?n:e)},l,l.exports,e,t,n,s)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<s.length;o++)r(s[o]);return r}({"./":[function(e,t){function n(e,t){return this instanceof n?(s.call(this),t||(t={}),this._url=e,this._reconnect=void 0!==t.reconnect?t.reconnect:o,void this._init()):new n(e,t)}t.exports=n;var s=e("events").EventEmitter,r=e("inherits"),i=e("once"),o=5e3;r(n,s),n.prototype.send=function(e){this._ws&&this._ws.readyState===WebSocket.OPEN&&("object"==typeof e&&(e=JSON.stringify(e)),this._ws.send(e))},n.prototype.destroy=function(e){e&&this.once("close",e);try{this._ws.close()}catch(t){this._onclose()}},n.prototype._init=function(){this._errored=!1,this._ws=new WebSocket(this._url),this._ws.onopen=this._onopen.bind(this),this._ws.onmessage=this._onmessage.bind(this),this._ws.onclose=this._onclose.bind(this),this._ws.onerror=i(this._onerror.bind(this))},n.prototype._onopen=function(){this.emit("ready")},n.prototype._onerror=function(e){this._errored=!0,this.close(),this._reconnect?(this._timeout=setTimeout(this._init.bind(this),this._reconnect),this.emit("warning",e)):this.emit("error",e)},n.prototype._onmessage=function(e){var t=e.data;try{t=JSON.parse(e.data)}catch(n){}this.emit("message",t)},n.prototype._onclose=function(){clearTimeout(this._timeout),this._ws&&(this._ws.onopen=null,this._ws.onerror=null,this._ws.onmessage=null,this._ws.onclose=null),this._ws=null,this._errored||this.emit("close")}},{events:1,inherits:2,once:3}],1:[function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function s(e){return"function"==typeof e}function r(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!r(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,r,h,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length))throw t=arguments[1],t instanceof Error?t:TypeError('Uncaught, unspecified "error" event.');if(n=this._events[e],o(n))return!1;if(s(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(r=arguments.length,h=new Array(r-1),u=1;r>u;u++)h[u-1]=arguments[u];n.apply(this,h)}else if(i(n)){for(r=arguments.length,h=new Array(r-1),u=1;r>u;u++)h[u-1]=arguments[u];for(c=n.slice(),r=c.length,u=0;r>u;u++)c[u].apply(this,h)}return!0},n.prototype.addListener=function(e,t){var r;if(!s(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,s(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned){var r;r=o(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!s(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,r,o,h;if(!s(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||s(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(n)){for(h=o;h-->0;)if(n[h]===t||n[h].listener&&n[h].listener===t){r=h;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],s(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?s(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?s(e._events[t])?1:e._events[t].length:0}},{}],2:[function(e,t){t.exports="function"==typeof Object.create?function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],3:[function(e,t){function n(e){var t=function(){return t.called?t.value:(t.called=!0,t.value=e.apply(this,arguments))};return t.called=!1,t}t.exports=n,n.proto=n(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return n(this)},configurable:!0})})},{}]},{},[])("./")}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109
14794
86