joinPresentation method

  1. @override
Future<Widget?> joinPresentation(
  1. String callToken,
  2. PresentationSettings presentationSettings,
  3. dynamic onSuccess(
    1. Widget callWidget
    ),
  4. dynamic onError(
    1. CometChatCallsException error
    ),
)
override

Implementation

@override
Future<Widget?> joinPresentation(String callToken,
    PresentationSettings presentationSettings, onSuccess, onError) async {
  try {
    if (callToken.isNotEmpty) {
      await setUpNativeStreamListener(
          callToken, null, presentationSettings, onSuccess, onError);
      await getCometChatCallingView(callToken, null, presentationSettings);
      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;
}