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

Commit e69991c

Browse files
committed
Fix for module export
1 parent d06bf41 commit e69991c

File tree

5 files changed

+73
-70
lines changed

5 files changed

+73
-70
lines changed

dist/browser/clusterws.js

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@ var ClusterWS = function() {
33
function t(t) {
44
return console.log(t);
55
}
6-
var n = function() {
7-
function n(t, n) {
8-
this.socket = t, this.name = n, this.subscribe();
6+
var e = function() {
7+
function e(t, e) {
8+
this.socket = t, this.name = e, this.subscribe();
99
}
10-
return n.prototype.watch = function(n) {
11-
return "[object Function]" !== {}.toString.call(n) ? t("Listener must be a function") : (this.listener = n,
10+
return e.prototype.watch = function(e) {
11+
return "[object Function]" !== {}.toString.call(e) ? t("Listener must be a function") : (this.listener = e,
1212
this);
13-
}, n.prototype.publish = function(t) {
13+
}, e.prototype.publish = function(t) {
1414
return this.socket.send(this.name, t, "publish"), this;
15-
}, n.prototype.unsubscribe = function() {
15+
}, e.prototype.unsubscribe = function() {
1616
this.socket.send("unsubscribe", this.name, "system"), this.socket.channels[this.name] = null;
17-
}, n.prototype.onMessage = function(t) {
17+
}, e.prototype.onMessage = function(t) {
1818
this.listener && this.listener.call(null, t);
19-
}, n.prototype.subscribe = function() {
19+
}, e.prototype.subscribe = function() {
2020
this.socket.send("subscribe", this.name, "system");
21-
}, n;
22-
}(), e = function() {
23-
function n() {
21+
}, e;
22+
}(), n = function() {
23+
function e() {
2424
this.events = {};
2525
}
26-
return n.prototype.on = function(n, e) {
27-
if ("[object Function]" !== {}.toString.call(e)) return t("Listener must be a function");
28-
this.events[n] = e;
29-
}, n.prototype.emit = function(t) {
30-
for (var n = [], e = 1; e < arguments.length; e++) n[e - 1] = arguments[e];
31-
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));
3232
var o;
33-
}, n.prototype.removeAllEvents = function() {
33+
}, e.prototype.removeAllEvents = function() {
3434
this.events = {};
35-
}, n;
35+
}, e;
3636
}(), o = function() {
3737
function t(t) {
3838
this.socket = t, this.inReconnectionState = !1, this.reconnectionAttempted = 0,
@@ -53,105 +53,106 @@ var ClusterWS = function() {
5353
}, this.socket.options.reconnectionIntervalMin));
5454
}, t;
5555
}();
56-
function i(t, n, e) {
57-
switch (e) {
56+
function i(t, e, n) {
57+
switch (n) {
5858
case "ping":
5959
return t;
6060

6161
case "emit":
6262
return JSON.stringify({
63-
"#": [ "e", t, n ]
63+
"#": [ "e", t, e ]
6464
});
6565

6666
case "publish":
6767
return JSON.stringify({
68-
"#": [ "p", t, n ]
68+
"#": [ "p", t, e ]
6969
});
7070

7171
case "system":
7272
switch (t) {
7373
case "subscribe":
7474
return JSON.stringify({
75-
"#": [ "s", "s", n ]
75+
"#": [ "s", "s", e ]
7676
});
7777

7878
case "unsubscribe":
7979
return JSON.stringify({
80-
"#": [ "s", "u", n ]
80+
"#": [ "s", "u", e ]
8181
});
8282

8383
case "configuration":
8484
return JSON.stringify({
85-
"#": [ "s", "c", n ]
85+
"#": [ "s", "c", e ]
8686
});
8787
}
8888
}
8989
}
90-
return function() {
91-
function s(n) {
92-
return this.channels = {}, this.events = new e(), this.missedPing = 0, this.useBinary = !1,
93-
n.url ? (this.options = {
94-
url: n.url,
95-
autoReconnect: n.autoReconnect || !1,
96-
reconnectionAttempts: n.reconnectionAttempts || 0,
97-
reconnectionIntervalMin: n.reconnectionIntervalMin || 1e3,
98-
reconnectionIntervalMax: n.reconnectionIntervalMax || 5e3
90+
var s = function() {
91+
function s(e) {
92+
return this.channels = {}, this.events = new n(), this.missedPing = 0, this.useBinary = !1,
93+
e.url ? (this.options = {
94+
url: e.url,
95+
autoReconnect: e.autoReconnect || !1,
96+
reconnectionAttempts: e.reconnectionAttempts || 0,
97+
reconnectionIntervalMin: e.reconnectionIntervalMin || 1e3,
98+
reconnectionIntervalMax: e.reconnectionIntervalMax || 5e3
9999
}, this.options.reconnectionIntervalMin > this.options.reconnectionIntervalMax ? t("reconnectionIntervalMin can not be more then reconnectionIntervalMax") : (this.reconnection = new o(this),
100100
void this.create())) : t("Url must be provided and it must be string");
101101
}
102102
return s.prototype.create = function() {
103-
var n = this, e = window.MozWebSocket || window.WebSocket;
104-
this.websocket = new e(this.options.url), this.websocket.binaryType = "arraybuffer",
103+
var e = this, n = window.MozWebSocket || window.WebSocket;
104+
this.websocket = new n(this.options.url), this.websocket.binaryType = "arraybuffer",
105105
this.websocket.onopen = function() {
106-
return n.reconnection.isConnected();
106+
return e.reconnection.isConnected();
107107
}, this.websocket.onerror = function(t) {
108-
return n.events.emit("error", t.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 n.missedPing = 0, n.send("#1", null, "ping");
108+
return e.events.emit("error", t.message);
109+
}, this.websocket.onmessage = function(n) {
110+
var o = "string" != typeof n.data ? String.fromCharCode.apply(null, new Uint8Array(n.data)) : n.data;
111+
if ("#0" === o) return e.missedPing = 0, e.send("#1", null, "ping");
112112
try {
113113
o = JSON.parse(o);
114-
} catch (n) {
115-
return t(n);
114+
} catch (e) {
115+
return t(e);
116116
}
117-
!function(t, n) {
118-
switch (n["#"][0]) {
117+
!function(t, e) {
118+
switch (e["#"][0]) {
119119
case "e":
120-
return t.events.emit(n["#"][1], n["#"][2]);
120+
return t.events.emit(e["#"][1], e["#"][2]);
121121

122122
case "p":
123-
t.channels[n["#"][1]] && t.channels[n["#"][1]].onMessage(n["#"][2]);
123+
t.channels[e["#"][1]] && t.channels[e["#"][1]].onMessage(e["#"][2]);
124124

125125
case "s":
126-
switch (n["#"][1]) {
126+
switch (e["#"][1]) {
127127
case "c":
128128
t.pingInterval = setInterval(function() {
129129
return t.missedPing++ > 2 && t.disconnect(4001, "Did not get pings");
130-
}, n["#"][2].ping), t.useBinary = n["#"][2].binary, t.events.emit("connect");
130+
}, e["#"][2].ping), t.useBinary = e["#"][2].binary, t.events.emit("connect");
131131
}
132132
}
133-
}(n, o);
133+
}(e, o);
134134
}, this.websocket.onclose = function(t) {
135-
if (n.missedPing = 0, clearInterval(n.pingInterval), n.events.emit("disconnect", t.code, t.reason),
136-
n.options.autoReconnect && 1e3 !== t.code) return n.reconnection.reconnect();
137-
n.events.removeAllEvents();
138-
for (var e in n) n[e] && (n[e] = null);
135+
if (e.missedPing = 0, clearInterval(e.pingInterval), e.events.emit("disconnect", t.code, t.reason),
136+
e.options.autoReconnect && 1e3 !== t.code) return e.reconnection.reconnect();
137+
e.events.removeAllEvents();
138+
for (var n in e) e[n] && (e[n] = null);
139139
};
140-
}, s.prototype.on = function(t, n) {
141-
this.events.on(t, n);
142-
}, s.prototype.send = function(t, n, e) {
143-
void 0 === e && (e = "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-
}(i(t, n, e)) : i(t, n, e));
147-
}, s.prototype.disconnect = function(t, n) {
148-
this.websocket.close(t || 1e3, n);
140+
}, s.prototype.on = function(t, e) {
141+
this.events.on(t, e);
142+
}, s.prototype.send = function(t, e, n) {
143+
void 0 === n && (n = "emit"), this.websocket.send(this.useBinary ? function(t) {
144+
for (var e = t.length, n = new Uint8Array(e), o = 0; o < e; o++) n[o] = t.charCodeAt(o);
145+
return n.buffer;
146+
}(i(t, e, n)) : i(t, e, n));
147+
}, s.prototype.disconnect = function(t, e) {
148+
this.websocket.close(t || 1e3, e);
149149
}, s.prototype.getState = function() {
150150
return this.websocket.readyState;
151151
}, s.prototype.subscribe = function(t) {
152-
return this.channels[t] ? this.channels[t] : this.channels[t] = new n(this, t);
152+
return this.channels[t] ? this.channels[t] : this.channels[t] = new e(this, t);
153153
}, s.prototype.getChannelByName = function(t) {
154154
return this.channels[t];
155155
}, s;
156156
}();
157+
return module.exports.default = s, s;
157158
}();

dist/browser/clusterws.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,4 @@ var ClusterWS = function() {
162162
}, t;
163163
}();
164164

165-
module.exports = ClusterWS;
165+
module.exports.default = ClusterWS, module.exports = ClusterWS;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clusterws-client-js",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "JavaScript Client for ClusterWS - lightweight, fast and powerful framework for building horizontally & vertically scalable WebSocket applications in Node.js.",
55
"main": "index.js",
66
"author": "Dmitrii Goriunov",

0 commit comments

Comments
 (0)