Skip to content

Commit a7d8834

Browse files
committed
Removed socket parameters from emitMessage
1 parent 91be56e commit a7d8834

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

dist/nodejs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ dop.core.emitDisconnect = function(node) {
885885

886886
////////// src/core/api_transports/emitMessage.js
887887

888-
dop.core.emitMessage = function(node, socket, message_string, message_raw) {
888+
dop.core.emitMessage = function(node, message_string, message_raw) {
889889

890890
// If server
891891
if (node.listener)

src/core/api_transports/emitMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
dop.core.emitMessage = function(node, socket, message_string, message_raw) {
2+
dop.core.emitMessage = function(node, message_string, message_raw) {
33

44
// If server
55
if (node.listener)

src/env/browser/websocket.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ function websocket(dop, node, options) {
33

44
var url = 'ws://localhost:4444/'+dop.name,
55
args = arguments;
6-
76
if (typeof options.url == 'string')
87
url = options.url.replace('http','ws');
98
else if (typeof window!='undefined' && /http/.test(window.location.href)) {
@@ -12,26 +11,25 @@ function websocket(dop, node, options) {
1211
url = protocol+'://'+domain_prefix[2].toLocaleLowerCase()+'/'+dop.name;
1312
}
1413

14+
1515
// Variables
1616
var api = options.transport.getApi(),
1717
socket = new api(url),
1818
send_queue = [];
1919

20-
21-
// We use this function as alias to store messages when connection is not CONNECT
20+
// Helpers
2221
function send(message) {
2322
(socket.readyState===socket.constructor.OPEN && node.readyState===dop.CONS.CONNECT) ?
2423
socket.send(message)
2524
:
2625
send_queue.push(message);
2726
}
28-
29-
// This function emit all the queue messages
3027
function sendQueue(message) {
3128
while (send_queue.length>0)
3229
socket.send(send_queue.shift());
3330
}
3431

32+
// Socket events
3533
function onopen() {
3634
// Reconnect
3735
if (node.readyState === dop.CONS.RECONNECT)
@@ -47,7 +45,6 @@ function websocket(dop, node, options) {
4745
// Reconnecting
4846
if (node.readyState===dop.CONS.RECONNECT && message.data===node.tokenServer) {
4947
node.readyState = dop.CONS.CONNECT;
50-
// node.socket = socket;
5148
dop.core.emitReconnectClient(node, oldSocket);
5249
// sendQueue();
5350
}
@@ -58,35 +55,38 @@ function websocket(dop, node, options) {
5855
dop.core.emitClose(node, socket);
5956
}
6057

61-
// Adding listeners
62-
addListeners(socket, onopen, onmessage, onclose);
63-
node.readyState = dop.CONS.CLOSE;
64-
node.reconnect = function() {
65-
oldSocket = socket;
66-
socket = new api(url);
67-
addListeners(socket, onopen, onmessage, onclose);
68-
removeListeners(oldSocket, onopen, onmessage, onclose);
69-
node.readyState = dop.CONS.RECONNECT;
70-
};
71-
node.on(dop.CONS.CONNECT, function() {
58+
// dop events
59+
function onconnect() {
7260
if (node.readyState === dop.CONS.RECONNECT) {
7361
node.socket = oldSocket;
7462
dop.core.emitDisconnect(node);
7563
node.socket = socket;
7664
}
7765
node.readyState = dop.CONS.CONNECT;
7866
dop.core.emitConnect(node);
79-
});
80-
node.on(dop.CONS.SEND, function(message) {
81-
send(message);
82-
});
83-
node.on(dop.CONS.DISCONNECT, function() {
67+
}
68+
function ondisconnect() {
8469
node.readyState = dop.CONS.CLOSE;
8570
socket.close();
86-
});
71+
}
72+
8773

74+
// Setting up
75+
node.readyState = dop.CONS.CLOSE;
76+
node.reconnect = function() {
77+
oldSocket = socket;
78+
socket = new api(url);
79+
addListeners(socket, onopen, onmessage, onclose);
80+
removeListeners(oldSocket, onopen, onmessage, onclose);
81+
node.readyState = dop.CONS.RECONNECT;
82+
};
83+
node.on(dop.CONS.CONNECT, onconnect);
84+
node.on(dop.CONS.SEND, send);
85+
node.on(dop.CONS.DISCONNECT, ondisconnect);
86+
addListeners(socket, onopen, onmessage, onclose);
87+
8888
return socket;
89-
};
89+
}
9090

9191
function addListeners(socket, onopen, onmessage, onclose) {
9292
socket.addEventListener('open', onopen);

0 commit comments

Comments
 (0)