requestCallToUser method

RequestCallToUserInstance requestCallToUser({
  1. required MediaStream localStream,
  2. required USER_ID userId,
  3. Map<String, dynamic>? additionalData,
})

Request a call to a remote user. Returns a RequestCallToUserInstance

localStream The MediaStream for the local user, so the remote user will be able to receive video and/or audio. You can get it with navigator.mediaDevices.getUserMedia(...)

userId Refers to the remote user the local user want talk to.

additionalData Add custom data here (optional)

Example

 final localVideoRenderer = RTCVideoRenderer();
 final remoteVideoRenderer = RTCVideoRenderer();
 RequestCallToUserInstance? callInstance;

 requestCall() async {
   navigator.mediaDevices.getUserMedia({
     'audio': true,
     'video': {
       'facingMode': 'user',
     },
   }).then((localUserStream) {
     setState(() {
       localVideoRenderer.srcObject = localUserStream;
       callInstance = AsklessClient.instance.requestCallToUser(
         userId: 2,
         localStream: localUserStream,
         additionalData: {
           "videoCall": true // add your custom data here, I'm sending whether is a video call or not
         },
       );
       callInstance!.response().then((response) {
         if (!response.callAccepted) {
           print("Call has not been accepted");
           return;
         }

         setState(() {
           remoteVideoRenderer.srcObject = response.liveCall!.remoteStream;
           liveCall!.addOnCallClosesListener(listener: () {
             // to handle when the call has been closed
           });
         });
       });
     });
   }, onError: (error) {
     print("Could not get access to camera and/or microphone ${error.toString()}");
   });
 }

 @override
 Widget build(BuildContext context) {
   return Stack(
     children: [
       RTCVideoView(remoteVideoRenderer),
       Positioned(
         bottom: 4,
         right: 0,
         child: SizedBox(
           height: 125,
           width: 75,
           child: RTCVideoView(localVideoRenderer),
         ),
       ),
     ],
   );
 }

 @override
 void dispose() {
   callInstance?.dispose();
   liveCall?.dispose();
   super.dispose();
 }

Implementation

RequestCallToUserInstance requestCallToUser({
  required MediaStream localStream,
  required USER_ID userId,
  Map<String,dynamic>? additionalData,
}) {
  assert(additionalData == null || additionalData is Map);

  return CallService<USER_ID>(_getWebRTCParams).requestCallToUser(
    localStream: localStream,
    remoteUserId: userId,
    additionalData: Map.from(additionalData ?? {}),
  );
}