-
Notifications
You must be signed in to change notification settings - Fork 60
Description
A few questions:
- why are there so many public methods? Shouldn't
encodePayloadanddecodePayloadbe enough?
Currently, it seems that:
- encodePayload/decodePayload is used for polling transport
- encodePacket/decodePacket is used for websocket transport
Quoting socketio/engine.io-client#140 (comment):
encodePacketis more efficient in this case so we can leverage the WS framing
Is that really more efficient? Shouldn't we rather concatenate two packets instead of sending them one by one? (I think that's why, currently, sending a buffer with socket.io results in two frames: socketio/socket.io#2444)
- according to the following comment, I understand that utf8 is needed for mixing binary/string content
The reason we are using utf8.js is that when encoding mixed binary and string contents, we need to support multibyte strings. It is easiest to encode the multibyte characters so that we can do a transformation to a binary representation one byte at a time.
Yet it seems that, since encodePayload always call encodePacket with utf8encode to true, the strings transmitted over polling transport are UTF8-encoded twice (socketio/engine.io#315):
exports.encodePayload = function (packets, supportsBinary, callback) {
...
if (supportsBinary) {
return exports.encodePayloadAsBinary(packets, callback);
// which call encodePacket with utf8encode = true => OK
}
...
function encodeOne(packet, doneCallback) {
exports.encodePacket(packet, supportsBinary, true, function(message) {
doneCallback(null, setLengthHeader(message));
});
// since the payload is not encoded as binary, shouldn't utf8encode be set to false here?
}
}