File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ patch type="fixed" "Add signal RTT tracking via pingReq/pongResp"
Original file line number Diff line number Diff line change @@ -53,8 +53,11 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
5353 Timer ? _pingIntervalTimer;
5454
5555 int get pingCount => _pingCount;
56-
5756 int _pingCount = 0 ;
57+
58+ /// Signal round-trip time in milliseconds, calculated from pingReq/pongResp.
59+ int get rtt => _rtt;
60+ int _rtt = 0 ;
5861 String ? participantSid;
5962
6063 int _requestId = 0 ;
@@ -345,6 +348,11 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
345348 _pingCount++ ;
346349 _resetPingTimeout ();
347350 break ;
351+ case lk_rtc.SignalResponse_Message .pongResp:
352+ _rtt = DateTime .timestamp ().millisecondsSinceEpoch - msg.pongResp.lastPingTimestamp.toInt ();
353+ _pingCount++ ;
354+ _resetPingTimeout ();
355+ break ;
348356 case lk_rtc.SignalResponse_Message .reconnect:
349357 events.emit (SignalReconnectResponseEvent (response: msg.reconnect));
350358 break ;
@@ -379,7 +387,14 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
379387 }
380388
381389 void _sendPing () {
382- _sendRequest (lk_rtc.SignalRequest ()..ping = Int64 (DateTime .timestamp ().millisecondsSinceEpoch));
390+ final now = DateTime .timestamp ().millisecondsSinceEpoch;
391+ // Send both ping and pingReq for compatibility with old and new servers
392+ _sendRequest (lk_rtc.SignalRequest ()..ping = Int64 (now));
393+ _sendRequest (lk_rtc.SignalRequest ()
394+ ..pingReq = lk_rtc.Ping (
395+ timestamp: Int64 (now),
396+ rtt: Int64 (_rtt),
397+ ));
383398 }
384399
385400 void _startPingInterval () {
You can’t perform that action at this time.
0 commit comments