Skip to content

Commit

Permalink
Merge pull request #398 from Nibbler999/ws-write-packet-options
Browse files Browse the repository at this point in the history
Fix websocket packet writing
  • Loading branch information
rauchg committed Jun 6, 2015
2 parents 0637e07 + 295f91a commit e595a72
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/transports/websocket.js
Expand Up @@ -155,24 +155,25 @@ WS.prototype.write = function(packets){
// no need for encodePayload
var total = packets.length;
for (var i = 0, l = total; i < l; i++) {
var packet = packets[i];
parser.encodePacket(packet, this.supportsBinary, function(data) {
//Sometimes the websocket has already been closed but the browser didn't
//have a chance of informing us about it yet, in that case send will
//throw an error
try {
if (global.WebSocket && self.ws instanceof global.WebSocket) {
// TypeError is thrown when passing the second argument on Safari
self.ws.send(data);
} else {
self.ws.send(data, packet.options);
(function(packet) {
parser.encodePacket(packet, this.supportsBinary, function(data) {
//Sometimes the websocket has already been closed but the browser didn't
//have a chance of informing us about it yet, in that case send will
//throw an error
try {
if (global.WebSocket && self.ws instanceof global.WebSocket) {
// TypeError is thrown when passing the second argument on Safari
self.ws.send(data);
} else {
self.ws.send(data, packet.options);
}
} catch (e){
debug('websocket closed before onclose event');
}
} catch (e){
debug('websocket closed before onclose event');
}

--total || done();
});
--total || done();
});
})(packets[i]);
}

function done(){
Expand Down

0 comments on commit e595a72

Please sign in to comment.