forked from eatvio/eatvio_app
feat(video_calls): call accepting and declingn handling
This commit is contained in:
@@ -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();
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user