3

When I want to mute microphone I use mediastream which I get from

session.sessionDescriptionHandler.on('userMedia', 
onUserMediaObtained.bind(this))

function onUserMediaObtained(stream) {
    localMediaStream = stream
}

Session value is from agent.invite() method.

But when I get incoming call, in onInvite event handler:

agent.on('invite', onInvite(dispatch, store))

const onInvite = (dispatch, store) => session => {
  if (session.sessionDescriptionHandler) {}
  else { //always undefined here}
 }

I try again attach event in onaccepted event handler

session.on('accepted', onAccepted(dispatch))

There is sessionDescriptionHandler object initialized, but I think it's too late, onUserMediaObtained isn't fired.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Zwoniar
  • 43
  • 9

3 Answers3

1
let pc = this.session.sessionDescriptionHandler.peerConnection;
pc.getLocalStreams().forEach(function (stream) {
    stream.getAudioTracks().forEach(function (track) {
        try {
            track.enabled = !track.enabled;
        } catch (e) {
            toastr.error('Error occured in executing this command.');
            console.log(e);
        }
    });
});
0

You can use the session object to mute/unmute the microphone. It seems that these two functions have been removed from the Session API page, but I'm pretty sure it still works.

In this the 0.7.0 API page you have it specified https://sipjs.com/api/0.7.0/session/#muteoptions

Vasco Lameiras
  • 344
  • 3
  • 15
  • It's not working. They removed it in 0.8, there were breaking changes in media handling in this version. https://github.com/onsip/SIP.js/releases/tag/0.8.0 – Zwoniar Jan 10 '18 at 14:23
0

here I just did this with sipjs 11

`const pc = session.sessionDescriptionHandler.peerConnection;
        let togglemute = `true/false`;
        // this.emit
        if (pc.getSenders) {
            pc.getSenders().forEach(function (sender) {
                if (sender.track) {
                    sender.track.enabled = !togglemute;

                }
            });
        } else {
            pc.getReceivers().forEach(function (receiver) {
                if (receiver.track) {
                    receiver.track.enabled = !togglemute;
                }
            });
        }`
Metawaa
  • 306
  • 3
  • 15