startSession method
Future<Widget?>
startSession(
- String callToken,
- CallSettings callSettings,
- dynamic onSuccess(
- Widget callWidget
- dynamic onError(
- CometChatCallsException error
override
Implementation
@override
Future<Widget?> startSession(
String callToken, CallSettings callSettings, onSuccess, onError) async {
try {
if (callToken.isNotEmpty) {
await setUpNativeStreamListener(
callToken, callSettings, null, onSuccess, onError);
await getCometChatCallingView(callToken, callSettings, null);
if (Platform.isAndroid) {
final nativeView = PlatformViewLink(
viewType: "cometchatcallsNativeViewAndroid",
surfaceFactory: (context, controller) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
gestureRecognizers: const <Factory<
OneSequenceGestureRecognizer>>{},
);
},
onCreatePlatformView: (params) {
return PlatformViewsService.initExpensiveAndroidView(
id: params.id,
viewType: "cometchatcallsNativeViewAndroid",
layoutDirection: TextDirection.ltr)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..create();
},
);
onSuccess(nativeView);
return nativeView;
} else {
final Map<String, dynamic> creationParams = <String, dynamic>{};
final nativeView = UiKitView(
viewType: "cometchatcallsNativeViewiOS",
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
);
onSuccess(nativeView);
return nativeView;
}
} else {
onError(CometChatCallsException(CometChatCallsConstants.codeError,
"Call token is null", "Call token is null"));
}
} on PlatformException catch (platformException) {
onError(CometChatCallsException(platformException.code,
platformException.message, platformException.details));
} catch (e) {
onError(CometChatCallsException(
CometChatCallsConstants.codeError, e.toString(), e.toString()));
}
return null;
}