team-telnyx / webrtc

SDK for Telnyx's WebRTC platform
https://developers.telnyx.com/docs/v2/webrtc
MIT License
40 stars 20 forks source link

receiving a call while already on an active call #170

Closed weevaa closed 3 years ago

weevaa commented 3 years ago

Hey there.. Thank you for you all that you do. I am using vanilla js example, I'm not sure how to handle a secondary call coming in when the client is already active with another one.

The issue is, that when a SIP call is active, and another one comes in, the software does as intended and starts playing the ringtone, however it does this whether or not you're on another call or not. Is there a way to send the second call to voicemail, or put on hold and/or stop the client ringtone so you can deal with the call that is active, or place them on hold and answer?

Thank you in advance!

DeividVeloso commented 3 years ago

Hello @weevaa thank you for your question, you can use something like this inside the telnyx.notification'event

  if (notification.call.state === 'ringing') {
              if (
                Object.values(clientRef.current.calls).some((call) => {
                  return (
                    call.direction === 'inbound' &&
                    call.id !== notification.call.id
                  );
                })
              ) {
               //Here you can do these actions with next incoming call
                notification.call.hangup();
                notification.call.hold();
                break;
              }
            }

About ringtone you can stop to pass this props ringtoneFile to new TelnxRTC({...}) and create your own way to play audios. https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement/Audio

You can play and stop audio using the notification.call.state changes.