Skip to content

Commit 8440a57

Browse files

File tree

6 files changed

+19
-11433
lines changed

6 files changed

+19
-11433
lines changed

lib/transports/polling.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Polling extends Transport {
102102
};
103103

104104
// decode payload
105-
parser.decodePayload(data, this.socket.binaryType, callback);
105+
parser.decodePayload(data, this.socket.binaryType).forEach(callback);
106106

107107
// if an event did not trigger closing
108108
if ("closed" !== this.readyState) {
@@ -150,15 +150,13 @@ class Polling extends Transport {
150150
* @api private
151151
*/
152152
write(packets) {
153-
const self = this;
154153
this.writable = false;
155-
const callbackfn = function() {
156-
self.writable = true;
157-
self.emit("drain");
158-
};
159154

160-
parser.encodePayload(packets, this.supportsBinary, function(data) {
161-
self.doWrite(data, callbackfn);
155+
parser.encodePayload(packets, data => {
156+
this.doWrite(data, () => {
157+
this.writable = true;
158+
this.emit("drain");
159+
});
162160
});
163161
}
164162

lib/transports/websocket-constructor.browser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ const globalThis = require("../globalThis");
22

33
module.exports = {
44
WebSocket: globalThis.WebSocket || globalThis.MozWebSocket,
5-
usingBrowserWebSocket: true
5+
usingBrowserWebSocket: true,
6+
defaultBinaryType: "arraybuffer"
67
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
WebSocket: require("ws"),
3-
usingBrowserWebSocket: false
3+
usingBrowserWebSocket: false,
4+
defaultBinaryType: "nodebuffer"
45
};

lib/transports/websocket.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ const parser = require("engine.io-parser");
33
const parseqs = require("parseqs");
44
const yeast = require("yeast");
55
const { pick } = require("../util");
6-
const { WebSocket, usingBrowserWebSocket } = require("./websocket-constructor");
6+
const {
7+
WebSocket,
8+
usingBrowserWebSocket,
9+
defaultBinaryType
10+
} = require("./websocket-constructor");
711

812
const debug = require("debug")("engine.io-client:websocket");
913

@@ -88,16 +92,7 @@ class WS extends Transport {
8892
return this.emit("error", err);
8993
}
9094

91-
if (this.ws.binaryType === undefined) {
92-
this.supportsBinary = false;
93-
}
94-
95-
if (this.ws.supports && this.ws.supports.binary) {
96-
this.supportsBinary = true;
97-
this.ws.binaryType = "nodebuffer";
98-
} else {
99-
this.ws.binaryType = "arraybuffer";
100-
}
95+
this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
10196

10297
this.addEventListeners();
10398
}

0 commit comments

Comments
 (0)