QuickBlox / quickblox-flutter-sdk

quickblox-flutter-sdk
Other
8 stars 0 forks source link

Unable to add userInfo object while creating a call #66

Closed AbdurrehmanSubhani closed 1 year ago

AbdurrehmanSubhani commented 1 year ago

Hey, what is the correct format for adding userInfo data while making a call. I want to display the caller name while receiving a call on the callee side and hence trying to send information through userInfo. I have tried the following approaches:

  1. Approach 1: try { QBRTCSession? session = await QB.webrtc.call(opponentIds, QBRTCSessionTypes.AUDIO, userInfo: { "callerData": qbUser!, });

    _sessionId = session!.id; logger.d("The call was initiated for session id: $_sessionId");

    _sessionId = _sessionId; return sessionId; } on PlatformException catch (e) { logger.d(e); return null; } error logs: Invalid argument: Instance of 'QBUser'

  2. Approach 2: try { final callerData = { "callerData": { "name": qbUser!.fullName, } }; QBRTCSession? session = await QB.webrtc .call(opponentIds, QBRTCSessionTypes.AUDIO, userInfo: callerData);

    _sessionId = session!.id;

    logger.d("The call was initiated for session id: $_sessionId");

    _sessionId = _sessionId; return sessionId; } on PlatformException catch (e) { logger.d(e); return null; } error logs: PlatformException(error, java.util.HashMap cannot be cast to java.lang.String, null, java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String I/flutter ( 8716): β”‚ πŸ› at com.quickblox.quickblox_sdk.webrtc.WebRTCModule.call(WebRTCModule.java:175) I/flutter ( 8716): β”‚ πŸ› at com.quickblox.quickblox_sdk.webrtc.WebRTCModule.handleMethod(WebRTCModule.java:85) I/flutter ( 8716): β”‚ πŸ› at com.quickblox.quickblox_sdk.webrtc.WebRTCModule$$ExternalSyntheticLambda0.onMethodCall(Unknown Source:2) I/flutter ( 8716): β”‚ πŸ› at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) I/flutter ( 8716): β”‚ πŸ› at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) I/flutter ( 8716): β”‚ πŸ› at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) I/flutter ( 8716): β”‚ πŸ› at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) I/flutter ( 8716): β”‚ πŸ› at android.os.Handler.handleCallback(Handler.java:942) I/flutter ( 8716): β”‚ πŸ› at android.os.Handler.dispatchMessage(Handler.java:99) I/flutter ( 8716): β”‚ πŸ› at android.os.Looper.loopOnce(Looper.java:201) I/flutter ( 8716): β”‚ πŸ› at android.os.Looper.loop(Looper.java:288) I/flutter ( 8716): β”‚ πŸ› at android.app.ActivityThread.main(ActivityThread.java:7898) I/flutter ( 8716): β”‚ πŸ› at java.lang.reflect.Method.invoke(Native Method) I/flutter ( 8716): β”‚ πŸ› at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) I/flutter ( 8716): β”‚ πŸ› at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) I/flutter ( 8716): β”‚ πŸ› )

sshaforenkoqb commented 1 year ago

Hello @AbdurrehmanSubhani, userInfo should be passed as a String:String hash map, try to pass data in next format: final callerData = { "callerName": qbUser!.fullName, };

AbdurrehmanSubhani commented 1 year ago

The userInfo type set in the sdk is set Map<String,Object?> hence im not able to assign the callerData mentioned above: error: The argument type 'Map<String, String?>' can't be assigned to the parameter type 'Map<String, Object>?'.

kirillTolmachev commented 1 year ago

Hello @AbdurrehmanSubhani I have tested in version Flutter Quickblox SDK 0.12.4 and the code below works fine:

Caller side:

Map<String, Object> callerInfo = {};
callerInfo["callerData"] = qbUser?.fullName ?? "FullName or User is NULL";
QBRTCSession? session = await QB.webrtc.call(OPPONENTS_IDS, QBRTCSessionTypes.AUDIO, userInfo: callerInfo);

Opponent side:

_callSubscription = await QB.webrtc.subscribeRTCEvent(QBRTCEventTypes.CALL, (data) {
        Map<dynamic, dynamic> payloadMap = Map<dynamic, dynamic>.from(data["payload"]);
        String callerData = payloadMap["userInfo"]["callerData"];

        /*Some code for handle calls*/
});
AbdurrehmanSubhani commented 1 year ago

Thanks, the solution is working! @kirillTolmachev i tried finding an example on the sdk documentation but couldn't find any, it would be great if the code provided above is added to the sdk documentation!