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

Commit 06f763b

Browse files
committed
remove seporate file for parser
1 parent f009c44 commit 06f763b

6 files changed

Lines changed: 226 additions & 243 deletions

File tree

dist/browser/clusterws.js

Lines changed: 110 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,39 @@
11
var ClusterWS = function() {
22
"use strict";
3-
function t(t, n, e) {
4-
switch (e) {
5-
case "ping":
6-
return t;
7-
8-
case "emit":
9-
return JSON.stringify({
10-
"#": [ "e", t, n ]
11-
});
12-
13-
case "publish":
14-
return JSON.stringify({
15-
"#": [ "p", t, n ]
16-
});
17-
18-
case "system":
19-
switch (t) {
20-
case "subscribe":
21-
return JSON.stringify({
22-
"#": [ "s", "s", n ]
23-
});
24-
25-
case "unsubscribe":
26-
return JSON.stringify({
27-
"#": [ "s", "u", n ]
28-
});
29-
30-
case "configuration":
31-
return JSON.stringify({
32-
"#": [ "s", "c", n ]
33-
});
34-
}
35-
}
36-
}
37-
function n(t) {
3+
function t(t) {
384
return console.log(t);
395
}
406
var e = function() {
41-
function t(t, n) {
42-
this.socket = t, this.name = n, this.subscribe();
7+
function e(t, e) {
8+
this.socket = t, this.name = e, this.subscribe();
439
}
44-
return t.prototype.watch = function(t) {
45-
return "[object Function]" !== {}.toString.call(t) ? n("Listener must be a function") : (this.listener = t,
10+
return e.prototype.watch = function(e) {
11+
return "[object Function]" !== {}.toString.call(e) ? t("Listener must be a function") : (this.listener = e,
4612
this);
47-
}, t.prototype.publish = function(t) {
13+
}, e.prototype.publish = function(t) {
4814
return this.socket.send(this.name, t, "publish"), this;
49-
}, t.prototype.unsubscribe = function() {
15+
}, e.prototype.unsubscribe = function() {
5016
this.socket.send("unsubscribe", this.name, "system"), this.socket.channels[this.name] = null;
51-
}, t.prototype.onMessage = function(t) {
17+
}, e.prototype.onMessage = function(t) {
5218
this.listener && this.listener.call(null, t);
53-
}, t.prototype.subscribe = function() {
19+
}, e.prototype.subscribe = function() {
5420
this.socket.send("subscribe", this.name, "system");
55-
}, t;
56-
}(), o = function() {
57-
function t() {
21+
}, e;
22+
}(), n = function() {
23+
function e() {
5824
this.events = {};
5925
}
60-
return t.prototype.on = function(t, e) {
61-
if ("[object Function]" !== {}.toString.call(e)) return n("Listener must be a function");
62-
this.events[t] = e;
63-
}, t.prototype.emit = function(t) {
64-
for (var n = [], e = 1; e < arguments.length; e++) n[e - 1] = arguments[e];
65-
this.events[t] && (o = this.events[t]).call.apply(o, [ null ].concat(n));
26+
return e.prototype.on = function(e, n) {
27+
if ("[object Function]" !== {}.toString.call(n)) return t("Listener must be a function");
28+
this.events[e] = n;
29+
}, e.prototype.emit = function(t) {
30+
for (var e = [], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n];
31+
this.events[t] && (o = this.events[t]).call.apply(o, [ null ].concat(e));
6632
var o;
67-
}, t.prototype.removeAllEvents = function() {
33+
}, e.prototype.removeAllEvents = function() {
6834
this.events = {};
69-
}, t;
70-
}(), i = function() {
35+
}, e;
36+
}(), o = function() {
7137
function t(t) {
7238
this.socket = t, this.inReconnectionState = !1, this.reconnectionAttempted = 0,
7339
this.autoReconnect = this.socket.options.autoReconnect;
@@ -88,70 +54,103 @@ var ClusterWS = function() {
8854
}, t;
8955
}();
9056
return function() {
91-
function s(t) {
92-
return this.channels = {}, this.events = new o(), this.missedPing = 0, this.useBinary = !1,
93-
t.url ? (this.options = {
94-
url: t.url,
95-
autoReconnect: t.autoReconnect || !1,
96-
reconnectionAttempts: t.reconnectionAttempts || 0,
97-
reconnectionIntervalMin: t.reconnectionIntervalMin || 1e3,
98-
reconnectionIntervalMax: t.reconnectionIntervalMax || 5e3
99-
}, this.options.reconnectionIntervalMin > this.options.reconnectionIntervalMax ? n("reconnectionIntervalMin can not be more then reconnectionIntervalMax") : (this.reconnection = new i(this),
100-
void this.create())) : n("Url must be provided and it must be string");
57+
function i(e) {
58+
return this.channels = {}, this.events = new n(), this.missedPing = 0, this.useBinary = !1,
59+
e.url ? (this.options = {
60+
url: e.url,
61+
autoReconnect: e.autoReconnect || !1,
62+
reconnectionAttempts: e.reconnectionAttempts || 0,
63+
reconnectionIntervalMin: e.reconnectionIntervalMin || 1e3,
64+
reconnectionIntervalMax: e.reconnectionIntervalMax || 5e3
65+
}, this.options.reconnectionIntervalMin > this.options.reconnectionIntervalMax ? t("reconnectionIntervalMin can not be more then reconnectionIntervalMax") : (this.reconnection = new o(this),
66+
void this.create())) : t("Url must be provided and it must be string");
10167
}
102-
return s.prototype.create = function() {
103-
var t = this, e = window.MozWebSocket || window.WebSocket;
104-
this.websocket = new e(this.options.url), this.websocket.binaryType = "arraybuffer",
68+
return i.prototype.create = function() {
69+
var e = this, n = window.MozWebSocket || window.WebSocket;
70+
this.websocket = new n(this.options.url), this.websocket.binaryType = "arraybuffer",
10571
this.websocket.onopen = function() {
106-
return t.reconnection.isConnected();
107-
}, this.websocket.onerror = function(n) {
108-
return t.events.emit("error", n.message);
109-
}, this.websocket.onmessage = function(e) {
110-
var o = "string" != typeof e.data ? String.fromCharCode.apply(null, new Uint8Array(e.data)) : e.data;
111-
if ("#0" === o) return t.missedPing = 0, t.send("#1", null, "ping");
72+
return e.reconnection.isConnected();
73+
}, this.websocket.onerror = function(t) {
74+
return e.events.emit("error", t.message);
75+
}, this.websocket.onmessage = function(n) {
76+
var o = "string" != typeof n.data ? String.fromCharCode.apply(null, new Uint8Array(n.data)) : n.data;
77+
if ("#0" === o) return e.missedPing = 0, e.send("#1", null, "ping");
11278
try {
11379
o = JSON.parse(o);
114-
} catch (t) {
115-
return n(t);
80+
} catch (e) {
81+
return t(e);
11682
}
117-
!function(t, n) {
118-
switch (n["#"][0]) {
119-
case "e":
120-
return t.events.emit(n["#"][1], n["#"][2]);
121-
122-
case "p":
123-
t.channels[n["#"][1]] && t.channels[n["#"][1]].onMessage(n["#"][2]);
124-
125-
case "s":
126-
switch (n["#"][1]) {
127-
case "c":
128-
t.pingInterval = setInterval(function() {
129-
return t.missedPing++ > 2 && t.disconnect(4001, "Did not get pings");
130-
}, n["#"][2].ping), t.useBinary = n["#"][2].binary, t.events.emit("connect");
131-
}
132-
}
133-
}(t, o);
134-
}, this.websocket.onclose = function(n) {
135-
if (t.missedPing = 0, clearInterval(t.pingInterval), t.events.emit("disconnect", n.code, n.reason),
136-
t.options.autoReconnect && 1e3 !== n.code) return t.reconnection.reconnect();
137-
t.events.removeAllEvents();
138-
for (var e in t) t[e] && (t[e] = null);
83+
i.decode(e, o);
84+
}, this.websocket.onclose = function(t) {
85+
if (e.missedPing = 0, clearInterval(e.pingInterval), e.events.emit("disconnect", t.code, t.reason),
86+
e.options.autoReconnect && 1e3 !== t.code) return e.reconnection.reconnect();
87+
e.events.removeAllEvents();
88+
for (var n in e) e[n] && (e[n] = null);
13989
};
140-
}, s.prototype.on = function(t, n) {
141-
this.events.on(t, n);
142-
}, s.prototype.send = function(n, e, o) {
143-
void 0 === o && (o = "emit"), this.websocket.send(this.useBinary ? function(t) {
144-
for (var n = t.length, e = new Uint8Array(n), o = 0; o < n; o++) e[o] = t.charCodeAt(o);
145-
return e.buffer;
146-
}(t(n, e, o)) : t(n, e, o));
147-
}, s.prototype.disconnect = function(t, n) {
148-
this.websocket.close(t || 1e3, n);
149-
}, s.prototype.getState = function() {
90+
}, i.prototype.on = function(t, e) {
91+
this.events.on(t, e);
92+
}, i.prototype.send = function(t, e, n) {
93+
void 0 === n && (n = "emit"), this.websocket.send(this.useBinary ? i.buffer(i.encode(t, e, n)) : i.encode(t, e, n));
94+
}, i.prototype.disconnect = function(t, e) {
95+
this.websocket.close(t || 1e3, e);
96+
}, i.prototype.getState = function() {
15097
return this.websocket.readyState;
151-
}, s.prototype.subscribe = function(t) {
98+
}, i.prototype.subscribe = function(t) {
15299
return this.channels[t] ? this.channels[t] : this.channels[t] = new e(this, t);
153-
}, s.prototype.getChannelByName = function(t) {
100+
}, i.prototype.getChannelByName = function(t) {
154101
return this.channels[t];
155-
}, s;
102+
}, i.buffer = function(t) {
103+
for (var e = t.length, n = new Uint8Array(e), o = 0; o < e; o++) n[o] = t.charCodeAt(o);
104+
return n.buffer;
105+
}, i.decode = function(t, e) {
106+
switch (e["#"][0]) {
107+
case "e":
108+
return t.events.emit(e["#"][1], e["#"][2]);
109+
110+
case "p":
111+
t.channels[e["#"][1]] && t.channels[e["#"][1]].onMessage(e["#"][2]);
112+
113+
case "s":
114+
switch (e["#"][1]) {
115+
case "c":
116+
t.pingInterval = setInterval(function() {
117+
return t.missedPing++ > 2 && t.disconnect(4001, "Did not get pings");
118+
}, e["#"][2].ping), t.useBinary = e["#"][2].binary, t.events.emit("connect");
119+
}
120+
}
121+
}, i.encode = function(t, e, n) {
122+
switch (n) {
123+
case "ping":
124+
return t;
125+
126+
case "emit":
127+
return JSON.stringify({
128+
"#": [ "e", t, e ]
129+
});
130+
131+
case "publish":
132+
return JSON.stringify({
133+
"#": [ "p", t, e ]
134+
});
135+
136+
case "system":
137+
switch (t) {
138+
case "subscribe":
139+
return JSON.stringify({
140+
"#": [ "s", "s", e ]
141+
});
142+
143+
case "unsubscribe":
144+
return JSON.stringify({
145+
"#": [ "s", "u", e ]
146+
});
147+
148+
case "configuration":
149+
return JSON.stringify({
150+
"#": [ "s", "c", e ]
151+
});
152+
}
153+
}
154+
}, i;
156155
}();
157156
}();

0 commit comments

Comments
 (0)