From e69991cf009dfa435f8351bf70680a6d0664d331 Mon Sep 17 00:00:00 2001 From: Dmitrii Goriunov Date: Fri, 12 Jan 2018 01:16:52 +1300 Subject: [PATCH 1/4] Fix for module export --- dist/browser/clusterws.js | 133 +++++++++++++++++----------------- dist/browser/clusterws.min.js | 2 +- dist/index.js | 2 +- package.json | 2 +- src/index.ts | 4 +- 5 files changed, 73 insertions(+), 70 deletions(-) diff --git a/dist/browser/clusterws.js b/dist/browser/clusterws.js index f9c3fb0..3a57913 100644 --- a/dist/browser/clusterws.js +++ b/dist/browser/clusterws.js @@ -3,36 +3,36 @@ var ClusterWS = function() { function t(t) { return console.log(t); } - var n = function() { - function n(t, n) { - this.socket = t, this.name = n, this.subscribe(); + var e = function() { + function e(t, e) { + this.socket = t, this.name = e, this.subscribe(); } - return n.prototype.watch = function(n) { - return "[object Function]" !== {}.toString.call(n) ? t("Listener must be a function") : (this.listener = n, + return e.prototype.watch = function(e) { + return "[object Function]" !== {}.toString.call(e) ? t("Listener must be a function") : (this.listener = e, this); - }, n.prototype.publish = function(t) { + }, e.prototype.publish = function(t) { return this.socket.send(this.name, t, "publish"), this; - }, n.prototype.unsubscribe = function() { + }, e.prototype.unsubscribe = function() { this.socket.send("unsubscribe", this.name, "system"), this.socket.channels[this.name] = null; - }, n.prototype.onMessage = function(t) { + }, e.prototype.onMessage = function(t) { this.listener && this.listener.call(null, t); - }, n.prototype.subscribe = function() { + }, e.prototype.subscribe = function() { this.socket.send("subscribe", this.name, "system"); - }, n; - }(), e = function() { - function n() { + }, e; + }(), n = function() { + function e() { this.events = {}; } - return n.prototype.on = function(n, e) { - if ("[object Function]" !== {}.toString.call(e)) return t("Listener must be a function"); - this.events[n] = e; - }, n.prototype.emit = function(t) { - for (var n = [], e = 1; e < arguments.length; e++) n[e - 1] = arguments[e]; - this.events[t] && (o = this.events[t]).call.apply(o, [ null ].concat(n)); + return e.prototype.on = function(e, n) { + if ("[object Function]" !== {}.toString.call(n)) return t("Listener must be a function"); + this.events[e] = n; + }, e.prototype.emit = function(t) { + for (var e = [], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n]; + this.events[t] && (o = this.events[t]).call.apply(o, [ null ].concat(e)); var o; - }, n.prototype.removeAllEvents = function() { + }, e.prototype.removeAllEvents = function() { this.events = {}; - }, n; + }, e; }(), o = function() { function t(t) { this.socket = t, this.inReconnectionState = !1, this.reconnectionAttempted = 0, @@ -53,105 +53,106 @@ var ClusterWS = function() { }, this.socket.options.reconnectionIntervalMin)); }, t; }(); - function i(t, n, e) { - switch (e) { + function i(t, e, n) { + switch (n) { case "ping": return t; case "emit": return JSON.stringify({ - "#": [ "e", t, n ] + "#": [ "e", t, e ] }); case "publish": return JSON.stringify({ - "#": [ "p", t, n ] + "#": [ "p", t, e ] }); case "system": switch (t) { case "subscribe": return JSON.stringify({ - "#": [ "s", "s", n ] + "#": [ "s", "s", e ] }); case "unsubscribe": return JSON.stringify({ - "#": [ "s", "u", n ] + "#": [ "s", "u", e ] }); case "configuration": return JSON.stringify({ - "#": [ "s", "c", n ] + "#": [ "s", "c", e ] }); } } } - return function() { - function s(n) { - return this.channels = {}, this.events = new e(), this.missedPing = 0, this.useBinary = !1, - n.url ? (this.options = { - url: n.url, - autoReconnect: n.autoReconnect || !1, - reconnectionAttempts: n.reconnectionAttempts || 0, - reconnectionIntervalMin: n.reconnectionIntervalMin || 1e3, - reconnectionIntervalMax: n.reconnectionIntervalMax || 5e3 + var s = function() { + function s(e) { + return this.channels = {}, this.events = new n(), this.missedPing = 0, this.useBinary = !1, + e.url ? (this.options = { + url: e.url, + autoReconnect: e.autoReconnect || !1, + reconnectionAttempts: e.reconnectionAttempts || 0, + reconnectionIntervalMin: e.reconnectionIntervalMin || 1e3, + reconnectionIntervalMax: e.reconnectionIntervalMax || 5e3 }, this.options.reconnectionIntervalMin > this.options.reconnectionIntervalMax ? t("reconnectionIntervalMin can not be more then reconnectionIntervalMax") : (this.reconnection = new o(this), void this.create())) : t("Url must be provided and it must be string"); } return s.prototype.create = function() { - var n = this, e = window.MozWebSocket || window.WebSocket; - this.websocket = new e(this.options.url), this.websocket.binaryType = "arraybuffer", + var e = this, n = window.MozWebSocket || window.WebSocket; + this.websocket = new n(this.options.url), this.websocket.binaryType = "arraybuffer", this.websocket.onopen = function() { - return n.reconnection.isConnected(); + return e.reconnection.isConnected(); }, this.websocket.onerror = function(t) { - return n.events.emit("error", t.message); - }, this.websocket.onmessage = function(e) { - var o = "string" != typeof e.data ? String.fromCharCode.apply(null, new Uint8Array(e.data)) : e.data; - if ("#0" === o) return n.missedPing = 0, n.send("#1", null, "ping"); + return e.events.emit("error", t.message); + }, this.websocket.onmessage = function(n) { + var o = "string" != typeof n.data ? String.fromCharCode.apply(null, new Uint8Array(n.data)) : n.data; + if ("#0" === o) return e.missedPing = 0, e.send("#1", null, "ping"); try { o = JSON.parse(o); - } catch (n) { - return t(n); + } catch (e) { + return t(e); } - !function(t, n) { - switch (n["#"][0]) { + !function(t, e) { + switch (e["#"][0]) { case "e": - return t.events.emit(n["#"][1], n["#"][2]); + return t.events.emit(e["#"][1], e["#"][2]); case "p": - t.channels[n["#"][1]] && t.channels[n["#"][1]].onMessage(n["#"][2]); + t.channels[e["#"][1]] && t.channels[e["#"][1]].onMessage(e["#"][2]); case "s": - switch (n["#"][1]) { + switch (e["#"][1]) { case "c": t.pingInterval = setInterval(function() { return t.missedPing++ > 2 && t.disconnect(4001, "Did not get pings"); - }, n["#"][2].ping), t.useBinary = n["#"][2].binary, t.events.emit("connect"); + }, e["#"][2].ping), t.useBinary = e["#"][2].binary, t.events.emit("connect"); } } - }(n, o); + }(e, o); }, this.websocket.onclose = function(t) { - if (n.missedPing = 0, clearInterval(n.pingInterval), n.events.emit("disconnect", t.code, t.reason), - n.options.autoReconnect && 1e3 !== t.code) return n.reconnection.reconnect(); - n.events.removeAllEvents(); - for (var e in n) n[e] && (n[e] = null); + if (e.missedPing = 0, clearInterval(e.pingInterval), e.events.emit("disconnect", t.code, t.reason), + e.options.autoReconnect && 1e3 !== t.code) return e.reconnection.reconnect(); + e.events.removeAllEvents(); + for (var n in e) e[n] && (e[n] = null); }; - }, s.prototype.on = function(t, n) { - this.events.on(t, n); - }, s.prototype.send = function(t, n, e) { - void 0 === e && (e = "emit"), this.websocket.send(this.useBinary ? function(t) { - for (var n = t.length, e = new Uint8Array(n), o = 0; o < n; o++) e[o] = t.charCodeAt(o); - return e.buffer; - }(i(t, n, e)) : i(t, n, e)); - }, s.prototype.disconnect = function(t, n) { - this.websocket.close(t || 1e3, n); + }, s.prototype.on = function(t, e) { + this.events.on(t, e); + }, s.prototype.send = function(t, e, n) { + void 0 === n && (n = "emit"), this.websocket.send(this.useBinary ? function(t) { + for (var e = t.length, n = new Uint8Array(e), o = 0; o < e; o++) n[o] = t.charCodeAt(o); + return n.buffer; + }(i(t, e, n)) : i(t, e, n)); + }, s.prototype.disconnect = function(t, e) { + this.websocket.close(t || 1e3, e); }, s.prototype.getState = function() { return this.websocket.readyState; }, s.prototype.subscribe = function(t) { - return this.channels[t] ? this.channels[t] : this.channels[t] = new n(this, t); + return this.channels[t] ? this.channels[t] : this.channels[t] = new e(this, t); }, s.prototype.getChannelByName = function(t) { return this.channels[t]; }, s; }(); + return module.exports.default = s, s; }(); diff --git a/dist/browser/clusterws.min.js b/dist/browser/clusterws.min.js index 2120f81..78c5a1c 100644 --- a/dist/browser/clusterws.min.js +++ b/dist/browser/clusterws.min.js @@ -1 +1 @@ -var ClusterWS=function(){"use strict";function t(t){return console.log(t)}var n=function(){function n(t,n){this.socket=t,this.name=n,this.subscribe()}return n.prototype.watch=function(n){return"[object Function]"!=={}.toString.call(n)?t("Listener must be a function"):(this.listener=n,this)},n.prototype.publish=function(t){return this.socket.send(this.name,t,"publish"),this},n.prototype.unsubscribe=function(){this.socket.send("unsubscribe",this.name,"system"),this.socket.channels[this.name]=null},n.prototype.onMessage=function(t){this.listener&&this.listener.call(null,t)},n.prototype.subscribe=function(){this.socket.send("subscribe",this.name,"system")},n}(),e=function(){function n(){this.events={}}return n.prototype.on=function(n,e){if("[object Function]"!=={}.toString.call(e))return t("Listener must be a function");this.events[n]=e},n.prototype.emit=function(t){for(var n=[],e=1;e=t.socket.options.reconnectionAttempts&&(clearInterval(t.interval),t.autoReconnect=!1,t.inReconnectionState=!1),clearTimeout(t.timer),t.timer=setTimeout(function(){return t.socket.create()},Math.floor(Math.random()*(t.socket.options.reconnectionIntervalMax-t.socket.options.reconnectionIntervalMin+1))))},this.socket.options.reconnectionIntervalMin))},t}();function i(t,n,e){switch(e){case"ping":return t;case"emit":return JSON.stringify({"#":["e",t,n]});case"publish":return JSON.stringify({"#":["p",t,n]});case"system":switch(t){case"subscribe":return JSON.stringify({"#":["s","s",n]});case"unsubscribe":return JSON.stringify({"#":["s","u",n]});case"configuration":return JSON.stringify({"#":["s","c",n]})}}}return function(){function s(n){return this.channels={},this.events=new e,this.missedPing=0,this.useBinary=!1,n.url?(this.options={url:n.url,autoReconnect:n.autoReconnect||!1,reconnectionAttempts:n.reconnectionAttempts||0,reconnectionIntervalMin:n.reconnectionIntervalMin||1e3,reconnectionIntervalMax:n.reconnectionIntervalMax||5e3},this.options.reconnectionIntervalMin>this.options.reconnectionIntervalMax?t("reconnectionIntervalMin can not be more then reconnectionIntervalMax"):(this.reconnection=new o(this),void this.create())):t("Url must be provided and it must be string")}return s.prototype.create=function(){var n=this,e=window.MozWebSocket||window.WebSocket;this.websocket=new e(this.options.url),this.websocket.binaryType="arraybuffer",this.websocket.onopen=function(){return n.reconnection.isConnected()},this.websocket.onerror=function(t){return n.events.emit("error",t.message)},this.websocket.onmessage=function(e){var o="string"!=typeof e.data?String.fromCharCode.apply(null,new Uint8Array(e.data)):e.data;if("#0"===o)return n.missedPing=0,n.send("#1",null,"ping");try{o=JSON.parse(o)}catch(n){return t(n)}!function(t,n){switch(n["#"][0]){case"e":return t.events.emit(n["#"][1],n["#"][2]);case"p":t.channels[n["#"][1]]&&t.channels[n["#"][1]].onMessage(n["#"][2]);case"s":switch(n["#"][1]){case"c":t.pingInterval=setInterval(function(){return t.missedPing++>2&&t.disconnect(4001,"Did not get pings")},n["#"][2].ping),t.useBinary=n["#"][2].binary,t.events.emit("connect")}}}(n,o)},this.websocket.onclose=function(t){if(n.missedPing=0,clearInterval(n.pingInterval),n.events.emit("disconnect",t.code,t.reason),n.options.autoReconnect&&1e3!==t.code)return n.reconnection.reconnect();n.events.removeAllEvents();for(var e in n)n[e]&&(n[e]=null)}},s.prototype.on=function(t,n){this.events.on(t,n)},s.prototype.send=function(t,n,e){void 0===e&&(e="emit"),this.websocket.send(this.useBinary?function(t){for(var n=t.length,e=new Uint8Array(n),o=0;o=t.socket.options.reconnectionAttempts&&(clearInterval(t.interval),t.autoReconnect=!1,t.inReconnectionState=!1),clearTimeout(t.timer),t.timer=setTimeout(function(){return t.socket.create()},Math.floor(Math.random()*(t.socket.options.reconnectionIntervalMax-t.socket.options.reconnectionIntervalMin+1))))},this.socket.options.reconnectionIntervalMin))},t}();function i(t,e,n){switch(n){case"ping":return t;case"emit":return JSON.stringify({"#":["e",t,e]});case"publish":return JSON.stringify({"#":["p",t,e]});case"system":switch(t){case"subscribe":return JSON.stringify({"#":["s","s",e]});case"unsubscribe":return JSON.stringify({"#":["s","u",e]});case"configuration":return JSON.stringify({"#":["s","c",e]})}}}var s=function(){function s(e){return this.channels={},this.events=new n,this.missedPing=0,this.useBinary=!1,e.url?(this.options={url:e.url,autoReconnect:e.autoReconnect||!1,reconnectionAttempts:e.reconnectionAttempts||0,reconnectionIntervalMin:e.reconnectionIntervalMin||1e3,reconnectionIntervalMax:e.reconnectionIntervalMax||5e3},this.options.reconnectionIntervalMin>this.options.reconnectionIntervalMax?t("reconnectionIntervalMin can not be more then reconnectionIntervalMax"):(this.reconnection=new o(this),void this.create())):t("Url must be provided and it must be string")}return s.prototype.create=function(){var e=this,n=window.MozWebSocket||window.WebSocket;this.websocket=new n(this.options.url),this.websocket.binaryType="arraybuffer",this.websocket.onopen=function(){return e.reconnection.isConnected()},this.websocket.onerror=function(t){return e.events.emit("error",t.message)},this.websocket.onmessage=function(n){var o="string"!=typeof n.data?String.fromCharCode.apply(null,new Uint8Array(n.data)):n.data;if("#0"===o)return e.missedPing=0,e.send("#1",null,"ping");try{o=JSON.parse(o)}catch(e){return t(e)}!function(t,e){switch(e["#"][0]){case"e":return t.events.emit(e["#"][1],e["#"][2]);case"p":t.channels[e["#"][1]]&&t.channels[e["#"][1]].onMessage(e["#"][2]);case"s":switch(e["#"][1]){case"c":t.pingInterval=setInterval(function(){return t.missedPing++>2&&t.disconnect(4001,"Did not get pings")},e["#"][2].ping),t.useBinary=e["#"][2].binary,t.events.emit("connect")}}}(e,o)},this.websocket.onclose=function(t){if(e.missedPing=0,clearInterval(e.pingInterval),e.events.emit("disconnect",t.code,t.reason),e.options.autoReconnect&&1e3!==t.code)return e.reconnection.reconnect();e.events.removeAllEvents();for(var n in e)e[n]&&(e[n]=null)}},s.prototype.on=function(t,e){this.events.on(t,e)},s.prototype.send=function(t,e,n){void 0===n&&(n="emit"),this.websocket.send(this.useBinary?function(t){for(var e=t.length,n=new Uint8Array(e),o=0;o Date: Fri, 12 Jan 2018 01:39:38 +1300 Subject: [PATCH 2/4] TEst library --- dist/browser/clusterws.js | 2 +- dist/browser/clusterws.min.js | 2 +- dist/index.js | 2 +- dist/package.json | 2 +- package.json | 2 +- src/index.ts | 1 + 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dist/browser/clusterws.js b/dist/browser/clusterws.js index 3a57913..69c46a1 100644 --- a/dist/browser/clusterws.js +++ b/dist/browser/clusterws.js @@ -154,5 +154,5 @@ var ClusterWS = function() { return this.channels[t]; }, s; }(); - return module.exports.default = s, s; + return module.exports = s, module.exports.default = s, s; }(); diff --git a/dist/browser/clusterws.min.js b/dist/browser/clusterws.min.js index 78c5a1c..97e7cc1 100644 --- a/dist/browser/clusterws.min.js +++ b/dist/browser/clusterws.min.js @@ -1 +1 @@ -var ClusterWS=function(){"use strict";function t(t){return console.log(t)}var e=function(){function e(t,e){this.socket=t,this.name=e,this.subscribe()}return e.prototype.watch=function(e){return"[object Function]"!=={}.toString.call(e)?t("Listener must be a function"):(this.listener=e,this)},e.prototype.publish=function(t){return this.socket.send(this.name,t,"publish"),this},e.prototype.unsubscribe=function(){this.socket.send("unsubscribe",this.name,"system"),this.socket.channels[this.name]=null},e.prototype.onMessage=function(t){this.listener&&this.listener.call(null,t)},e.prototype.subscribe=function(){this.socket.send("subscribe",this.name,"system")},e}(),n=function(){function e(){this.events={}}return e.prototype.on=function(e,n){if("[object Function]"!=={}.toString.call(n))return t("Listener must be a function");this.events[e]=n},e.prototype.emit=function(t){for(var e=[],n=1;n=t.socket.options.reconnectionAttempts&&(clearInterval(t.interval),t.autoReconnect=!1,t.inReconnectionState=!1),clearTimeout(t.timer),t.timer=setTimeout(function(){return t.socket.create()},Math.floor(Math.random()*(t.socket.options.reconnectionIntervalMax-t.socket.options.reconnectionIntervalMin+1))))},this.socket.options.reconnectionIntervalMin))},t}();function i(t,e,n){switch(n){case"ping":return t;case"emit":return JSON.stringify({"#":["e",t,e]});case"publish":return JSON.stringify({"#":["p",t,e]});case"system":switch(t){case"subscribe":return JSON.stringify({"#":["s","s",e]});case"unsubscribe":return JSON.stringify({"#":["s","u",e]});case"configuration":return JSON.stringify({"#":["s","c",e]})}}}var s=function(){function s(e){return this.channels={},this.events=new n,this.missedPing=0,this.useBinary=!1,e.url?(this.options={url:e.url,autoReconnect:e.autoReconnect||!1,reconnectionAttempts:e.reconnectionAttempts||0,reconnectionIntervalMin:e.reconnectionIntervalMin||1e3,reconnectionIntervalMax:e.reconnectionIntervalMax||5e3},this.options.reconnectionIntervalMin>this.options.reconnectionIntervalMax?t("reconnectionIntervalMin can not be more then reconnectionIntervalMax"):(this.reconnection=new o(this),void this.create())):t("Url must be provided and it must be string")}return s.prototype.create=function(){var e=this,n=window.MozWebSocket||window.WebSocket;this.websocket=new n(this.options.url),this.websocket.binaryType="arraybuffer",this.websocket.onopen=function(){return e.reconnection.isConnected()},this.websocket.onerror=function(t){return e.events.emit("error",t.message)},this.websocket.onmessage=function(n){var o="string"!=typeof n.data?String.fromCharCode.apply(null,new Uint8Array(n.data)):n.data;if("#0"===o)return e.missedPing=0,e.send("#1",null,"ping");try{o=JSON.parse(o)}catch(e){return t(e)}!function(t,e){switch(e["#"][0]){case"e":return t.events.emit(e["#"][1],e["#"][2]);case"p":t.channels[e["#"][1]]&&t.channels[e["#"][1]].onMessage(e["#"][2]);case"s":switch(e["#"][1]){case"c":t.pingInterval=setInterval(function(){return t.missedPing++>2&&t.disconnect(4001,"Did not get pings")},e["#"][2].ping),t.useBinary=e["#"][2].binary,t.events.emit("connect")}}}(e,o)},this.websocket.onclose=function(t){if(e.missedPing=0,clearInterval(e.pingInterval),e.events.emit("disconnect",t.code,t.reason),e.options.autoReconnect&&1e3!==t.code)return e.reconnection.reconnect();e.events.removeAllEvents();for(var n in e)e[n]&&(e[n]=null)}},s.prototype.on=function(t,e){this.events.on(t,e)},s.prototype.send=function(t,e,n){void 0===n&&(n="emit"),this.websocket.send(this.useBinary?function(t){for(var e=t.length,n=new Uint8Array(e),o=0;o=t.socket.options.reconnectionAttempts&&(clearInterval(t.interval),t.autoReconnect=!1,t.inReconnectionState=!1),clearTimeout(t.timer),t.timer=setTimeout(function(){return t.socket.create()},Math.floor(Math.random()*(t.socket.options.reconnectionIntervalMax-t.socket.options.reconnectionIntervalMin+1))))},this.socket.options.reconnectionIntervalMin))},t}();function i(t,e,n){switch(n){case"ping":return t;case"emit":return JSON.stringify({"#":["e",t,e]});case"publish":return JSON.stringify({"#":["p",t,e]});case"system":switch(t){case"subscribe":return JSON.stringify({"#":["s","s",e]});case"unsubscribe":return JSON.stringify({"#":["s","u",e]});case"configuration":return JSON.stringify({"#":["s","c",e]})}}}var s=function(){function s(e){return this.channels={},this.events=new n,this.missedPing=0,this.useBinary=!1,e.url?(this.options={url:e.url,autoReconnect:e.autoReconnect||!1,reconnectionAttempts:e.reconnectionAttempts||0,reconnectionIntervalMin:e.reconnectionIntervalMin||1e3,reconnectionIntervalMax:e.reconnectionIntervalMax||5e3},this.options.reconnectionIntervalMin>this.options.reconnectionIntervalMax?t("reconnectionIntervalMin can not be more then reconnectionIntervalMax"):(this.reconnection=new o(this),void this.create())):t("Url must be provided and it must be string")}return s.prototype.create=function(){var e=this,n=window.MozWebSocket||window.WebSocket;this.websocket=new n(this.options.url),this.websocket.binaryType="arraybuffer",this.websocket.onopen=function(){return e.reconnection.isConnected()},this.websocket.onerror=function(t){return e.events.emit("error",t.message)},this.websocket.onmessage=function(n){var o="string"!=typeof n.data?String.fromCharCode.apply(null,new Uint8Array(n.data)):n.data;if("#0"===o)return e.missedPing=0,e.send("#1",null,"ping");try{o=JSON.parse(o)}catch(e){return t(e)}!function(t,e){switch(e["#"][0]){case"e":return t.events.emit(e["#"][1],e["#"][2]);case"p":t.channels[e["#"][1]]&&t.channels[e["#"][1]].onMessage(e["#"][2]);case"s":switch(e["#"][1]){case"c":t.pingInterval=setInterval(function(){return t.missedPing++>2&&t.disconnect(4001,"Did not get pings")},e["#"][2].ping),t.useBinary=e["#"][2].binary,t.events.emit("connect")}}}(e,o)},this.websocket.onclose=function(t){if(e.missedPing=0,clearInterval(e.pingInterval),e.events.emit("disconnect",t.code,t.reason),e.options.autoReconnect&&1e3!==t.code)return e.reconnection.reconnect();e.events.removeAllEvents();for(var n in e)e[n]&&(e[n]=null)}},s.prototype.on=function(t,e){this.events.on(t,e)},s.prototype.send=function(t,e,n){void 0===n&&(n="emit"),this.websocket.send(this.useBinary?function(t){for(var e=t.length,n=new Uint8Array(e),o=0;o Date: Fri, 12 Jan 2018 02:53:40 +1300 Subject: [PATCH 3/4] Fix exports --- dist/browser/clusterws.js | 134 +++++++++++++++++----------------- dist/browser/clusterws.min.js | 2 +- dist/index.js | 7 +- package.json | 2 +- src/index.ts | 5 +- 5 files changed, 72 insertions(+), 78 deletions(-) diff --git a/dist/browser/clusterws.js b/dist/browser/clusterws.js index 69c46a1..c9ca9c2 100644 --- a/dist/browser/clusterws.js +++ b/dist/browser/clusterws.js @@ -3,36 +3,35 @@ var ClusterWS = function() { function t(t) { return console.log(t); } - var e = function() { - function e(t, e) { - this.socket = t, this.name = e, this.subscribe(); + var n = function() { + function n(t, n) { + this.socket = t, this.name = n, this.subscribe(); } - return e.prototype.watch = function(e) { - return "[object Function]" !== {}.toString.call(e) ? t("Listener must be a function") : (this.listener = e, + return n.prototype.watch = function(n) { + return "[object Function]" !== {}.toString.call(n) ? t("Listener must be a function") : (this.listener = n, this); - }, e.prototype.publish = function(t) { + }, n.prototype.publish = function(t) { return this.socket.send(this.name, t, "publish"), this; - }, e.prototype.unsubscribe = function() { + }, n.prototype.unsubscribe = function() { this.socket.send("unsubscribe", this.name, "system"), this.socket.channels[this.name] = null; - }, e.prototype.onMessage = function(t) { + }, n.prototype.onMessage = function(t) { this.listener && this.listener.call(null, t); - }, e.prototype.subscribe = function() { + }, n.prototype.subscribe = function() { this.socket.send("subscribe", this.name, "system"); - }, e; - }(), n = function() { - function e() { + }, n; + }(), e = function() { + function n() { this.events = {}; } - return e.prototype.on = function(e, n) { - if ("[object Function]" !== {}.toString.call(n)) return t("Listener must be a function"); - this.events[e] = n; - }, e.prototype.emit = function(t) { - for (var e = [], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n]; - this.events[t] && (o = this.events[t]).call.apply(o, [ null ].concat(e)); - var o; - }, e.prototype.removeAllEvents = function() { + return n.prototype.on = function(n, e) { + if ("[object Function]" !== {}.toString.call(e)) return t("Listener must be a function"); + this.events[n] = e; + }, n.prototype.emit = function(t) { + for (var n, e = [], o = 1; o < arguments.length; o++) e[o - 1] = arguments[o]; + this.events[t] && (n = this.events[t]).call.apply(n, [ null ].concat(e)); + }, n.prototype.removeAllEvents = function() { this.events = {}; - }, e; + }, n; }(), o = function() { function t(t) { this.socket = t, this.inReconnectionState = !1, this.reconnectionAttempted = 0, @@ -53,106 +52,105 @@ var ClusterWS = function() { }, this.socket.options.reconnectionIntervalMin)); }, t; }(); - function i(t, e, n) { - switch (n) { + function i(t, n, e) { + switch (e) { case "ping": return t; case "emit": return JSON.stringify({ - "#": [ "e", t, e ] + "#": [ "e", t, n ] }); case "publish": return JSON.stringify({ - "#": [ "p", t, e ] + "#": [ "p", t, n ] }); case "system": switch (t) { case "subscribe": return JSON.stringify({ - "#": [ "s", "s", e ] + "#": [ "s", "s", n ] }); case "unsubscribe": return JSON.stringify({ - "#": [ "s", "u", e ] + "#": [ "s", "u", n ] }); case "configuration": return JSON.stringify({ - "#": [ "s", "c", e ] + "#": [ "s", "c", n ] }); } } } - var s = function() { - function s(e) { - return this.channels = {}, this.events = new n(), this.missedPing = 0, this.useBinary = !1, - e.url ? (this.options = { - url: e.url, - autoReconnect: e.autoReconnect || !1, - reconnectionAttempts: e.reconnectionAttempts || 0, - reconnectionIntervalMin: e.reconnectionIntervalMin || 1e3, - reconnectionIntervalMax: e.reconnectionIntervalMax || 5e3 + return function() { + function s(n) { + return this.channels = {}, this.events = new e(), this.missedPing = 0, this.useBinary = !1, + n.url ? (this.options = { + url: n.url, + autoReconnect: n.autoReconnect || !1, + reconnectionAttempts: n.reconnectionAttempts || 0, + reconnectionIntervalMin: n.reconnectionIntervalMin || 1e3, + reconnectionIntervalMax: n.reconnectionIntervalMax || 5e3 }, this.options.reconnectionIntervalMin > this.options.reconnectionIntervalMax ? t("reconnectionIntervalMin can not be more then reconnectionIntervalMax") : (this.reconnection = new o(this), void this.create())) : t("Url must be provided and it must be string"); } return s.prototype.create = function() { - var e = this, n = window.MozWebSocket || window.WebSocket; - this.websocket = new n(this.options.url), this.websocket.binaryType = "arraybuffer", + var n = this, e = window.MozWebSocket || window.WebSocket; + this.websocket = new e(this.options.url), this.websocket.binaryType = "arraybuffer", this.websocket.onopen = function() { - return e.reconnection.isConnected(); + return n.reconnection.isConnected(); }, this.websocket.onerror = function(t) { - return e.events.emit("error", t.message); - }, this.websocket.onmessage = function(n) { - var o = "string" != typeof n.data ? String.fromCharCode.apply(null, new Uint8Array(n.data)) : n.data; - if ("#0" === o) return e.missedPing = 0, e.send("#1", null, "ping"); + return n.events.emit("error", t.message); + }, this.websocket.onmessage = function(e) { + var o = "string" != typeof e.data ? String.fromCharCode.apply(null, new Uint8Array(e.data)) : e.data; + if ("#0" === o) return n.missedPing = 0, n.send("#1", null, "ping"); try { o = JSON.parse(o); - } catch (e) { - return t(e); + } catch (n) { + return t(n); } - !function(t, e) { - switch (e["#"][0]) { + !function(t, n) { + switch (n["#"][0]) { case "e": - return t.events.emit(e["#"][1], e["#"][2]); + return t.events.emit(n["#"][1], n["#"][2]); case "p": - t.channels[e["#"][1]] && t.channels[e["#"][1]].onMessage(e["#"][2]); + t.channels[n["#"][1]] && t.channels[n["#"][1]].onMessage(n["#"][2]); case "s": - switch (e["#"][1]) { + switch (n["#"][1]) { case "c": t.pingInterval = setInterval(function() { return t.missedPing++ > 2 && t.disconnect(4001, "Did not get pings"); - }, e["#"][2].ping), t.useBinary = e["#"][2].binary, t.events.emit("connect"); + }, n["#"][2].ping), t.useBinary = n["#"][2].binary, t.events.emit("connect"); } } - }(e, o); + }(n, o); }, this.websocket.onclose = function(t) { - if (e.missedPing = 0, clearInterval(e.pingInterval), e.events.emit("disconnect", t.code, t.reason), - e.options.autoReconnect && 1e3 !== t.code) return e.reconnection.reconnect(); - e.events.removeAllEvents(); - for (var n in e) e[n] && (e[n] = null); + if (n.missedPing = 0, clearInterval(n.pingInterval), n.events.emit("disconnect", t.code, t.reason), + n.options.autoReconnect && 1e3 !== t.code) return n.reconnection.reconnect(); + n.events.removeAllEvents(); + for (var e in n) n[e] && (n[e] = null); }; - }, s.prototype.on = function(t, e) { - this.events.on(t, e); - }, s.prototype.send = function(t, e, n) { - void 0 === n && (n = "emit"), this.websocket.send(this.useBinary ? function(t) { - for (var e = t.length, n = new Uint8Array(e), o = 0; o < e; o++) n[o] = t.charCodeAt(o); - return n.buffer; - }(i(t, e, n)) : i(t, e, n)); - }, s.prototype.disconnect = function(t, e) { - this.websocket.close(t || 1e3, e); + }, s.prototype.on = function(t, n) { + this.events.on(t, n); + }, s.prototype.send = function(t, n, e) { + void 0 === e && (e = "emit"), this.websocket.send(this.useBinary ? function(t) { + for (var n = t.length, e = new Uint8Array(n), o = 0; o < n; o++) e[o] = t.charCodeAt(o); + return e.buffer; + }(i(t, n, e)) : i(t, n, e)); + }, s.prototype.disconnect = function(t, n) { + this.websocket.close(t || 1e3, n); }, s.prototype.getState = function() { return this.websocket.readyState; }, s.prototype.subscribe = function(t) { - return this.channels[t] ? this.channels[t] : this.channels[t] = new e(this, t); + return this.channels[t] ? this.channels[t] : this.channels[t] = new n(this, t); }, s.prototype.getChannelByName = function(t) { return this.channels[t]; }, s; }(); - return module.exports = s, module.exports.default = s, s; }(); diff --git a/dist/browser/clusterws.min.js b/dist/browser/clusterws.min.js index 97e7cc1..f1c2ab5 100644 --- a/dist/browser/clusterws.min.js +++ b/dist/browser/clusterws.min.js @@ -1 +1 @@ -var ClusterWS=function(){"use strict";function t(t){return console.log(t)}var e=function(){function e(t,e){this.socket=t,this.name=e,this.subscribe()}return e.prototype.watch=function(e){return"[object Function]"!=={}.toString.call(e)?t("Listener must be a function"):(this.listener=e,this)},e.prototype.publish=function(t){return this.socket.send(this.name,t,"publish"),this},e.prototype.unsubscribe=function(){this.socket.send("unsubscribe",this.name,"system"),this.socket.channels[this.name]=null},e.prototype.onMessage=function(t){this.listener&&this.listener.call(null,t)},e.prototype.subscribe=function(){this.socket.send("subscribe",this.name,"system")},e}(),n=function(){function e(){this.events={}}return e.prototype.on=function(e,n){if("[object Function]"!=={}.toString.call(n))return t("Listener must be a function");this.events[e]=n},e.prototype.emit=function(t){for(var e=[],n=1;n=t.socket.options.reconnectionAttempts&&(clearInterval(t.interval),t.autoReconnect=!1,t.inReconnectionState=!1),clearTimeout(t.timer),t.timer=setTimeout(function(){return t.socket.create()},Math.floor(Math.random()*(t.socket.options.reconnectionIntervalMax-t.socket.options.reconnectionIntervalMin+1))))},this.socket.options.reconnectionIntervalMin))},t}();function i(t,e,n){switch(n){case"ping":return t;case"emit":return JSON.stringify({"#":["e",t,e]});case"publish":return JSON.stringify({"#":["p",t,e]});case"system":switch(t){case"subscribe":return JSON.stringify({"#":["s","s",e]});case"unsubscribe":return JSON.stringify({"#":["s","u",e]});case"configuration":return JSON.stringify({"#":["s","c",e]})}}}var s=function(){function s(e){return this.channels={},this.events=new n,this.missedPing=0,this.useBinary=!1,e.url?(this.options={url:e.url,autoReconnect:e.autoReconnect||!1,reconnectionAttempts:e.reconnectionAttempts||0,reconnectionIntervalMin:e.reconnectionIntervalMin||1e3,reconnectionIntervalMax:e.reconnectionIntervalMax||5e3},this.options.reconnectionIntervalMin>this.options.reconnectionIntervalMax?t("reconnectionIntervalMin can not be more then reconnectionIntervalMax"):(this.reconnection=new o(this),void this.create())):t("Url must be provided and it must be string")}return s.prototype.create=function(){var e=this,n=window.MozWebSocket||window.WebSocket;this.websocket=new n(this.options.url),this.websocket.binaryType="arraybuffer",this.websocket.onopen=function(){return e.reconnection.isConnected()},this.websocket.onerror=function(t){return e.events.emit("error",t.message)},this.websocket.onmessage=function(n){var o="string"!=typeof n.data?String.fromCharCode.apply(null,new Uint8Array(n.data)):n.data;if("#0"===o)return e.missedPing=0,e.send("#1",null,"ping");try{o=JSON.parse(o)}catch(e){return t(e)}!function(t,e){switch(e["#"][0]){case"e":return t.events.emit(e["#"][1],e["#"][2]);case"p":t.channels[e["#"][1]]&&t.channels[e["#"][1]].onMessage(e["#"][2]);case"s":switch(e["#"][1]){case"c":t.pingInterval=setInterval(function(){return t.missedPing++>2&&t.disconnect(4001,"Did not get pings")},e["#"][2].ping),t.useBinary=e["#"][2].binary,t.events.emit("connect")}}}(e,o)},this.websocket.onclose=function(t){if(e.missedPing=0,clearInterval(e.pingInterval),e.events.emit("disconnect",t.code,t.reason),e.options.autoReconnect&&1e3!==t.code)return e.reconnection.reconnect();e.events.removeAllEvents();for(var n in e)e[n]&&(e[n]=null)}},s.prototype.on=function(t,e){this.events.on(t,e)},s.prototype.send=function(t,e,n){void 0===n&&(n="emit"),this.websocket.send(this.useBinary?function(t){for(var e=t.length,n=new Uint8Array(e),o=0;o=t.socket.options.reconnectionAttempts&&(clearInterval(t.interval),t.autoReconnect=!1,t.inReconnectionState=!1),clearTimeout(t.timer),t.timer=setTimeout(function(){return t.socket.create()},Math.floor(Math.random()*(t.socket.options.reconnectionIntervalMax-t.socket.options.reconnectionIntervalMin+1))))},this.socket.options.reconnectionIntervalMin))},t}();function i(t,n,e){switch(e){case"ping":return t;case"emit":return JSON.stringify({"#":["e",t,n]});case"publish":return JSON.stringify({"#":["p",t,n]});case"system":switch(t){case"subscribe":return JSON.stringify({"#":["s","s",n]});case"unsubscribe":return JSON.stringify({"#":["s","u",n]});case"configuration":return JSON.stringify({"#":["s","c",n]})}}}return function(){function s(n){return this.channels={},this.events=new e,this.missedPing=0,this.useBinary=!1,n.url?(this.options={url:n.url,autoReconnect:n.autoReconnect||!1,reconnectionAttempts:n.reconnectionAttempts||0,reconnectionIntervalMin:n.reconnectionIntervalMin||1e3,reconnectionIntervalMax:n.reconnectionIntervalMax||5e3},this.options.reconnectionIntervalMin>this.options.reconnectionIntervalMax?t("reconnectionIntervalMin can not be more then reconnectionIntervalMax"):(this.reconnection=new o(this),void this.create())):t("Url must be provided and it must be string")}return s.prototype.create=function(){var n=this,e=window.MozWebSocket||window.WebSocket;this.websocket=new e(this.options.url),this.websocket.binaryType="arraybuffer",this.websocket.onopen=function(){return n.reconnection.isConnected()},this.websocket.onerror=function(t){return n.events.emit("error",t.message)},this.websocket.onmessage=function(e){var o="string"!=typeof e.data?String.fromCharCode.apply(null,new Uint8Array(e.data)):e.data;if("#0"===o)return n.missedPing=0,n.send("#1",null,"ping");try{o=JSON.parse(o)}catch(n){return t(n)}!function(t,n){switch(n["#"][0]){case"e":return t.events.emit(n["#"][1],n["#"][2]);case"p":t.channels[n["#"][1]]&&t.channels[n["#"][1]].onMessage(n["#"][2]);case"s":switch(n["#"][1]){case"c":t.pingInterval=setInterval(function(){return t.missedPing++>2&&t.disconnect(4001,"Did not get pings")},n["#"][2].ping),t.useBinary=n["#"][2].binary,t.events.emit("connect")}}}(n,o)},this.websocket.onclose=function(t){if(n.missedPing=0,clearInterval(n.pingInterval),n.events.emit("disconnect",t.code,t.reason),n.options.autoReconnect&&1e3!==t.code)return n.reconnection.reconnect();n.events.removeAllEvents();for(var e in n)n[e]&&(n[e]=null)}},s.prototype.on=function(t,n){this.events.on(t,n)},s.prototype.send=function(t,n,e){void 0===e&&(e="emit"),this.websocket.send(this.useBinary?function(t){for(var n=t.length,e=new Uint8Array(n),o=0;o Date: Fri, 12 Jan 2018 02:54:31 +1300 Subject: [PATCH 4/4] Publish v 1.5.3 --- dist/package.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/package.json b/dist/package.json index f74637f..aeb044f 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "clusterws-client-js", - "version": "1.5.2", + "version": "1.5.3", "description": "JavaScript Client for ClusterWS - lightweight, fast and powerful framework for building horizontally & vertically scalable WebSocket applications in Node.js.", "main": "index.js", "author": "Dmitrii Goriunov", diff --git a/package.json b/package.json index f5820b9..7c9609d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clusterws-client-js", - "version": "1.5.2", + "version": "1.5.3", "description": "JavaScript Client for ClusterWS - lightweight, fast and powerful framework for building horizontally & vertically scalable WebSocket applications in Node.js.", "main": "index.js", "author": "Dmitrii Goriunov",