Проблема: < /p>
Я использую ConnectyCube в моем приложении Flutter для обработки видеозвонков. Когда вызов начинается с одного устройства к другому, и приемное устройство находится в фоновом режиме, уведомление вызовов появляется, как и ожидалось. С другой стороны, если я нажимаю на само уведомление, приложение открывается, как и ожидалось. Приложение на передний план.
Нажимая само уведомление, правильно открывает приложение. /> Как я могу убедиться, что когда я нажимаю на «Принять» в уведомлении, приложение доведено на передний план? < /p>
Любая помощь или руководство будут оценены! xmlns:tools="http://schemas.android.com/tools"
package="com.sambuq.care_first">
< /code>
Ниже приведен менеджер вызовов, который я использую < /p>
import 'package:care_first/bloc/auth_bloc/bloc/auth_bloc.dart';
import 'package:care_first/routing/route_names.dart';
import 'package:care_first/screens/my_360_provider/services/fcm/fcm_setup.dart';
import 'package:care_first/screens/my_360_provider/services/fcm/notification_handler.dart';
import 'package:care_first/screens/settings/my_appointments/doctor_appointment/models/my_appointment.dart';
import 'package:care_first/shared/helper/helper_methods.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:universal_io/io.dart';
import 'package:connectycube_flutter_call_kit/connectycube_flutter_call_kit.dart';
import 'package:connectycube_sdk/connectycube_sdk.dart';
import 'call_kit_manager.dart';
import '../utils/consts.dart';
class CallManager {
static String TAG = "CallManager";
static CallManager get instance => _getInstance();
static CallManager? _instance;
static CallManager _getInstance() {
return _instance ??= CallManager._internal();
}
factory CallManager() => _getInstance();
CallManager._internal();
P2PClient? _callClient;
P2PSession? _currentCall;
BuildContext? context;
MediaStream? localMediaStream;
Map remoteStreams = {};
GlobalKey? navigatorKey;
String? selfCubeId;
late String resourceId;
SystemMessagesManager? systemMessagesManager =
CubeChatConnection.instance.systemMessagesManager;
CubeMessage systemMessage = CubeMessage();
final player = AudioPlayer();
Function(bool, String)? onMicMuted;
init(
BuildContext context,
GlobalKey navigatorKey,
String selfCubeId,
String resourceId,
) {
this.context = context;
this.navigatorKey = navigatorKey;
this.selfCubeId = selfCubeId;
this.resourceId = resourceId;
_initCustomMediaConfigs();
if (CubeChatConnection.instance.isAuthenticated()) {
_initCalls(context);
} else {
_initChatConnectionStateListener(context);
}
_initCallKit();
}
destroy() {
_callClient?.destroy();
_callClient = null;
}
void _initCustomMediaConfigs() {
RTCMediaConfig mediaConfig = RTCMediaConfig.instance;
mediaConfig.minHeight = 340;
mediaConfig.minWidth = 480;
mediaConfig.minFrameRate = 25;
RTCConfig.instance.statsReportsInterval = 200;
}
void _initCalls(BuildContext context) {
if (_callClient == null) {
_callClient = P2PClient.instance;
_callClient!.init();
}
// _callClient is P2PClient
_callClient!.onReceiveNewSession = (callSession) async {
print("${'*' * 10} RECEIVED NEW CALL SESSION ${'*' * 10}");
// if (_currentCall != null &&
// _currentCall!.sessionId != callSession.sessionId &&
// _currentCall!.opponentsIds.first.toString() != selfCubeId) {
// callSession.reject();
// return;
// }
if (navigatorKey!.currentContext!.read().user.persona ==
"patient") {
await player
.setReleaseMode(ReleaseMode.loop)
.then(
(value) => player.setSource(AssetSource('audio/ringtone.mp3')))
.then((value) => player.resume());
}
_currentCall = callSession;
var callState = await _getCallState(_currentCall!.sessionId);
await Future.delayed(Duration(seconds: 1));
if (callState == CallState.REJECTED) {
reject(_currentCall!.sessionId, false);
} else if (callState == CallState.ACCEPTED) {
acceptCall(_currentCall!.sessionId,
_currentCall?.cubeSdp.userInfo ?? {}, false);
} else if (callState == CallState.UNKNOWN ||
callState == CallState.PENDING) {
if (callState == CallState.UNKNOWN &&
(Platform.isIOS || Platform.isAndroid)) {
await ConnectycubeFlutterCallKit.setCallState(
sessionId: _currentCall!.sessionId, callState: CallState.PENDING);
}
if (_currentCall!.cubeSdp.callerId.toString() != selfCubeId) {
navigatorKey!.currentContext!.read().p2pSession =
callSession;
// await Future.delayed(Duration(seconds: 1));
// await ConnectycubeFlutterCallKit.showCallNotification(CallEvent(
// sessionId: _currentCall!.sessionId,
// callType: CallType.VIDEO_CALL,
// callerId: _currentCall!.cubeSdp.callerId,
// callerName: "YASH",
// opponentsIds: _currentCall!.opponentsIds,
// userInfo: _currentCall?.cubeSdp.userInfo ?? {},
// ));
print("NOTIFICATION NOT CALLED");
_showIncomingCallScreen(_currentCall!, navigatorKey!.currentContext!);
}
}
_currentCall?.onLocalStreamReceived = (localStream) {
localMediaStream = localStream;
};
_currentCall?.onRemoteStreamReceived = (session, userId, stream) {
remoteStreams[userId] = stream;
};
_currentCall?.onRemoteStreamRemoved = (session, userId, stream) {
remoteStreams.remove(userId);
};
_currentCall?.onReceiveHungUpFromUser =
(session, userId, [userInfo]) async {
print("CALL_MANAGER: onReceiveHungUpFromUser");
/* systemMessage.recipientId = int.tryParse(selfCubeId!);
systemMessage.properties["resourceId"] = resourceId;
systemMessage.properties["action"] = "CALL_HUNGUP";
print("-------------BROADCASTING CALL HUNGUP EVENT-----------");
systemMessagesManager?.sendSystemMessage(systemMessage); */
broadcastSystemMessage("CALL_HUNGUP");
await player.release();
if (GoRouter.of(navigatorKey!.currentContext!)!.location ==
RoutesName.incomingVideoCall) {
GoRouter.of(navigatorKey!.currentContext!).pop();
}
};
};
_callClient!.onSessionClosed = (callSession) async {
if (_currentCall != null &&
_currentCall!.sessionId == callSession.sessionId) {
_currentCall = null;
localMediaStream?.getTracks().forEach((track) async {
await track.stop();
});
await localMediaStream?.dispose();
localMediaStream = null;
remoteStreams.forEach((key, value) async {
await value.dispose();
});
remoteStreams.clear();
CallKitManager.instance.processCallFinished(callSession.sessionId);
if (GoRouter.of(navigatorKey!.currentContext!)!.location ==
RoutesName.incomingVideoCall) {
GoRouter.of(navigatorKey!.currentContext!).pop();
}
}
};
}
void startNewCall(BuildContext context, int callType, int patientCubeId,
MyAppointment appointment, String? businessId, String? moduleId) async {
this.context = context;
Set opponents = {patientCubeId};
if (opponents.isEmpty) return;
if (!kIsWeb) {
if (Platform.isIOS) {
await Helper.setAppleAudioIOMode(AppleAudioIOMode.localAndRemote,
preferSpeakerOutput: true);
}
}
P2PSession callSession =
await _callClient!.createCallSession(callType, opponents);
_currentCall = callSession;
// storing it in authbloc
context.read().p2pSession = callSession;
context.read().resourceId = resourceId;
context.read().selfCubeId = selfCubeId;
String callerName;
if (appointment.doctorMap?["firstname"] != null) {
callerName =
"${appointment.doctorMap?["firstname"]} ${appointment.doctorMap?["lastname"]}";
} else {
callerName = "";
}
await _sendStartCallSignalForOffliners(_currentCall!, callerName);
GoRouter.of(context)
.pushNamed(RoutesName.videoCallDoctorRoute, pathParameters: {
'businessId': encrypt(text: businessId ?? '', context: context),
}, queryParameters: {
'moduleId': moduleId,
}, extra: {
// 'callSession': callSession,
'appointment': appointment,
});
}
void _showIncomingCallScreen(P2PSession callSession, BuildContext context) {
if (navigatorKey!.currentContext != null) {
GoRouter.of(navigatorKey!.currentContext!).pushNamed(
RoutesName.incomingVideoCall,
extra: Map.from(
{"resourceId": resourceId, "selfCubeId": selfCubeId}));
}
}
void acceptCall(
String sessionId,
Map userInfo,
bool fromCallkit,
) async {
await player.release();
log('acceptCall, from callKit: $fromCallkit', TAG);
//ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: true);
if (_currentCall != null) {
if (context != null) {
// if (AppLifecycleState.resumed !=
// WidgetsBinding.instance.lifecycleState) {
await _currentCall?.acceptCall();
// }
MyAppointment appointment = MyAppointment(
id: userInfo['appointment_id'], doctor: userInfo['doctor_id']);
log(userInfo.toString(), "User Info from AcceptCall");
if (!fromCallkit) {
await ConnectycubeFlutterCallKit.reportCallAccepted(
sessionId: sessionId);
}
broadcastSystemMessage("CALL_ACCEPTED");
navigatorKey!.currentContext!.read().p2pSession =
_currentCall;
GoRouter.of(navigatorKey!.currentContext!).pushReplacementNamed(
RoutesName.videoCallPatientRoute,
extra: Map.from({
// 'currentCall': _currentCall!,
'appointment': appointment,
}),
);
/* systemMessage.recipientId = int.tryParse(selfCubeId!);
systemMessage.properties["resourceId"] = resourceId;
systemMessage.properties["action"] = "CALL_ACCEPTED";
print("-------------BROADCASTING ACCEPT CALL EVENT-----------");
systemMessagesManager?.sendSystemMessage(systemMessage); */
}
if (!kIsWeb) {
if (Platform.isIOS) {
await Helper.setAppleAudioIOMode(AppleAudioIOMode.localAndRemote,
preferSpeakerOutput: true);
}
}
}
}
void reject(String sessionId, bool fromCallkit) {
if (_currentCall != null) {
player.release();
broadcastSystemMessage("CALL_REJECTED");
if (fromCallkit) {
ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: false);
} else {
CallKitManager.instance.processCallFinished(_currentCall!.sessionId);
}
_currentCall!.reject();
_sendEndCallSignalForOffliners(_currentCall, null);
}
}
void hungUp() {
if (_currentCall != null) {
player.release();
CallKitManager.instance.processCallFinished(_currentCall!.sessionId);
_currentCall!.hungUp();
_sendEndCallSignalForOffliners(_currentCall, null);
}
}
CreateEventParams _getCallEventParameters(
P2PSession currentCall, String? callerName) {
/* String? callerName = users
.where((cubeUser) => cubeUser.id == currentCall.callerId)
.first
.fullName; */
CreateEventParams params = CreateEventParams();
params.parameters = {
'message':
"Incoming ${currentCall.callType == CallType.VIDEO_CALL ? "Video" : "Audio"} call",
PARAM_CALL_TYPE: currentCall.callType,
PARAM_SESSION_ID: currentCall.sessionId,
PARAM_CALLER_ID: currentCall.callerId,
PARAM_CALL_OPPONENTS: currentCall.opponentsIds.join(','),
PARAM_CALLER_NAME: callerName ?? "Doctor",
};
params.notificationType = NotificationType.PUSH;
params.environment = CubeEnvironment.DEVELOPMENT;
//kReleaseMode ? CubeEnvironment.PRODUCTION : CubeEnvironment.DEVELOPMENT;
params.usersIds = currentCall.opponentsIds.toList();
return params;
}
Future _sendStartCallSignalForOffliners(
P2PSession currentCall, String callerName) async {
CreateEventParams params = _getCallEventParameters(currentCall, callerName);
params.parameters[PARAM_SIGNAL_TYPE] = SIGNAL_TYPE_START_CALL;
params.parameters[PARAM_IOS_VOIP] = 1;
params.parameters[PARAM_EXPIRATION] = 0;
params.parameters['ios_push_type'] = 'voip';
await createEvent(params.getEventForRequest()).then((cubeEvent) {
log("Event for offliners created: $cubeEvent");
}).catchError((error) {
log("ERROR occurs during create event");
});
}
void _sendEndCallSignalForOffliners(
P2PSession? currentCall, String? callerName) {
if (currentCall == null) return;
CubeUser? currentUser = CubeChatConnection.instance.currentUser;
if (currentUser == null || currentUser.id != currentCall.callerId) return;
CreateEventParams params = _getCallEventParameters(currentCall, callerName);
params.parameters[PARAM_SIGNAL_TYPE] = SIGNAL_TYPE_END_CALL;
createEvent(params.getEventForRequest()).then((cubeEvent) {
log("Event for offliners created");
}).catchError((error) {
log("ERROR occurs during create event");
});
}
void _initCallKit() {
CallKitManager.instance.init(
onCallAccepted: (uuid) {
acceptCall(uuid, _currentCall?.cubeSdp.userInfo ?? {}, true);
},
onCallEnded: (uuid) {
reject(uuid, true);
},
onMuteCall: (mute, uuid) {
onMicMuted?.call(mute, uuid);
},
);
}
void _initChatConnectionStateListener(BuildContext context) {
CubeChatConnection.instance.connectionStateStream.listen((state) {
if (CubeChatConnectionState.Ready == state) {
_initCalls(context);
}
});
}
Future _getCallState(String sessionId) async {
if (Platform.isAndroid || Platform.isIOS) {
var callState =
await ConnectycubeFlutterCallKit.getCallState(sessionId: sessionId);
log("CONECTICUBE CALL STATE: $callState");
return callState;
} else {
return Future.value(CallState.UNKNOWN);
}
}
void muteCall(String sessionId, bool mute) {
CallKitManager.instance.muteCall(sessionId, mute);
}
Future _onBackPressed(BuildContext context) {
return Future.value(false);
}
void broadcastSystemMessage(action) {
systemMessage.recipientId = int.tryParse(selfCubeId!);
systemMessage.properties["resourceId"] = resourceId;
systemMessage.properties["action"] = action;
print("BROADCASTING: $action EVENT");
systemMessagesManager?.sendSystemMessage(systemMessage);
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... ect-to-app
Flutter ConnectyCube: принятие вызова от уведомления не перенаправляет в приложение ⇐ Android
Форум для тех, кто программирует под Android
1741736150
Anonymous
Проблема: < /p>
Я использую ConnectyCube в моем приложении Flutter для обработки видеозвонков. Когда вызов начинается с одного устройства к другому, и приемное устройство находится в фоновом режиме, уведомление вызовов появляется, как и ожидалось. С другой стороны, если я нажимаю на само уведомление, приложение открывается, как и ожидалось. Приложение на передний план.
Нажимая само уведомление, правильно открывает приложение. /> Как я могу убедиться, что когда я нажимаю на «Принять» в уведомлении, приложение доведено на передний план? < /p>
Любая помощь или руководство будут оценены! xmlns:tools="http://schemas.android.com/tools"
package="com.sambuq.care_first">
< /code>
Ниже приведен менеджер вызовов, который я использую < /p>
import 'package:care_first/bloc/auth_bloc/bloc/auth_bloc.dart';
import 'package:care_first/routing/route_names.dart';
import 'package:care_first/screens/my_360_provider/services/fcm/fcm_setup.dart';
import 'package:care_first/screens/my_360_provider/services/fcm/notification_handler.dart';
import 'package:care_first/screens/settings/my_appointments/doctor_appointment/models/my_appointment.dart';
import 'package:care_first/shared/helper/helper_methods.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:universal_io/io.dart';
import 'package:connectycube_flutter_call_kit/connectycube_flutter_call_kit.dart';
import 'package:connectycube_sdk/connectycube_sdk.dart';
import 'call_kit_manager.dart';
import '../utils/consts.dart';
class CallManager {
static String TAG = "CallManager";
static CallManager get instance => _getInstance();
static CallManager? _instance;
static CallManager _getInstance() {
return _instance ??= CallManager._internal();
}
factory CallManager() => _getInstance();
CallManager._internal();
P2PClient? _callClient;
P2PSession? _currentCall;
BuildContext? context;
MediaStream? localMediaStream;
Map remoteStreams = {};
GlobalKey? navigatorKey;
String? selfCubeId;
late String resourceId;
SystemMessagesManager? systemMessagesManager =
CubeChatConnection.instance.systemMessagesManager;
CubeMessage systemMessage = CubeMessage();
final player = AudioPlayer();
Function(bool, String)? onMicMuted;
init(
BuildContext context,
GlobalKey navigatorKey,
String selfCubeId,
String resourceId,
) {
this.context = context;
this.navigatorKey = navigatorKey;
this.selfCubeId = selfCubeId;
this.resourceId = resourceId;
_initCustomMediaConfigs();
if (CubeChatConnection.instance.isAuthenticated()) {
_initCalls(context);
} else {
_initChatConnectionStateListener(context);
}
_initCallKit();
}
destroy() {
_callClient?.destroy();
_callClient = null;
}
void _initCustomMediaConfigs() {
RTCMediaConfig mediaConfig = RTCMediaConfig.instance;
mediaConfig.minHeight = 340;
mediaConfig.minWidth = 480;
mediaConfig.minFrameRate = 25;
RTCConfig.instance.statsReportsInterval = 200;
}
void _initCalls(BuildContext context) {
if (_callClient == null) {
_callClient = P2PClient.instance;
_callClient!.init();
}
// _callClient is P2PClient
_callClient!.onReceiveNewSession = (callSession) async {
print("${'*' * 10} RECEIVED NEW CALL SESSION ${'*' * 10}");
// if (_currentCall != null &&
// _currentCall!.sessionId != callSession.sessionId &&
// _currentCall!.opponentsIds.first.toString() != selfCubeId) {
// callSession.reject();
// return;
// }
if (navigatorKey!.currentContext!.read().user.persona ==
"patient") {
await player
.setReleaseMode(ReleaseMode.loop)
.then(
(value) => player.setSource(AssetSource('audio/ringtone.mp3')))
.then((value) => player.resume());
}
_currentCall = callSession;
var callState = await _getCallState(_currentCall!.sessionId);
await Future.delayed(Duration(seconds: 1));
if (callState == CallState.REJECTED) {
reject(_currentCall!.sessionId, false);
} else if (callState == CallState.ACCEPTED) {
acceptCall(_currentCall!.sessionId,
_currentCall?.cubeSdp.userInfo ?? {}, false);
} else if (callState == CallState.UNKNOWN ||
callState == CallState.PENDING) {
if (callState == CallState.UNKNOWN &&
(Platform.isIOS || Platform.isAndroid)) {
await ConnectycubeFlutterCallKit.setCallState(
sessionId: _currentCall!.sessionId, callState: CallState.PENDING);
}
if (_currentCall!.cubeSdp.callerId.toString() != selfCubeId) {
navigatorKey!.currentContext!.read().p2pSession =
callSession;
// await Future.delayed(Duration(seconds: 1));
// await ConnectycubeFlutterCallKit.showCallNotification(CallEvent(
// sessionId: _currentCall!.sessionId,
// callType: CallType.VIDEO_CALL,
// callerId: _currentCall!.cubeSdp.callerId,
// callerName: "YASH",
// opponentsIds: _currentCall!.opponentsIds,
// userInfo: _currentCall?.cubeSdp.userInfo ?? {},
// ));
print("NOTIFICATION NOT CALLED");
_showIncomingCallScreen(_currentCall!, navigatorKey!.currentContext!);
}
}
_currentCall?.onLocalStreamReceived = (localStream) {
localMediaStream = localStream;
};
_currentCall?.onRemoteStreamReceived = (session, userId, stream) {
remoteStreams[userId] = stream;
};
_currentCall?.onRemoteStreamRemoved = (session, userId, stream) {
remoteStreams.remove(userId);
};
_currentCall?.onReceiveHungUpFromUser =
(session, userId, [userInfo]) async {
print("CALL_MANAGER: onReceiveHungUpFromUser");
/* systemMessage.recipientId = int.tryParse(selfCubeId!);
systemMessage.properties["resourceId"] = resourceId;
systemMessage.properties["action"] = "CALL_HUNGUP";
print("-------------BROADCASTING CALL HUNGUP EVENT-----------");
systemMessagesManager?.sendSystemMessage(systemMessage); */
broadcastSystemMessage("CALL_HUNGUP");
await player.release();
if (GoRouter.of(navigatorKey!.currentContext!)!.location ==
RoutesName.incomingVideoCall) {
GoRouter.of(navigatorKey!.currentContext!).pop();
}
};
};
_callClient!.onSessionClosed = (callSession) async {
if (_currentCall != null &&
_currentCall!.sessionId == callSession.sessionId) {
_currentCall = null;
localMediaStream?.getTracks().forEach((track) async {
await track.stop();
});
await localMediaStream?.dispose();
localMediaStream = null;
remoteStreams.forEach((key, value) async {
await value.dispose();
});
remoteStreams.clear();
CallKitManager.instance.processCallFinished(callSession.sessionId);
if (GoRouter.of(navigatorKey!.currentContext!)!.location ==
RoutesName.incomingVideoCall) {
GoRouter.of(navigatorKey!.currentContext!).pop();
}
}
};
}
void startNewCall(BuildContext context, int callType, int patientCubeId,
MyAppointment appointment, String? businessId, String? moduleId) async {
this.context = context;
Set opponents = {patientCubeId};
if (opponents.isEmpty) return;
if (!kIsWeb) {
if (Platform.isIOS) {
await Helper.setAppleAudioIOMode(AppleAudioIOMode.localAndRemote,
preferSpeakerOutput: true);
}
}
P2PSession callSession =
await _callClient!.createCallSession(callType, opponents);
_currentCall = callSession;
// storing it in authbloc
context.read().p2pSession = callSession;
context.read().resourceId = resourceId;
context.read().selfCubeId = selfCubeId;
String callerName;
if (appointment.doctorMap?["firstname"] != null) {
callerName =
"${appointment.doctorMap?["firstname"]} ${appointment.doctorMap?["lastname"]}";
} else {
callerName = "";
}
await _sendStartCallSignalForOffliners(_currentCall!, callerName);
GoRouter.of(context)
.pushNamed(RoutesName.videoCallDoctorRoute, pathParameters: {
'businessId': encrypt(text: businessId ?? '', context: context),
}, queryParameters: {
'moduleId': moduleId,
}, extra: {
// 'callSession': callSession,
'appointment': appointment,
});
}
void _showIncomingCallScreen(P2PSession callSession, BuildContext context) {
if (navigatorKey!.currentContext != null) {
GoRouter.of(navigatorKey!.currentContext!).pushNamed(
RoutesName.incomingVideoCall,
extra: Map.from(
{"resourceId": resourceId, "selfCubeId": selfCubeId}));
}
}
void acceptCall(
String sessionId,
Map userInfo,
bool fromCallkit,
) async {
await player.release();
log('acceptCall, from callKit: $fromCallkit', TAG);
//ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: true);
if (_currentCall != null) {
if (context != null) {
// if (AppLifecycleState.resumed !=
// WidgetsBinding.instance.lifecycleState) {
await _currentCall?.acceptCall();
// }
MyAppointment appointment = MyAppointment(
id: userInfo['appointment_id'], doctor: userInfo['doctor_id']);
log(userInfo.toString(), "User Info from AcceptCall");
if (!fromCallkit) {
await ConnectycubeFlutterCallKit.reportCallAccepted(
sessionId: sessionId);
}
broadcastSystemMessage("CALL_ACCEPTED");
navigatorKey!.currentContext!.read().p2pSession =
_currentCall;
GoRouter.of(navigatorKey!.currentContext!).pushReplacementNamed(
RoutesName.videoCallPatientRoute,
extra: Map.from({
// 'currentCall': _currentCall!,
'appointment': appointment,
}),
);
/* systemMessage.recipientId = int.tryParse(selfCubeId!);
systemMessage.properties["resourceId"] = resourceId;
systemMessage.properties["action"] = "CALL_ACCEPTED";
print("-------------BROADCASTING ACCEPT CALL EVENT-----------");
systemMessagesManager?.sendSystemMessage(systemMessage); */
}
if (!kIsWeb) {
if (Platform.isIOS) {
await Helper.setAppleAudioIOMode(AppleAudioIOMode.localAndRemote,
preferSpeakerOutput: true);
}
}
}
}
void reject(String sessionId, bool fromCallkit) {
if (_currentCall != null) {
player.release();
broadcastSystemMessage("CALL_REJECTED");
if (fromCallkit) {
ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: false);
} else {
CallKitManager.instance.processCallFinished(_currentCall!.sessionId);
}
_currentCall!.reject();
_sendEndCallSignalForOffliners(_currentCall, null);
}
}
void hungUp() {
if (_currentCall != null) {
player.release();
CallKitManager.instance.processCallFinished(_currentCall!.sessionId);
_currentCall!.hungUp();
_sendEndCallSignalForOffliners(_currentCall, null);
}
}
CreateEventParams _getCallEventParameters(
P2PSession currentCall, String? callerName) {
/* String? callerName = users
.where((cubeUser) => cubeUser.id == currentCall.callerId)
.first
.fullName; */
CreateEventParams params = CreateEventParams();
params.parameters = {
'message':
"Incoming ${currentCall.callType == CallType.VIDEO_CALL ? "Video" : "Audio"} call",
PARAM_CALL_TYPE: currentCall.callType,
PARAM_SESSION_ID: currentCall.sessionId,
PARAM_CALLER_ID: currentCall.callerId,
PARAM_CALL_OPPONENTS: currentCall.opponentsIds.join(','),
PARAM_CALLER_NAME: callerName ?? "Doctor",
};
params.notificationType = NotificationType.PUSH;
params.environment = CubeEnvironment.DEVELOPMENT;
//kReleaseMode ? CubeEnvironment.PRODUCTION : CubeEnvironment.DEVELOPMENT;
params.usersIds = currentCall.opponentsIds.toList();
return params;
}
Future _sendStartCallSignalForOffliners(
P2PSession currentCall, String callerName) async {
CreateEventParams params = _getCallEventParameters(currentCall, callerName);
params.parameters[PARAM_SIGNAL_TYPE] = SIGNAL_TYPE_START_CALL;
params.parameters[PARAM_IOS_VOIP] = 1;
params.parameters[PARAM_EXPIRATION] = 0;
params.parameters['ios_push_type'] = 'voip';
await createEvent(params.getEventForRequest()).then((cubeEvent) {
log("Event for offliners created: $cubeEvent");
}).catchError((error) {
log("ERROR occurs during create event");
});
}
void _sendEndCallSignalForOffliners(
P2PSession? currentCall, String? callerName) {
if (currentCall == null) return;
CubeUser? currentUser = CubeChatConnection.instance.currentUser;
if (currentUser == null || currentUser.id != currentCall.callerId) return;
CreateEventParams params = _getCallEventParameters(currentCall, callerName);
params.parameters[PARAM_SIGNAL_TYPE] = SIGNAL_TYPE_END_CALL;
createEvent(params.getEventForRequest()).then((cubeEvent) {
log("Event for offliners created");
}).catchError((error) {
log("ERROR occurs during create event");
});
}
void _initCallKit() {
CallKitManager.instance.init(
onCallAccepted: (uuid) {
acceptCall(uuid, _currentCall?.cubeSdp.userInfo ?? {}, true);
},
onCallEnded: (uuid) {
reject(uuid, true);
},
onMuteCall: (mute, uuid) {
onMicMuted?.call(mute, uuid);
},
);
}
void _initChatConnectionStateListener(BuildContext context) {
CubeChatConnection.instance.connectionStateStream.listen((state) {
if (CubeChatConnectionState.Ready == state) {
_initCalls(context);
}
});
}
Future _getCallState(String sessionId) async {
if (Platform.isAndroid || Platform.isIOS) {
var callState =
await ConnectycubeFlutterCallKit.getCallState(sessionId: sessionId);
log("CONECTICUBE CALL STATE: $callState");
return callState;
} else {
return Future.value(CallState.UNKNOWN);
}
}
void muteCall(String sessionId, bool mute) {
CallKitManager.instance.muteCall(sessionId, mute);
}
Future _onBackPressed(BuildContext context) {
return Future.value(false);
}
void broadcastSystemMessage(action) {
systemMessage.recipientId = int.tryParse(selfCubeId!);
systemMessage.properties["resourceId"] = resourceId;
systemMessage.properties["action"] = action;
print("BROADCASTING: $action EVENT");
systemMessagesManager?.sendSystemMessage(systemMessage);
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79480830/flutter-connectycube-accepting-call-from-notification-doesnt-redirect-to-app[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия