feat(video_calls): ios calle mic fix, infinite loading after accepting call on an oppened app fix, incaming call declining after declining on a different device

This commit is contained in:
misha
2026-10-22 14:56:15 +03:00
parent 992573aead
commit d8d7a211bd
24 changed files with 924 additions and 142 deletions

View File

@@ -1027,6 +1027,42 @@ void main() {
await reconnectController.close();
},
);
test('video-call-declined closes the call on this device', () async {
final declined = StreamController<ChannelReadEvent>.broadcast();
when(mockWsManager.newMessagesStream).thenReturn(null);
when(mockWsManager.reconnected).thenAnswer((_) => const Stream.empty());
when(
mockWsManager.videoCallDeclinedStream,
).thenAnswer((_) => declined.stream);
when(mockWsManager.videoCallEndedStream).thenReturn(null);
final dismissed = <String?>[];
final ended = <String?>[];
chatsCubit.dismissIncomingVideoCall = (uuid) async {
dismissed.add(uuid);
};
chatsCubit.endActiveVideoCall = ({conversationUuid, callId}) async {
ended.add(conversationUuid);
expect(callId, 'call-1');
};
await chatsCubit.connectToWebSocket();
declined.add(
_FakeChannelReadEvent(
jsonEncode(<String, dynamic>{
'call_id': 'call-1',
'conversation_uuid': 'conv-1',
'status': 'declined',
}),
),
);
await Future<void>.delayed(Duration.zero);
expect(dismissed, ['conv-1']);
expect(ended, ['conv-1']);
await declined.close();
});
});
}

View File

@@ -1,4 +1,5 @@
import 'package:eatvio_app/features/video_calls/services/video_call_audio_session_coordinator.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -28,7 +29,7 @@ void main() {
expect(calls, ['activate', 'activate', 'restart', 'deactivate']);
});
test('startCallKitCapture restarts the AudioEngine ADM', () async {
test('startCallKitCapture starts the AudioEngine ADM without stopping', () async {
final adm = <String>[];
final coordinator = VideoCallAudioSessionCoordinator(
isIos: true,
@@ -40,7 +41,45 @@ void main() {
await coordinator.startCallKitCapture();
expect(coordinator.isActive, isTrue);
expect(adm, ['stop', 'start']);
expect(adm, ['start']);
});
test('stop stops the AudioEngine ADM', () async {
final adm = <String>[];
final coordinator = VideoCallAudioSessionCoordinator(
isIos: true,
iosCallAudioSession: (_) async {},
stopLocalRecording: () async => adm.add('stop'),
startLocalRecording: () async => adm.add('start'),
);
await coordinator.startCallKitCapture();
await coordinator.stop();
expect(coordinator.isActive, isFalse);
expect(adm, ['start', 'stop']);
});
test('forwards a later CallKit audio activation', () async {
TestWidgetsFlutterBinding.ensureInitialized();
final coordinator = VideoCallAudioSessionCoordinator(isIos: true);
var activations = 0;
coordinator.onIosAudioSessionActivated = () async {
activations++;
};
const codec = StandardMethodCodec();
final data = codec.encodeMethodCall(
const MethodCall('audioSessionActivated'),
);
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.handlePlatformMessage(
'com.eatvioapp/call_audio_session',
data,
(_) {},
);
expect(activations, 1);
});
test('stop clears the active session when deactivate fails', () async {

View File

@@ -75,6 +75,23 @@ void main() {
isFalse,
);
});
test('a legacy ring without call_id still matches the conversation', () {
const call = CallKitParams(
id: conversation,
handle: conversation,
extra: <String, dynamic>{'conversationUuid': conversation},
);
expect(
VideoCallEndedPushHandler.callMatches(
call: call,
conversationUuid: conversation,
callId: '0199a0b1-7c2d-7e3f-8a4b-5c6d7e8f9a0b',
),
isTrue,
);
});
});
group('VideoCallEndedPushHandler.dismissIncomingCallUi (CallKit)', () {

View File

@@ -66,23 +66,11 @@ void main() {
);
});
test('does not report the end while the other user is still in the room', () {
test('reports the end so the other devices drop the call', () {
expect(
shouldNotifyCallEnded(
alreadyNotified: false,
hasConversation: true,
peerStillInRoom: true,
),
isFalse,
);
});
test('reports the end when this client is the last participant', () {
expect(
shouldNotifyCallEnded(
alreadyNotified: false,
hasConversation: true,
peerStillInRoom: false,
),
isTrue,
);
@@ -90,7 +78,13 @@ void main() {
shouldNotifyCallEnded(
alreadyNotified: true,
hasConversation: true,
peerStillInRoom: false,
),
isFalse,
);
expect(
shouldNotifyCallEnded(
alreadyNotified: false,
hasConversation: false,
),
isFalse,
);
@@ -118,6 +112,78 @@ void main() {
);
});
test('an incoming start does not tear down the accepted CallKit call', () {
expect(
shouldPreserveCallKitWhenStartingCall(
previousConversationUuid: '',
nextConversationUuid: 'conv-1',
),
isTrue,
);
expect(
shouldPreserveCallKitWhenStartingCall(
previousConversationUuid: 'conv-1',
nextConversationUuid: 'conv-1',
),
isTrue,
);
expect(
shouldPreserveCallKitWhenStartingCall(
previousConversationUuid: 'conv-old',
nextConversationUuid: 'conv-1',
),
isFalse,
);
});
test('the conversation uuid is not sent as the session call id', () {
expect(
backendVideoCallId(callId: 'conv-1', conversationUuid: 'conv-1'),
isNull,
);
expect(
backendVideoCallId(
callId: '0199a0b1-7c2d-7e3f-8a4b-5c6d7e8f9a0b',
conversationUuid: 'conv-1',
),
'0199a0b1-7c2d-7e3f-8a4b-5c6d7e8f9a0b',
);
expect(
backendVideoCallId(callId: ' ', conversationUuid: 'conv-1'),
isNull,
);
});
test('a lost connection on the visible call screen is not ignored', () {
expect(
isTransientIdleSnapshotWhileCallScreenVisible(
callScreenVisible: true,
conversationUuid: '',
needsManualReconnect: false,
connectError: null,
),
isTrue,
);
expect(
isTransientIdleSnapshotWhileCallScreenVisible(
callScreenVisible: true,
conversationUuid: 'conv-1',
needsManualReconnect: true,
connectError: 'timeout',
),
isFalse,
);
expect(
isTransientIdleSnapshotWhileCallScreenVisible(
callScreenVisible: false,
conversationUuid: '',
needsManualReconnect: false,
connectError: null,
),
isFalse,
);
});
test('a token is not requested again right after leaving', () {
final leftAt = DateTime(2026, 10, 16, 12);
expect(

View File

@@ -0,0 +1,49 @@
import 'dart:convert';
import 'package:eatvio_app/features/video_calls/services/video_call_end_reason.dart';
import 'package:eatvio_app/features/video_calls/services/video_call_socket_signal.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('decline closes the caller call and the other ringing devices', () {
final signal = VideoCallSocketSignal.tryParseDeclined(
jsonEncode(<String, dynamic>{
'call_id': 'call-1',
'conversation_uuid': 'conv-1',
'status': 'declined',
}),
);
expect(signal, isNotNull);
expect(signal!.endsActiveCall, isTrue);
expect(signal.conversationUuid, 'conv-1');
expect(signal.callId, 'call-1');
expect(signal.reason, VideoCallEndReason.declined);
});
test('ended closes an active call', () {
final signal = VideoCallSocketSignal.tryParseEnded(<String, dynamic>{
'conversation_uuid': 'conv-1',
'reason': 'cancelled',
});
expect(signal?.endsActiveCall, isTrue);
expect(signal?.reason, VideoCallEndReason.cancelled);
});
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',
});
expect(signal?.endsActiveCall, isFalse);
});
test('ignores a payload without a call or a conversation', () {
expect(
VideoCallSocketSignal.tryParseDeclined(<String, dynamic>{'status': 'declined'}),
isNull,
);
});
}