Skip to content

Commit 8bf6999

Browse files
ThanhDodeurOdooalexkuhn
authored andcommitted
[FIX] prevent potential race condition during websocket init
Before this commit, the connection of the rtc session on the server, which was dependent on the speed of asynchronous mediasoup calls (`router.createWebRtcTransport`) could race the initialization of the websocket on the client. This commit fixes this issue by signaling to the client when the websocket is authenticated as soon as possible, before starting the RTC connection process.
1 parent f8263ab commit 8bf6999

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/services/ws.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export async function start(options) {
5858
});
5959
session.remote = remoteAddress;
6060
logger.info(`session [${session.name}] authenticated and created`);
61-
webSocket.send(); // client can start using ws after this message.
6261
} catch (error) {
6362
logger.warn(`${error.message} : ${error.cause ?? ""}`);
6463
if (error instanceof AuthenticationError) {
@@ -123,6 +122,7 @@ async function connect(webSocket, { channelUUID, jwt }) {
123122
if (!session_id) {
124123
throw new AuthenticationError("Malformed JWT payload");
125124
}
125+
webSocket.send(); // client can start using ws after this message.
126126
const bus = new Bus(webSocket, { batchDelay: config.timeouts.busBatch });
127127
const { session } = Channel.join(channel.uuid, session_id);
128128
session.once("close", ({ code }) => {

0 commit comments

Comments
 (0)