startSession method

  1. @override
Future<Widget?> startSession(
  1. String callToken,
  2. CallSettings callSettings,
  3. dynamic onSuccess(
    1. Widget callWidget
    ),
  4. dynamic onError(
    1. 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;
}