Skip to content

Commit

Permalink
Treat all signal messages as ping
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidzhao committed Nov 13, 2023
1 parent 800b866 commit 63bf7ec
Showing 1 changed file with 7 additions and 1 deletion.
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 63bf7ec

Please sign in to comment.