Closed zackliu closed 3 months ago
@darrachequesne We can discuss whether the design is acceptable, and I will write some more test.
@darrachequesne Do you have any comments on the design?
Hi @zackliu,
Thanks for your work on this.
However, I still don't think the use case is common enough for this to be included here in the package.
@darrachequesne I think there're two parts in it.
Authorization
in long polling and access_token
query in websocketI admit we can use a separate library for the second purpose but what about the first one? Do you think it's acceptable to have such a property as it's hard to achieve outside this package?
For 1, the transportOptions
option should be sufficient I think:
import { io } from "socket.io-client";
const socket = io({
transportOptions: {
polling: {
extraHeaders: {
Authorization: myToken
}
},
websocket: {
query: {
access_token: myToken
}
}
}
});
Reference: https://socket.io/docs/v4/client-options/#transportoptions
I think this can be closed now. Please reopen if needed!
Note: the
engine.io.js
file is the generated output ofmake engine.io.js
, and should not be manually modified.The kind of change this PR does introduce
Current behaviour
The engine.io connection directly connects to the
hostname
,path
.New behaviour
If
negotiatePath
is set, engine.io will make a fetch to the<hostname>/<negotiatePath>
to get a JSON encoded response first.if succeeded, the engine.io will parse the
url
got in negotiation and replace it with the previoushostname
,path
,port
andprotocol
inopts
. As theopts
has changed, everything is unchanged then (e.g when constructing a transport, it still read from opts).Another change is adding a
token
inopts
. Iftoken
is set, it will be used inAuthorization
for long polling, andaccess_token
query for websocket. Thistoken
can be set in opts directly but it can also be override in negotiation.Other information (e.g. related issues)
This is the implementation of issue https://github.com/socketio/socket.io/issues/4825