Skip to content

Commit 8bff03f

Browse files
committed
add support for drain event and send response boolean to make sockjs compliant with Writeable api that allows for handling back pressure
1 parent 0e8d891 commit 8bff03f

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

lib/main.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ SockJS.prototype.send = function(data) {
164164
if (this.readyState !== SockJS.OPEN) {
165165
return;
166166
}
167-
this._transport.send(escape.quote(data));
167+
return this._transport.send(escape.quote(data));
168168
};
169169

170170
SockJS.version = require('./version');
@@ -223,6 +223,10 @@ SockJS.prototype._connect = function() {
223223
debug('transport url', transportUrl);
224224
var transportObj = new Transport(transportUrl, this._transUrl, options);
225225
transportObj.on('message', this._transportMessage.bind(this));
226+
// for transports that support backpressure handle drain event
227+
transportObj.on('drain', function() {
228+
self.dispatchEvent(new Event('drain'));
229+
});
226230
transportObj.once('close', this._transportClose.bind(this));
227231
transportObj.transportName = Transport.transportName;
228232
this._transport = transportObj;

lib/transport/iframe.js

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ IframeTransport.prototype.postMessage = function(type, data) {
128128
IframeTransport.prototype.send = function(message) {
129129
debug('send', message);
130130
this.postMessage('m', message);
131+
return true;
131132
};
132133

133134
IframeTransport.enabled = function() {

lib/transport/lib/buffered-sender.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BufferedSender.prototype.send = function(message) {
2525
if (!this.sendStop) {
2626
this.sendSchedule();
2727
}
28+
return true;
2829
};
2930

3031
// For polling transports in a situation when in the message callback,

lib/transport/websocket.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ function WebSocketTransport(transUrl, ignore, options) {
5454
self.emit('close', 1006, 'WebSocket connection broken');
5555
self._cleanup();
5656
};
57+
this.ws.on('drain', function() {
58+
self.emit('drain');
59+
})
5760
}
5861

5962
inherits(WebSocketTransport, EventEmitter);
6063

6164
WebSocketTransport.prototype.send = function(data) {
6265
var msg = '[' + data + ']';
6366
debug('send', msg);
64-
this.ws.send(msg);
67+
return this.ws.send(msg);
6568
};
6669

6770
WebSocketTransport.prototype.close = function() {

0 commit comments

Comments
 (0)