callForNative method
Future<Map<String, dynamic> >
callForNative(
- BuildContext context, {
- required CallType callType,
- required List<
String> userIdList, - String? chatGroupId,
- String? roomId,
- String? userData,
- Map<
String, dynamic> ? offlinePushInfo, - int timeout = 30,
- bool isEphemeralCall = false,
- int cloudRecordPolicy = -1,
override
Implementation
@override
Future<Map<String, dynamic>> callForNative(BuildContext context, {
required CallType callType,
required List<String> userIdList,
String? chatGroupId,
String? roomId,
String? userData,
Map<String, dynamic>? offlinePushInfo,
int timeout = 30,
bool isEphemeralCall = false,
int cloudRecordPolicy = -1, // 是否启用云录制 -1 跟随后台配置 0 关闭 1 开启
}) async {
if (userIdList.isEmpty) {
throw Exception('拨打对方的 userId 列表为空,需要传入非空的 userIdList 参数');
}
if (ImState.callTypeNotifier.value != null) {
throw Exception('正在通话中,不可重复拨打');
}
ImState.callTypeNotifier.value = callType;
ImState.updateCallMemberList(userIdList);
ImState.callIsInitiatorNotifier.value = true;
try {
final handler = await CallStore.shared.calls(
userIdList,
callType == CallType.audio ? CallMediaType.audio : CallMediaType.video,
CallParams(
roomId: roomId ?? '',
chatGroupId: chatGroupId ?? '',
userData: userData ?? '',
offlinePushTitle: offlinePushInfo?.getOrNull('offlinePushTitle') ?? '',
offlinePushDescription: offlinePushInfo?.getOrNull('offlinePushDescription') ?? '',
timeout: timeout,
isEphemeralCall: isEphemeralCall,
cloudRecordPolicy: cloudRecordPolicy == 0 ? CloudRecordPolicy.disable : (cloudRecordPolicy == 1 ? CloudRecordPolicy.enable : CloudRecordPolicy.followConsoleConfig),
),
);
if (handler.errorCode == 0) {
// 唤起通话页面
if (context.mounted) {
showNativeCallPage(context);
}
return {};
} else {
ImState.callTypeNotifier.value = null;
ImState.updateCallMemberList([]);
ImState.callIsInitiatorNotifier.value = null;
debugPrint('Call failed: ${handler.errorCode}, ${handler.errorMessage}');
throw ImException(code: 400, message: '发起音视频通话邀请失败: ${handler.errorCode}, ${handler.errorMessage}');
}
} catch (e) {
rethrow;
}
}