forked from eatvio/eatvio_app
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:
@@ -11,6 +11,7 @@ import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_chat_signal.dart';
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_ended_push_handler.dart';
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_socket_signal.dart';
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_incoming_push_presenter.dart';
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_push_payload.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -23,11 +24,15 @@ class ChatsCubit extends Cubit<ChatsState> {
|
||||
StreamSubscription? newIncomingMessagesSubscription;
|
||||
StreamSubscription? newLastMessageSubscription;
|
||||
StreamSubscription<void>? reconnectedSubscription;
|
||||
StreamSubscription? videoCallDeclinedSubscription;
|
||||
StreamSubscription? videoCallEndedSubscription;
|
||||
final Set<int> _presentedVideoCallMessageIds = {};
|
||||
|
||||
/// Test seam. Production uses CallKit.
|
||||
Future<void> Function(VideoCallPushPayload payload)? presentIncomingVideoCall;
|
||||
Future<void> Function(String? conversationUuid)? dismissIncomingVideoCall;
|
||||
Future<void> Function({String? conversationUuid, String? callId})?
|
||||
endActiveVideoCall;
|
||||
|
||||
ChatsCubit({
|
||||
required this.chatRepository,
|
||||
@@ -55,6 +60,26 @@ class ChatsCubit extends Cubit<ChatsState> {
|
||||
_handleNewMessageViaSocket(event.data);
|
||||
});
|
||||
|
||||
await videoCallDeclinedSubscription?.cancel();
|
||||
videoCallDeclinedSubscription = wsManager.videoCallDeclinedStream?.listen(
|
||||
(event) {
|
||||
unawaited(
|
||||
_closeCallFromSocket(
|
||||
VideoCallSocketSignal.tryParseDeclined(event.data),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
await videoCallEndedSubscription?.cancel();
|
||||
videoCallEndedSubscription = wsManager.videoCallEndedStream?.listen((
|
||||
event,
|
||||
) {
|
||||
unawaited(
|
||||
_closeCallFromSocket(VideoCallSocketSignal.tryParseEnded(event.data)),
|
||||
);
|
||||
});
|
||||
|
||||
await reconnectedSubscription?.cancel();
|
||||
reconnectedSubscription = wsManager.reconnected.listen((_) {
|
||||
unawaited(getChatRooms());
|
||||
@@ -262,6 +287,34 @@ class ChatsCubit extends Cubit<ChatsState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _closeCallFromSocket(VideoCallSocketSignal? signal) async {
|
||||
if (signal == null) return;
|
||||
if (signal.endsActiveCall) {
|
||||
final endActive = endActiveVideoCall;
|
||||
if (endActive != null) {
|
||||
await endActive(
|
||||
conversationUuid: signal.conversationUuid,
|
||||
callId: signal.callId,
|
||||
);
|
||||
} else {
|
||||
await VideoCallEndedPushHandler.endActiveCallIfMatches(
|
||||
conversationUuid: signal.conversationUuid,
|
||||
callId: signal.callId,
|
||||
);
|
||||
}
|
||||
}
|
||||
final dismiss = dismissIncomingVideoCall;
|
||||
if (dismiss != null) {
|
||||
await dismiss(signal.conversationUuid);
|
||||
return;
|
||||
}
|
||||
await VideoCallEndedPushHandler.dismissIncomingCallUi(
|
||||
conversationUuid: signal.conversationUuid,
|
||||
callId: signal.callId,
|
||||
reason: signal.reason,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _dismissIncomingVideoCallUi(String? conversationUuid) async {
|
||||
try {
|
||||
final dismiss = dismissIncomingVideoCall;
|
||||
@@ -308,6 +361,8 @@ class ChatsCubit extends Cubit<ChatsState> {
|
||||
@override
|
||||
Future<void> close() {
|
||||
newIncomingMessagesSubscription?.cancel();
|
||||
videoCallDeclinedSubscription?.cancel();
|
||||
videoCallEndedSubscription?.cancel();
|
||||
reconnectedSubscription?.cancel();
|
||||
return super.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user