Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
New version 2.2.1
Browse files Browse the repository at this point in the history
New version 2.2.1
  • Loading branch information
goriunov authored Mar 29, 2018
2 parents 94ea4c2 + 1176d46 commit 36b743b
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 102 deletions.
6 changes: 3 additions & 3 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<h6 align="center">Build Scalable Node.js WebSocket Applications</h6>

<p align="center">
<img src="https://cdn.rawgit.com/goriunov/159120ca6a883d8d4e75543ec395d361/raw/c7d5366740902a118bd857b70117a2df6ca97dd0/clusterws.svg" width="450">
<img src="https://cdn.rawgit.com/goriunov/159120ca6a883d8d4e75543ec395d361/raw/146220360173a2428fceb44e7fc9b2cda8a17832/clusterws.svg" width="450">
</p>

<p align="center">
<a href="https://github.com/ClusterWS/ClusterWS-Client-JS/blob/master/LICENSE"><img src="https://img.shields.io/github/license/ClusterWS/ClusterWS-Client-JS.svg?style=for-the-badge" alt="GitHub license" /></a>
<a href="https://www.npmjs.com/package/clusterws-client-js"><img src="https://img.shields.io/badge/npm-2.1.0-blue.svg?style=for-the-badge" alt="NPM Version" /></a>
<a href="https://github.com/ClusterWS/ClusterWS-Client-JS/blob/master/LICENSE"><img src="https://img.shields.io/github/license/ClusterWS/ClusterWS-Client-JS.svg?style=for-the-badge" alt="GitHub license"/></a>
<a href="https://www.npmjs.com/package/clusterws-client-js"><img src="https://img.shields.io/badge/npm-2.2.1-blue.svg?style=for-the-badge" alt="NPM Version" /></a>
<a href="https://github.com/ClusterWS/ClusterWS-Client-JS/graphs/commit-activity"><img src="https://img.shields.io/badge/Maintain-Yes-green.svg?style=for-the-badge" alt="Maintain" /></a>
</p>

Expand Down
163 changes: 81 additions & 82 deletions dist/browser/clusterws.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,129 +3,128 @@ var ClusterWS = function() {
function t(t) {
return console.log(t);
}
var n = function() {
function n(t, n) {
this.name = n, this.socket = t, this.subscribe();
var e = function() {
function e(t, e) {
this.name = e, this.socket = t, 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 = [], 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() {
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 = [], o = 1; o < arguments.length; o++) n[o - 1] = arguments[o];
this.events[t] && (e = this.events[t]).call.apply(e, [ null ].concat(n));
}, e.prototype.removeAllEvents = function() {
this.events = {};
}, n;
}, e;
}();
function o(t, n, e) {
function o(t, e, n) {
var o = {
emit: {
"#": [ "e", t, n ]
"#": [ "e", t, e ]
},
publish: {
"#": [ "p", t, n ]
"#": [ "p", t, e ]
},
system: {
subscribe: {
"#": [ "s", "s", n ]
"#": [ "s", "s", e ]
},
unsubscribe: {
"#": [ "s", "u", n ]
"#": [ "s", "u", e ]
}
}
};
return "ping" === e ? t : JSON.stringify("system" === e ? o[e][t] : o[e]);
return "ping" === n ? t : JSON.stringify("system" === n ? o[n][t] : o[n]);
}
return function() {
function s(n) {
return this.events = new e(), this.channels = {}, this.useBinary = !1, this.missedPing = 0,
this.reconnectionAttempted = 0, n.url ? (this.options = {
url: n.url,
autoReconnect: n.autoReconnect || !1,
autoReconnectOptions: n.autoReconnectOptions ? {
attempts: n.autoReconnectOptions.attempts || 0,
minInterval: n.autoReconnectOptions.minInterval || 1e3,
maxInterval: n.autoReconnectOptions.maxInterval || 5e3
function s(e) {
return this.events = new n(), this.isAlive = !0, this.channels = {}, this.useBinary = !1,
this.missedPing = 0, this.reconnectionAttempted = 0, e.url ? (this.options = {
url: e.url,
autoReconnect: e.autoReconnect || !1,
autoReconnectOptions: e.autoReconnectOptions ? {
attempts: e.autoReconnectOptions.attempts || 0,
minInterval: e.autoReconnectOptions.minInterval || 1e3,
maxInterval: e.autoReconnectOptions.maxInterval || 5e3
} : {
attempts: 0,
minInterval: 1e3,
maxInterval: 5e3
}
}, this.options.autoReconnectOptions.minInterval > this.options.autoReconnectOptions.maxInterval ? t("minInterval option can not be more than maxInterval option") : void this.create()) : t("Url must be provided and it must be string");
}, this.options.autoReconnectOptions.minInterval > this.options.autoReconnectOptions.maxInterval ? t("minInterval option can not be more than maxInterval option") : void this.create()) : t("Url must be provided and it must be a string");
}
return 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;
}(o(t, n, e)) : o(t, n, e));
}, s.prototype.disconnect = function(t, n) {
this.websocket.close(t || 1e3, n);
return 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;
}(o(t, e, n)) : o(t, e, n));
}, s.prototype.disconnect = function(t, e) {
this.websocket.close(t || 1e3, e);
}, 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.prototype.getState = function() {
return this.websocket.readyState;
}, 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() {
n.reconnectionAttempted = 0;
for (var t = 0, e = Object.keys(n.channels), o = e.length; t < o; t++) n.channels[e[t]] && n.channels[e[t]].subscribe();
e.reconnectionAttempted = 0;
for (var t = 0, n = Object.keys(e.channels), o = n.length; t < o; t++) e.channels[n[t]] && e.channels[n[t]].subscribe();
}, this.websocket.onerror = function(t) {
return n.events.emit("error", t);
}, 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);
}, 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);
}
!function(t, n) {
var e = {
e: function() {
return t.events.emit(n["#"][1], n["#"][2]);
},
p: function() {
return t.channels[n["#"][1]] && t.channels[n["#"][1]].onMessage(n["#"][2]);
},
s: {
c: function() {
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");
o = JSON.parse(o), function(t, e) {
var n = {
e: function() {
return t.events.emit(e["#"][1], e["#"][2]);
},
p: function() {
return t.channels[e["#"][1]] && t.channels[e["#"][1]].onMessage(e["#"][2]);
},
s: {
c: function() {
t.useBinary = e["#"][2].binary, t.pingInterval = setInterval(function() {
return t.missedPing++ > 2 && t.disconnect(4001, "Did not get pings");
}, e["#"][2].ping), t.events.emit("connect");
}
}
}
};
"s" === n["#"][0] ? e[n["#"][0]][n["#"][1]] && e[n["#"][0]][n["#"][1]].call(null) : e[n["#"][0]] && e[n["#"][0]].call(null);
}(n, o);
};
"s" === e["#"][0] ? n[e["#"][0]][e["#"][1]] && n[e["#"][0]][e["#"][1]].call(null) : n[e["#"][0]] && n[e["#"][0]].call(null);
}(e, o);
} catch (e) {
return t(e);
}
}, 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 && (0 === n.options.autoReconnectOptions.attempts || n.reconnectionAttempted < n.options.autoReconnectOptions.attempts)) n.websocket.readyState === n.websocket.CLOSED ? (n.reconnectionAttempted++,
n.websocket = void 0, setTimeout(function() {
return n.create();
}, Math.floor(Math.random() * (n.options.autoReconnectOptions.maxInterval - n.options.autoReconnectOptions.minInterval + 1)))) : console.log("Some thing wrong with close event please contact developer"); else {
n.events.removeAllEvents();
for (var e = 0, o = Object.keys(n), s = o.length; e < s; e++) n[o[e]] = null;
if (e.missedPing = 0, clearInterval(e.pingInterval), e.events.emit("disconnect", t.code, t.reason),
e.options.autoReconnect && 1e3 !== t.code && (0 === e.options.autoReconnectOptions.attempts || e.reconnectionAttempted < e.options.autoReconnectOptions.attempts)) e.websocket.readyState === e.websocket.CLOSED ? (e.reconnectionAttempted++,
e.websocket = void 0, setTimeout(function() {
return e.create();
}, Math.floor(Math.random() * (e.options.autoReconnectOptions.maxInterval - e.options.autoReconnectOptions.minInterval + 1)))) : console.log("Some thing wrong with close event please contact developer"); else {
e.events.removeAllEvents();
for (var n = 0, o = Object.keys(e), s = o.length; n < s; n++) e[o[n]] = null;
}
};
}, s;
Expand Down
Loading

0 comments on commit 36b743b

Please sign in to comment.