forked from eatvio/eatvio_app
feat(video_calls): call ended push, recall button for message
This commit is contained in:
@@ -48,6 +48,8 @@ class VideoCallCallKitCoordinator {
|
||||
|
||||
_eventSubscription = FlutterCallkitIncoming.onEvent.listen(_onCallKitEvent);
|
||||
|
||||
VideoCallFcmHandler.registerForegroundListener();
|
||||
|
||||
if (Platform.isIOS) {
|
||||
_voipDiagnosticsChannel.setMethodCallHandler((call) async {
|
||||
switch (call.method) {
|
||||
@@ -67,7 +69,6 @@ class VideoCallCallKitCoordinator {
|
||||
}
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
VideoCallFcmHandler.registerForegroundListener();
|
||||
FlutterCallkitIncoming.acceptCallHandle(_onNativeAcceptCallHandle);
|
||||
await FlutterCallkitIncoming.requestNotificationPermission(<
|
||||
String,
|
||||
@@ -179,7 +180,7 @@ class VideoCallCallKitCoordinator {
|
||||
case CallEventActionCallDecline():
|
||||
await _handleDeclineEvent(event);
|
||||
case CallEventActionCallEnded():
|
||||
await _handleDeclineEvent(event);
|
||||
await _handleEndedEvent(event);
|
||||
case CallEventActionCallTimeout():
|
||||
await _handleDeclineEvent(event);
|
||||
default:
|
||||
@@ -211,6 +212,18 @@ class VideoCallCallKitCoordinator {
|
||||
await _handleDecline(id);
|
||||
}
|
||||
|
||||
Future<void> _handleEndedEvent(CallEvent event) async {
|
||||
final id = _callKitEventId(event);
|
||||
if (id == null) {
|
||||
log(
|
||||
'VideoCallCallKitCoordinator: ended event without callKit id, event=$event',
|
||||
name: 'VideoCallCallKit',
|
||||
);
|
||||
return;
|
||||
}
|
||||
await _handleEnded(id);
|
||||
}
|
||||
|
||||
Future<void> _captureCallKitEventToSentry(CallEvent event) async {
|
||||
if (!Platform.isIOS) return;
|
||||
final context = <String, Object?>{
|
||||
@@ -468,6 +481,8 @@ class VideoCallCallKitCoordinator {
|
||||
_acceptHandledCallKitIds.add(callKitId);
|
||||
_suppressedEndCallKitIds.add(callKitId);
|
||||
|
||||
unawaited(_manager.notifyIncomingCallAccepted(conversationUuid));
|
||||
|
||||
try {
|
||||
if (!Platform.isIOS) {
|
||||
await FlutterCallkitIncoming.endCall(callKitId);
|
||||
@@ -565,6 +580,25 @@ class VideoCallCallKitCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleEnded(String callKitId) async {
|
||||
if (_suppressedEndCallKitIds.contains(callKitId)) {
|
||||
log(
|
||||
'VideoCallCallKitCoordinator: ignore spurious ended during accept, callKitId=$callKitId',
|
||||
name: 'VideoCallCallKit',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
_callKitParamsById.remove(callKitId);
|
||||
if (_activeCallKitId == callKitId) {
|
||||
_activeCallKitId = null;
|
||||
}
|
||||
|
||||
try {
|
||||
await FlutterCallkitIncoming.endCall(callKitId);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
static String _parseConversationUuid(
|
||||
Map<String, Object?> extra, {
|
||||
String? handle,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
|
||||
|
||||
/// Dismisses incoming call UI after a remote `video_call_ended` push.
|
||||
abstract final class VideoCallEndedPushHandler {
|
||||
static Future<void> dismissIncomingCallUi() async {
|
||||
try {
|
||||
final activeCalls = await FlutterCallkitIncoming.activeCalls();
|
||||
for (final call in activeCalls) {
|
||||
try {
|
||||
await FlutterCallkitIncoming.endCall(call.id);
|
||||
} catch (_) {}
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
await FlutterCallkitIncoming.endAllCalls();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_push_payload.dart';
|
||||
|
||||
/// Marker for a data-only `video_call_ended` push (no conversation uuid required).
|
||||
class VideoCallEndedPushPayload {
|
||||
const VideoCallEndedPushPayload._();
|
||||
|
||||
static VideoCallEndedPushPayload? tryParse(Map<String, dynamic> data) {
|
||||
if (!VideoCallPushPayload.isEndedVideoCall(data)) return null;
|
||||
return const VideoCallEndedPushPayload._();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_ended_push_handler.dart';
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_ended_push_payload.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:eatvio_app/firebase_options.dart';
|
||||
@@ -43,9 +45,35 @@ abstract final class VideoCallFcmHandler {
|
||||
RemoteMessage message, {
|
||||
required String source,
|
||||
}) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
|
||||
final data = Map<String, dynamic>.from(message.data);
|
||||
|
||||
final endedPayload = VideoCallEndedPushPayload.tryParse(data);
|
||||
if (endedPayload != null) {
|
||||
if (Platform.isAndroid && source == 'background') {
|
||||
log(
|
||||
'VideoCallFcmHandler: skip background ended call, handled by native FCM service',
|
||||
name: 'VideoCallFcm',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
log(
|
||||
'VideoCallFcmHandler: dismiss incoming call UI, source=$source',
|
||||
name: 'VideoCallFcm',
|
||||
);
|
||||
try {
|
||||
await VideoCallEndedPushHandler.dismissIncomingCallUi();
|
||||
} catch (e, st) {
|
||||
log(
|
||||
'VideoCallFcmHandler: failed to dismiss incoming call UI: $e',
|
||||
name: 'VideoCallFcm',
|
||||
stackTrace: st,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Platform.isAndroid) return;
|
||||
if (data.isEmpty) return;
|
||||
|
||||
final payload = VideoCallPushPayload.tryParse(data);
|
||||
|
||||
@@ -52,6 +52,28 @@ class VideoCallPushPayload {
|
||||
);
|
||||
}
|
||||
|
||||
static bool isEndedVideoCall(Map<String, dynamic> data) {
|
||||
final type = _string(data, const [
|
||||
'type',
|
||||
'notification_type',
|
||||
'event',
|
||||
'action',
|
||||
'push_type',
|
||||
'call_type',
|
||||
]);
|
||||
if (type != null) {
|
||||
final normalized = type.toLowerCase().replaceAll('-', '_');
|
||||
if (normalized == 'video_call_ended' || normalized == 'video_call_end') {
|
||||
return true;
|
||||
}
|
||||
if (normalized.contains('video_call') &&
|
||||
(normalized.contains('ended') || normalized.endsWith('_end'))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isIncomingVideoCall(Map<String, dynamic> data) {
|
||||
final type = _string(data, const [
|
||||
'type',
|
||||
@@ -91,6 +113,9 @@ class VideoCallPushPayload {
|
||||
return false;
|
||||
}
|
||||
|
||||
static String? conversationUuidFromData(Map<String, dynamic> data) =>
|
||||
_conversationUuid(data);
|
||||
|
||||
static String? _conversationUuid(Map<String, dynamic> data) {
|
||||
final fromData = _string(data, const [
|
||||
'conversationUuid',
|
||||
|
||||
@@ -23,4 +23,10 @@ abstract class VideoCallService {
|
||||
@Path('conversation') required String conversationUuid,
|
||||
@Body() required Map<String, dynamic> body,
|
||||
});
|
||||
|
||||
@POST('/api/v2/chat/{conversation}/video-call/accept')
|
||||
Future<VideoCallAcceptResponse> notifyCallAccepted({
|
||||
@Path('conversation') required String conversationUuid,
|
||||
@Body() required Map<String, dynamic> body,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user