From 6a77802eb4d585b99a1152dbde9e6f70da064862 Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Wed, 7 Sep 2022 19:22:49 +0800 Subject: [PATCH] add participant id when resuming (#425) * changeset * prettier --- .changeset/slow-chefs-yawn.md | 5 +++++ src/api/SignalClient.ts | 9 ++++++++- src/room/RTCEngine.ts | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changeset/slow-chefs-yawn.md diff --git a/.changeset/slow-chefs-yawn.md b/.changeset/slow-chefs-yawn.md new file mode 100644 index 0000000000..15611e178d --- /dev/null +++ b/.changeset/slow-chefs-yawn.md @@ -0,0 +1,5 @@ +--- +'livekit-client': patch +--- + +add participant id when reconnecting diff --git a/src/api/SignalClient.ts b/src/api/SignalClient.ts index 2d4d7c255c..57e5646b91 100644 --- a/src/api/SignalClient.ts +++ b/src/api/SignalClient.ts @@ -38,6 +38,9 @@ interface ConnectOpts { /** internal */ reconnect?: boolean; + /** internal */ + sid?: string; + /** @deprecated */ publishOnly?: string; @@ -161,12 +164,13 @@ export class SignalClient { return res as JoinResponse; } - async reconnect(url: string, token: string): Promise { + async reconnect(url: string, token: string, sid?: string): Promise { this.isReconnecting = true; // clear ping interval and restart it once reconnected this.clearPingInterval(); await this.connect(url, token, { reconnect: true, + sid, }); } @@ -607,6 +611,9 @@ function createConnectionParams(token: string, info: ClientInfo, opts?: ConnectO // opts if (opts?.reconnect) { params.set('reconnect', '1'); + if (opts?.sid) { + params.set('sid', opts.sid); + } } if (opts?.autoSubscribe !== undefined) { params.set('auto_subscribe', opts.autoSubscribe ? '1' : '0'); diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index 8899258914..de14e0726c 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -120,6 +120,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit private reconnectTimeout?: ReturnType; + private participantSid?: string; + constructor(private options: RoomOptions) { super(); this.client = new SignalClient(); @@ -237,6 +239,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit return; } + this.participantSid = joinResponse.participant?.sid; + // update ICE servers before creating PeerConnection if (joinResponse.iceServers && !this.rtcConfig.iceServers) { const rtcIceServers: RTCIceServer[] = []; @@ -798,7 +802,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit } try { - await this.client.reconnect(this.url, this.token); + await this.client.reconnect(this.url, this.token, this.participantSid); } catch (e) { let message = ''; if (e instanceof Error) {