diff --git a/lib/socket.js b/lib/socket.js index 5a2f0b91b..81ffbb316 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -247,6 +247,13 @@ Socket.prototype.setupSendCallback = function () { if ('function' == typeof seqFn) { debug('executing send callback'); seqFn(self.transport); + } else if (Array.isArray(seqFn)) { + debug('executing batch send callback'); + for (var i in seqFn) { + if ('function' == typeof seqFn) { + seqFn[i](self.transport); + } + } } } }); @@ -288,9 +295,8 @@ Socket.prototype.sendPacket = function (type, data, callback) { this.writeBuffer.push(packet); //add send callback to object - if (callback) { - this.packetsFn.push(callback); - } + this.packetsFn.push(callback); + this.flush(); } }; @@ -309,6 +315,9 @@ Socket.prototype.flush = function () { this.server.emit('flush', this, this.writeBuffer); var wbuf = this.writeBuffer; this.writeBuffer = []; + if (!this.transport.supportsFraming) { + this.packetsFn = [this.packetsFn]; + } this.transport.send(wbuf); this.emit('drain'); this.server.emit('drain', this); diff --git a/lib/transports/flashsocket.js b/lib/transports/flashsocket.js index 4773c1114..794bb29fa 100644 --- a/lib/transports/flashsocket.js +++ b/lib/transports/flashsocket.js @@ -36,6 +36,14 @@ FlashSocket.prototype.__proto__ = WebSocket.prototype; FlashSocket.prototype.name = 'flashsocket'; +/** + * Advertise framing support. + * + * @api public + */ + +FlashSocket.prototype.supportsFraming = true; + /** * Listens for new configuration changes of the Manager * this way we can enable and disable the flash server. diff --git a/lib/transports/websocket.js b/lib/transports/websocket.js index 6c474c8e6..448699e5e 100644 --- a/lib/transports/websocket.js +++ b/lib/transports/websocket.js @@ -55,6 +55,14 @@ WebSocket.prototype.name = 'websocket'; WebSocket.prototype.handlesUpgrades = true; +/** + * Advertise framing support. + * + * @api public + */ + +WebSocket.prototype.supportsFraming = true; + /** * Processes the incoming data. *