SIP.js
SIP.js copied to clipboard
SessionManager in react native
I am trying to implement mute/unmute and hold/unhold features in react native. On web, we can do that using SessionManager but I cannot find any alternative to SessionManager in react native. Though i found another ways to mute/unmute a call but for hold/unhold, I found a workaround but I am not listening to any message (which we usually hear when holding a call).
Here is how i implemented the features:
mute: active => {
var audioTrack = inviter?.sessionDescriptionHandler?.peerConnection
?.getSenders()
?.find(sender => sender.track.kind === 'audio')?.track;
if (audioTrack) audioTrack.enabled = !active;
},
hold: active => {
var senders =
inviter?.sessionDescriptionHandler?.peerConnection?.getSenders();
var audioReceiver = inviter?.sessionDescriptionHandler?.peerConnection
?.getReceivers()
?.find(receiver => receiver.track.kind === 'audio');
if (audioReceiver) {
audioReceiver.track.enabled = !active;
}
if (active) {
senders?.forEach(sender => {
if (sender?.track && sender?.track?.kind === 'audio') {
sender.track.enabled = false;
}
});
} else {
mediaDevices
?.getUserMedia({audio: true, video: false})
.then(stream => {
var audioTrack = stream.getAudioTracks()[0];
senders.forEach(sender => {
if (sender.track && sender.track.kind === 'audio') {
sender.replaceTrack(audioTrack);
}
});
})
.catch(() => {
dispatch(
setSnackdata({
message: 'There was some issue while unholding the call.',
}),
);
});
}
}
I am kinda mimicking the hold functionality by disabling the receiving and audio device for sending audio (as both are disabled when a call in on hold).