-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes to event encoding and acknowledgement #242
Changes from all commits
8c3b7d9
6879154
8e590cc
6985e46
485f212
942ed48
cb3d8b5
e648cc0
4a6591e
e63d67a
357dace
52dbc10
23ce067
920c681
afe0a50
63850a5
a31a048
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,7 +329,7 @@ Manager.prototype.handleClient = function (data, req) { | |
if (count == 1) { | ||
// initialize the socket for all namespaces | ||
for (var i in self.namespaces) { | ||
self.namespaces[i].socket(data.id, true); | ||
self.namespaces[i].handlePacket(data.id, {type: 'connect'}); | ||
} | ||
|
||
// handle packets for the client (all namespaces) | ||
|
@@ -418,7 +418,7 @@ Manager.prototype.handleHandshake = function (data, req, res) { | |
function writeErr (status, message) { | ||
if (data.query.jsonp) { | ||
res.writeHead(200); | ||
res.end('io.j[' + data.query.jsonp + '](new Error(' + message + '));'); | ||
res.end('io.j[' + data.query.jsonp + '](new Error(' + JSON.stringify(message) + '));'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll rather see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if message is verbatim 'I like to collaborate to "3rd-Eden"'? ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we stringify a short message once for a faulty connection. It's not used in normal message traffic. But I admit that, if we are sure we won't use dquotes in our error messages, your initial proposal saves a couple of ticks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going with 3rd-Eden's first approach here. |
||
} else { | ||
res.writeHead(status); | ||
res.end(message); | ||
|
@@ -454,7 +454,7 @@ Manager.prototype.handleHandshake = function (data, req, res) { | |
if (data.query.jsonp) | ||
hs = 'io.j[' + data.query.jsonp + '](' + JSON.stringify(hs) + ');'; | ||
|
||
res.writeHead(200); | ||
res.writeHead(200, {'content-type': 'application/javascript'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
res.end(hs); | ||
}); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,18 @@ SocketNamespace.prototype.except = function (id) { | |
return this; | ||
}; | ||
|
||
/** | ||
* Defines a filtering function which should select session ids to | ||
* relay messages to (flag) | ||
* | ||
* @api public | ||
*/ | ||
|
||
SocketNamespace.prototype.filter = function (fn) { | ||
this.flags.filter = fn; | ||
return this; | ||
}; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very cool and needed, but I want tests for this one. Do it for any transport, |
||
* Sets the default flags. | ||
* | ||
|
@@ -107,6 +119,7 @@ SocketNamespace.prototype.setFlags = function () { | |
this.flags = { | ||
endpoint: this.name | ||
, exceptions: [] | ||
, filter: null | ||
}; | ||
return this; | ||
}; | ||
|
@@ -125,7 +138,9 @@ SocketNamespace.prototype.packet = function (packet) { | |
, packet = parser.encodePacket(packet); | ||
|
||
store.clients(this.flags.endpoint, function (clients) { | ||
clients.forEach(function (id) { | ||
(this.flags.filter ? clients.filter(this.flags.filter) : clients) | ||
.forEach(function (id) { | ||
// N.B. this should be implemented as filtering function | ||
if (~exceptions.indexOf(id)) { | ||
log.debug('ignoring packet to ', id); | ||
return; | ||
|
@@ -185,9 +200,6 @@ SocketNamespace.prototype.emit = function (name) { | |
SocketNamespace.prototype.socket = function (sid, readable) { | ||
if (!this.sockets[sid]) { | ||
this.sockets[sid] = new Socket(this.manager, sid, this, readable); | ||
if (this.name === '') { | ||
this.emit('connection', this.sockets[sid]); | ||
} | ||
} | ||
|
||
return this.sockets[sid]; | ||
|
@@ -200,7 +212,7 @@ SocketNamespace.prototype.socket = function (sid, readable) { | |
*/ | ||
|
||
SocketNamespace.prototype.handlePacket = function (sessid, packet) { | ||
var socket = this.socket(sessid) | ||
var socket = this.socket(sessid, true) // readable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the packet is handled, the socket should have already been initialized in a readable state. What's the need for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the call to SocketNamespace#socket is moved to manager and done with explicit |
||
, dataAck = packet.ack == 'data' | ||
, self = this; | ||
|
||
|
@@ -216,13 +228,14 @@ SocketNamespace.prototype.handlePacket = function (sessid, packet) { | |
switch (packet.type) { | ||
case 'connect': | ||
this.store.join(sessid, this.name, function () { | ||
self.emit('connection', self.sockets[sessid]); | ||
self.emit('connection', socket); | ||
}); | ||
break; | ||
|
||
case 'ack': | ||
if (socket.acks[packet.ackId]) { | ||
socket.acks[packet.ackId].apply(socket, packet.args); | ||
//delete socket.acks[packet.ackId]; | ||
} else { | ||
this.log.info('unknown ack packet'); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ exports.encodePacket = function (packet) { | |
case 'event': | ||
var params = packet.args && packet.args.length | ||
? JSON.stringify(packet.args) : ''; | ||
data = packet.name + (params !== '' ? ('\ufffd' + params) : ''); | ||
data = packet.name + (params !== '' ? ('\ufffc' + params) : ''); | ||
break; | ||
|
||
case 'json': | ||
|
@@ -173,7 +173,7 @@ exports.decodePacket = function (data) { | |
break; | ||
|
||
case 'event': | ||
var pieces = data.match(/([^\ufffd]+)(\ufffd)?(.*)/); | ||
var pieces = data.match(/([^\ufffc]+)(\ufffc)?(.*)/); | ||
packet.name = pieces[1] || ''; | ||
packet.args = []; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spec changed around this. See 1db340a |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,13 +263,12 @@ Client.prototype.count = function (fn) { | |
*/ | ||
|
||
Client.prototype.consume = function (fn) { | ||
this.consumer = fn; | ||
this.paused = false; | ||
|
||
if (this.buffer.length) { | ||
fn(this.buffer, null); | ||
this.buffer = []; | ||
} else { | ||
this.consumer = fn; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was probably creating problems in certain circumstances. However, it never came up with our test suite. Any chance you can create a test to avoid a regression for this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, still can't run tests -- they just timeout, because of ECONNREFUSED, because of client should connect to server only when server is bound for real. Mac has magical kernel, it listen()s synchronously, PC's doesn't ;) update: |
||
|
||
return this; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ HTMLFile.prototype.handleRequest = function (req) { | |
|
||
req.res.write( | ||
'<html><body>' | ||
+ '<script>var _ = function (msg) { parent.s._(msg, document); };</script>' | ||
+ '<script>var _ = function (msg) { parent.s.transport._(msg, document); };</script>' | ||
+ new Array(174).join(' ') | ||
); | ||
} | ||
|
@@ -65,7 +65,9 @@ HTMLFile.prototype.handleRequest = function (req) { | |
*/ | ||
|
||
HTMLFile.prototype.write = function (data) { | ||
data = '<script>_(' + JSON.stringify(data) + ');</script>'; | ||
//DVV: very bad to overwrite global _, it's usually for underscore.js :| | ||
// data = '<script>_(' + JSON.stringify(data) + ');</script>'; | ||
data = '<script>parent.s.transport._(' + JSON.stringify(data) + ', document);</script>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
this.drain = false; | ||
this.response.write(data); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this works changed recently. Please see up-to-date version.