Skip to content

Commit

Permalink
add participant id when resuming (#425)
Browse files Browse the repository at this point in the history
* changeset

* prettier
  • Loading branch information
cnderrauber authored Sep 7, 2022
1 parent edd4e56 commit 6a77802
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-chefs-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

add participant id when reconnecting
9 changes: 8 additions & 1 deletion src/api/SignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ interface ConnectOpts {
/** internal */
reconnect?: boolean;

/** internal */
sid?: string;

/** @deprecated */
publishOnly?: string;

Expand Down Expand Up @@ -161,12 +164,13 @@ export class SignalClient {
return res as JoinResponse;
}

async reconnect(url: string, token: string): Promise<void> {
async reconnect(url: string, token: string, sid?: string): Promise<void> {
this.isReconnecting = true;
// clear ping interval and restart it once reconnected
this.clearPingInterval();
await this.connect(url, token, {
reconnect: true,
sid,
});
}

Expand Down Expand Up @@ -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');
Expand Down
6 changes: 5 additions & 1 deletion src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit

private reconnectTimeout?: ReturnType<typeof setTimeout>;

private participantSid?: string;

constructor(private options: RoomOptions) {
super();
this.client = new SignalClient();
Expand Down Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6a77802

Please sign in to comment.