ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
124 stars 111 forks source link

Audio Call issues #311

Open muneeb-mt opened 1 year ago

muneeb-mt commented 1 year ago

Hi @ccvlad. I hope you are doing well. In connectycube version 3.21.0 for react-native app, I am facing an issue here:

async startCall(usersIds, callType, options = {}) { console.log({callType: callType}); try { const session = ConnectyCube.videochat.createNewSession( usersIds, callType, options, ); store.dispatch(setCallSession({session})); const CURRENT_USER_CALLER_ID = this.currentUser.callerId; CallNotification(usersIds, CURRENT_USER_CALLER_ID); await this.setMediaDevices();

  // create local stream
  const mediaOptions = {...CallService.MEDIA_OPTIONS};
  if (callType === ConnectyCube.videochat.CallType.AUDIO) {
    mediaOptions.video = false;
  }
  const stream = await this.callSession.getUserMedia(mediaOptions);
  // store streams
  const streams = [{userId: LOCAL_STREAM_USER_ID, stream: stream}];
  for (let uId of usersIds) {
    streams.push({userId: uId, stream: null});
  }
  store.dispatch(addOrUpdateStreams({streams}));
  this.callSession.call({});
  // report to CallKit (iOS only)
  this.reportStartCall(
    this.callSession.ID,
    this.currentUser?.profileResponse?.firstName || '',
    getCallRecipientString(usersIds),
    'generic',
    callType === 'video',
  );
  this.playSound('outgoing');
  this.setSpeakerphoneOn(
    this.callSession.callType === ConnectyCube.videochat.CallType.VIDEO,
  );
  return session;
} catch (error) {
  **console.log({'Not able to call the user': error.message});**
}

}

Note: If the callType is 2, which means audiocall, ConnectyCube.videochat.createNewSession is nit creating a session, hence I'm failed to get and create an audio call. Response is:

{"Not able to call the user": {"constraintName": undefined, "message": "Permission denied.", "name": "SecurityError"}}

My function to call startCall in callService:

const startCall = async callType => { if (!profileData?.profileResponse.callerId) { showToast('error', 'Error', 'Unable to make audio call with this user'); return; } else { const selectedOpponentsIds = [data.callerId]; ConnectyCube.videochat.CallType.AUDIO; const callSession = await callService.startCall( selectedOpponentsIds, callType, ); const pushParams = { message: Incoming call from ${data.firstName || ''}, ios_voip: 1, handle: data.firstName || '', initiatorId: callSession.initiatorID, opponentsIds: selectedOpponentsIds.join(','), uuid: callSession.ID, callType: callType === ConnectyCube.videochat.CallType.VIDEO ? 'video' : 'audio', }; pushNotificationsService.sendPushNotification( selectedOpponentsIds, pushParams, ); dispatch(onStartCall(data)); } };

I need an urgent help in it. Thanks

ccvlad commented 1 year ago

Hi @muneeb-mt

Please check the getUserMedia(mediaOptions) - is the audio = true? Or check your mic input, which must be permitted by the system.

It seems that you didn't manage to get a stream from the getUserMedia()

muneeb-mt commented 1 year ago

Yes - that's my point in video call -> calltype = 1. I'm getting the stream and its fine but in calltype = 2, that is audio, there is no stream @ccvlad

muneeb-mt commented 1 year ago

Thank you @ccvlad. I have solved the problem with your help.

muneeb-mt commented 1 year ago

Thank you @ccvlad. I have solved the problem with your help.

ccvlad commented 1 year ago

Based on the error message:

  1. Make sure you are passing the correct parameters to getUserMedia.
  2. Ensure that you haven't blocked the microphone permissions on your system (you might have allowed the camera but accidentally blocked the microphone).

The ConnectyCube.videochat.createNewSession(...) just make a new WebRTC instance with methods and props. The callType saves in the instance as a property of it and can't call the error you've pointed.

muneeb-mt commented 1 year ago

@ccvlad I got this error: {"Not able to call the user": [TypeError: null is not an object (evaluating 'client.jid._local')]}

Conditions No. 1: After first call -> if the opponent ends the call or the current user ends the call and we again click to call, we got this error Conditions No. 2: If the kill the app and again try to call -> we got the same error Why? Can you suggest any thing here?

muneeb-mt commented 1 year ago

@ccvlad @banshiAnton @DaveLomber @TatankaConCube Any solution for this? Actually our app is live and we are getting these problems and now we are reaching you people to ask you this. Much appreciated πŸ™Œ . Thank you in advance πŸ‘ πŸ˜„