Open eudaimos opened 1 year ago
Hi! I think that's because the parser
option is ignored when calling attachApp()
. Could you please try with:
import { Server } from "socket.io";
import { App } from "uWebSockets.js";
import customParser from 'socket.io-msgpack-parser';
- const io = new Server();
+ const io = new Server({
+ serveClient: false,
+ parser: customParser,
+ cors: environment.cors,
+ maxHttpBufferSize: 3.2e8,
+ });
const app = App();
- io.attachApp(app, {
- serveClient: false,
- parser: customParser,
- cors: environment.cors,
- maxHttpBufferSize: 3.2e8,
- });
+ io.attachApp(app);
Something is wrong with the types though, let me check.
thanks @darrachequesne - how did you figure out the parser
option is ignored when calling attachApp()
? Is it getting lost in the initialization of the engine.io
engine?
Before submitting the issue, I saw these lines in index.ts:450-458 and concluded it doesn't matter which way I pass the options, either via Server
constructor or the attachApp()
function.
Also to ensure it wasn't a difference, I tested both ways of initializing the Server
and only posted the code sample that was the last one I tried.
@darrachequesne I was able to get it to work with a different parser using the suggestion in this issue https://github.com/skgdev/socket.io-msgpack-javascript/issues/15
but only when using websocket only (no upgrade) does it encode binary from the server
It seems there is an issue in the parser here: https://github.com/skgdev/socket.io-msgpack-javascript/issues/15
The client sends { type: 0, data: undefined, nsp: '/' }
but the server decodes { type: 0, data: null, nsp: '/' }
and closes the connection because data
should either be undefined
or an object.
Describe the bug Combining a
uWebSockets.js
app using theio.attachApp()
with the msgpack parser (socket.io-msgpack-parser
) does not work. Under the following conditions I'm experiencing different behavior:transports
option, the upgrade will work to connect but the messages are only base64 encoded rather than binarytransports: ['websocket']
only, the connection handshake cannot complete and continuous reconnections are attempted by the client. The messages do appear to be binary however.To Reproduce
Please fill the following code example:
Socket.IO server version:
4.6.1
Socket.IO msgpack Parser version:3.0.2
uWebSockets.js version:uWebSockets.js@uNetworking/uWebSockets.js#v20.20.0
Server
Socket.IO client version:
4.6.1
Socket.IO msgpack Parser version:3.0.2
Client
Expected behavior Whether specifying
transports
option or not on the client, the socket will connect, perform the handshake successfully and messages will be passed back and forth in binary encoding.Platform:
Additional context The Client will repeatedly print
transport close
disconnect logs but the Server logs nothing. When I close the browser tab the client is executing in, then I will see the disconnect log on the Server.The parser works with plain
socket.io.Server
and when wrapping the built-in Node.jsHttpServer
in my testing.