feat(video_calls): call accepting and declingn handling

This commit is contained in:
misha
2026-10-23 14:11:20 +03:00
parent 2779f79464
commit 0ddd4c6b14
26 changed files with 959 additions and 170 deletions

View File

@@ -89,6 +89,7 @@ void main() {
required int authorId,
required String roomId,
String data = 'socket message',
String? callId,
}) {
return _FakeChannelReadEvent(
jsonEncode(<String, dynamic>{
@@ -100,6 +101,7 @@ void main() {
'read_by_to_user': false,
'is_author_message_auth_user': false,
'room_id': roomId,
if (callId != null) 'call_id': callId,
}),
);
}
@@ -418,8 +420,10 @@ void main() {
() async {
const chatId = 'chat-id';
final presented = <String>[];
String? presentedCallId;
chatsCubit.presentIncomingVideoCall = (payload) async {
presented.add(payload.conversationUuid);
presentedCallId = payload.callId;
};
chatsCubit.emit(
ChatsState(
@@ -436,11 +440,13 @@ void main() {
authorId: 7,
roomId: chatId,
data: 'Анна начал(а) видеозвонок.',
callId: '6f1e8c0a-1b2c-4d3e-8f90-aabbccddeeff',
),
);
await Future.delayed(const Duration(milliseconds: 100));
expect(presented, [chatId]);
expect(presentedCallId, '6f1e8c0a-1b2c-4d3e-8f90-aabbccddeeff');
await controller.close();
},
@@ -1063,6 +1069,84 @@ void main() {
expect(ended, ['conv-1']);
await declined.close();
});
test('video-call-accepted closes ringing on the other device', () async {
final accepted = StreamController<ChannelReadEvent>.broadcast();
when(mockWsManager.newMessagesStream).thenReturn(null);
when(mockWsManager.reconnected).thenAnswer((_) => const Stream.empty());
when(mockWsManager.videoCallDeclinedStream).thenReturn(null);
when(mockWsManager.videoCallEndedStream).thenReturn(null);
when(
mockWsManager.videoCallAcceptedStream,
).thenAnswer((_) => accepted.stream);
chatsCubit.currentDeviceHwId = () async => 'device-iphone';
final dismissed = <String?>[];
final ended = <String?>[];
chatsCubit.dismissIncomingVideoCall = (uuid) async {
dismissed.add(uuid);
};
chatsCubit.endActiveVideoCall = ({conversationUuid, callId}) async {
ended.add(conversationUuid);
};
await chatsCubit.connectToWebSocket();
accepted.add(
_FakeChannelReadEvent(
jsonEncode(<String, dynamic>{
'call_id': 'call-1',
'conversation_uuid': 'conv-1',
'status': 'accepted',
'accepted_device_id': 'device-android',
'accepted_client': 'android',
}),
),
);
await Future<void>.delayed(Duration.zero);
expect(dismissed, ['conv-1']);
expect(ended, isEmpty);
await accepted.close();
});
test(
'video-call-accepted keeps the call on the device that answered',
() async {
final accepted = StreamController<ChannelReadEvent>.broadcast();
when(mockWsManager.newMessagesStream).thenReturn(null);
when(mockWsManager.reconnected).thenAnswer((_) => const Stream.empty());
when(mockWsManager.videoCallDeclinedStream).thenReturn(null);
when(mockWsManager.videoCallEndedStream).thenReturn(null);
when(
mockWsManager.videoCallAcceptedStream,
).thenAnswer((_) => accepted.stream);
chatsCubit.currentDeviceHwId = () async => 'Device-iPhone';
final dismissed = <String?>[];
chatsCubit.dismissIncomingVideoCall = (uuid) async {
dismissed.add(uuid);
};
chatsCubit.endActiveVideoCall = ({conversationUuid, callId}) async {
fail('accepted call must stay on the answering device');
};
await chatsCubit.connectToWebSocket();
accepted.add(
_FakeChannelReadEvent(
jsonEncode(<String, dynamic>{
'call_id': 'call-1',
'conversation_uuid': 'conv-1',
'status': 'accepted',
'accepted_device_id': 'device-iphone',
}),
),
);
await Future<void>.delayed(Duration.zero);
expect(dismissed, isEmpty);
await accepted.close();
},
);
});
}

View File

@@ -1,5 +1,4 @@
import 'package:eatvio_app/features/video_calls/managers/video_call_manager.dart';
import 'package:eatvio_app/features/video_calls/models/video_call_models.dart';
import 'package:eatvio_app/features/video_calls/services/video_call_foreground_coordinator.dart';
import 'package:eatvio_app/features/video_calls/services/video_call_lifecycle_binding.dart';
import 'package:eatvio_app/features/video_calls/repositories/video_call_repository.dart';
@@ -120,33 +119,17 @@ void main() {
);
test(
'decline of a call that was never joined notifies the backend via /decline',
'decline of a call that was never joined does not POST /decline from Dart',
() async {
when(
await manager.declineIncomingCall('other-uuid');
verifyNever(
mockRepository.notifyCallDeclined(
conversationUuid: anyNamed('conversationUuid'),
hwId: anyNamed('hwId'),
callId: anyNamed('callId'),
),
).thenAnswer(
(_) async => const VideoCallDeclineResponse(
sent: true,
devicesNotified: 1,
),
);
await manager.declineIncomingCall(
'other-uuid',
callId: 'call-uuid-1',
);
verify(
mockRepository.notifyCallDeclined(
conversationUuid: 'other-uuid',
hwId: 'test-hw-id-android-01',
callId: 'call-uuid-1',
),
).called(1);
verifyNever(mockRepository.notifyCallEnded(any));
},
);

View File

@@ -33,6 +33,15 @@ void main() {
expect(payload.messageId, 1);
});
test('keeps the server call id on the incoming payload', () {
final payload = VideoCallChatSignal.incomingPayload(
message: message(data: 'Анна начал(а) видеозвонок.'),
callId: ' 6f1e8c0a-1b2c-4d3e-8f90-aabbccddeeff ',
);
expect(payload?.callId, '6f1e8c0a-1b2c-4d3e-8f90-aabbccddeeff');
});
test('recognizes an english realtime video call start', () {
expect(
VideoCallChatSignal.kindOf(message(data: 'Anna started a video call.')),

View File

@@ -34,15 +34,22 @@ void main() {
test('an accept marker does not tear down the call this device joined', () {
final signal = VideoCallSocketSignal.tryParseEnded(<String, dynamic>{
'call_id': 'call-1',
'reason': 'accepted',
'status': 'accepted',
'accepted_device_id': 'device-iphone',
'accepted_client': 'ios',
});
expect(signal?.endsActiveCall, isFalse);
expect(signal?.reason, VideoCallEndReason.accepted);
expect(signal?.acceptedDeviceId, 'device-iphone');
expect(signal?.acceptedClient, 'ios');
});
test('ignores a payload without a call or a conversation', () {
expect(
VideoCallSocketSignal.tryParseDeclined(<String, dynamic>{'status': 'declined'}),
VideoCallSocketSignal.tryParseDeclined(<String, dynamic>{
'status': 'declined',
}),
isNull,
);
});