WebRTC signaling heartbeat

This commit is contained in:
2025-10-19 18:58:54 +08:00
parent 43d767bc03
commit f4b28c3fa2
7 changed files with 42 additions and 23 deletions

View File

@@ -178,6 +178,7 @@ class CallNotifier extends _$CallNotifier {
accountId: p.userinfo.id,
account: p.userinfo,
joinedAt: DateTime.now(),
isLocal: true,
);
return CallParticipantLive(
participant: participantInfo,

View File

@@ -6,7 +6,7 @@ part of 'call.dart';
// RiverpodGenerator
// **************************************************************************
String _$callNotifierHash() => r'91e546c8711d1b46740ad592cbe481173b227e7b';
String _$callNotifierHash() => r'6db330370d473eaea313dd9f9439d261c355095f';
/// See also [CallNotifier].
@ProviderFor(CallNotifier)

View File

@@ -57,6 +57,7 @@ class WebRTCSignaling {
final StreamController<WebRTCWelcomeMessage> _welcomeController =
StreamController<WebRTCWelcomeMessage>.broadcast();
WebSocketChannel? _channel;
Timer? _heartbeatTimer;
Stream<SignalingMessage> get messages => _messageController.stream;
Stream<WebRTCWelcomeMessage> get welcomeMessages => _welcomeController.stream;
@@ -88,6 +89,9 @@ class WebRTCSignaling {
}
await _channel!.ready;
// Start heartbeat timer
_heartbeatTimer = Timer.periodic(const Duration(seconds: 30), (timer) => _sendHeartbeat());
_channel!.stream.listen(
(data) {
final dataStr =
@@ -196,7 +200,15 @@ class WebRTCSignaling {
);
}
void _sendHeartbeat() {
if (_channel == null) return;
talker.info('[WebRTC Signaling] Sending heartbeat');
final packet = WebSocketPacket(type: 'heartbeat', data: null);
_channel!.sink.add(jsonEncode(packet.toJson()));
}
void disconnect() {
_heartbeatTimer?.cancel();
_channel?.sink.close();
_messageController.close();
_welcomeController.close();