Skip to content

Commit

Permalink
Treat all signal messages as ping response (#933)
Browse files Browse the repository at this point in the history
* Treat all signal messages as ping

In cases of rooms that are highly active, it's possible to have a lot of
signal messages queued that it blocks the ping messages for awhile.

Since the purpose of ping/pong is to ensure signal channel is active, it
makes sense to use any type of signal traffic as that indicator of liveliness.

* changeset
  • Loading branch information
davidzhao authored Nov 14, 2023
1 parent bfa552b commit 93ee41b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/healthy-pillows-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Treat all signal messages as ping response
8 changes: 7 additions & 1 deletion src/api/SignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ export class SignalClient {
log.debug('received unsupported message');
return;
}

let pingHandled = false;
if (msg.case === 'answer') {
const sd = fromProtoSessionDescription(msg.value);
if (this.onAnswer) {
Expand Down Expand Up @@ -626,13 +628,17 @@ export class SignalClient {
this.onSubscriptionError(msg.value);
}
} else if (msg.case === 'pong') {
this.resetPingTimeout();
} else if (msg.case === 'pongResp') {
this.rtt = Date.now() - Number.parseInt(msg.value.lastPingTimestamp.toString());
this.resetPingTimeout();
pingHandled = true;
} else {
log.debug('unsupported message', msg);
}

if (!pingHandled) {
this.resetPingTimeout();
}
}

setReconnected() {
Expand Down

0 comments on commit 93ee41b

Please sign in to comment.