Cannot add user in direct call

Hello !

I’m trying to add a user in a direct call. As suggested by one person from your support team I sent a custom message to the user with the session Id. In “onCustomMessageReceived” callback I open a dialog to ask the user to join or refuse. If the user join I call startCall to join the call but impossible to make it work, the user start a call alone and does not join the existing call.

I tried to call startCall with several different parameters for callSettings :

  • the SessionId alone
  • a CallSettings instance
  • the sessionId got from the existing call passed as custom data with the method getSessionId()

I ran three instances of my React App in localhost connected with three different users accounts.
Do you think I can’t add users because I’m debugging in localhost ? To you have any clues about how to solve my problem ?

Thanks

Florent

Hello @florent.cadot,

Can you please share code snippet of the custom message you are sending and the onCustomMessageReceived() callback?

Warm Regards,

CometChat Pro
Mayur Bhandari

Hi Mayur, Here is the code in the onCustomMessageReceived() callback:

`                onCustomMessageReceived: customMessage => {
                    dispatch(addUserToCallDialog({ open: true, data:{ callToJoin:customMessage.data, addUserSender: customMessage.sender} }))
                }
            }`

The call session id is stored in “callToJoin” (in Redux Store) Then to start the call:

        `let call = Object.assign(new CometChat.Call(), this.props.addUserDialogData.callToJoin);
        CometChat.startCall(
            call.getSessionId(),
            document.getElementById("test-add-user"),
            new CometChat.OngoingCallListener({
                onCallEnded: call => {
                    console.log("Call ended:", call);
                },
                onError: error => {
                    console.log("Error :", error);
                },
            }),
        );`

I tried to pass a CallSettings object instead of the call session, same issue

Thanks
Florent

Hello @florent.cadot,

Can you please confirm if you are using the direct calling flow or default calling flow? I did test the direct calling flow on my end.

I started a direct call using the following code snippet:

startDirectCall(sessionId){
var callSettings = new CometChat.CallSettingsBuilder().setSessionID(sessionId).enableDefaultLayout(true).build();
let callListener = new CometChat.OngoingCallListener({
    onUserJoined: user => {
        console.log("Listener => onUserJoined:", user);
    },
    onUserLeft: user => {
        console.log("Listener => onUserLeft:", user);
    },
    onCallEnded: call => {
        console.log("Listener => onCallEnded:", call);
    },
    onError: error => {
        console.log("Listener => onError:", error);
    }
});
CometChat.startCall(callSettings, document.getElementById("callScreen"), callListener);
}

sendCustomCallInvite(sessionId){
    var receiverID = "UID";
    var customData = {
        sessionID: sessionId
    };
    var customType = "directCall";
    var receiverType = "user";
    var customMessage = new CometChat.CustomMessage(receiverID, receiverType, customType, customData);

    CometChat.sendCustomMessage(customMessage).then(
        message => {
            console.log("custom message sent successfully", message);
        },
        error => {
            console.log("custom message sending failed with error", error);
        }
    );
}

onStartDirectCallButtonClick(){
    let sessionId = "SESSION_ID";
    startDirectCall(sessionId);
    sendCustomCallInvite(sessionId);
}

On the receiving end, when I get the custom message in the Message Listener. I get the sessionId from the custom message and start the direct call using the below code snippet:

CometChat.addMessageListener(
    "MESSAGE_LSITENER",
    new CometChat.MessageListener({
        onCustomMessageReceived: customMessage => {
            handleCustomMessage(customMessage);
        }
    })
);

handleCustomMessage(){
    if(customMessage.type === 'directCall'){
        startDirectCall(customMessage.data.customData.sessionID);
    }
}

I hope this helps. Please let us know if you have any other issues.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hi Mayur,

Yes I’m using the direct calling flow

I start a call with the following function :

startDirectCall(sessionId, callListener) {
    let callSettings = new CometChat.CallSettingsBuilder().setSessionID(sessionId).setIsAudioOnlyCall(true).enableDefaultLayout(true).setMode(CometChat.CALL_MODE.SPOTLIGHT).build();
    CometChat.startCall(callSettings, document.getElementById("cp-call-screen-container"), callListener);
}

this function is run 3 times:

  • When the call is accepted on caller side (on the event “onOutgoingCallAccepted”)
  • When the call is accepted on callee side
  • When a third user receive a custom a message with the sessionId and and accept to join the call clicking on a button in the dialog

I can’t make it work, the third user cannot join the call

Should I share you more code or do you anything wrong in this function ?

Hello @florent.cadot,

I think you are using the default calling flow. Since in the direct calling flow the real-time call listeners are not triggered. Since you are accepting a call in the real-time call listeners you are using the default calling flow.

When you initiate a call, you need to send a custom message in that particular conversation. And when the user receives the custom message, they need to accept the call and then start the call. I hope this solves your confusion.

Also, can you please share any errors you are getting in the console & a small video demonstrating the issue will be helpful. Thank You.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hello Mayur,

You were absolutely right, I was using the default callingFlox, I was confused because one of my component method was called “startDirectCall”. It works using the direct calling flow, thanks for your help!

Florent

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.