Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SessionManager in react native #1050

Open
Irfanwani opened this issue Jul 14, 2023 · 0 comments
Open

SessionManager in react native #1050

Irfanwani opened this issue Jul 14, 2023 · 0 comments

Comments

@Irfanwani
Copy link

Irfanwani commented Jul 14, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant