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

Mute/Unmute bug & fix in iOS devices #616

Closed
Qvadis opened this issue Apr 13, 2020 · 1 comment
Closed

Mute/Unmute bug & fix in iOS devices #616

Qvadis opened this issue Apr 13, 2020 · 1 comment

Comments

@Qvadis
Copy link

Qvadis commented Apr 13, 2020

Hi,

first of all, thank you guys for your work here.

I've found an issue an its solution, and I would like to discuss it, just in case it is a matter of configuration.

The issue is regarding the mute and unmute function.

When I open a new SIP session, and the session is established, I have the need to mute/unmute the microphone, so I call the mute/unmute functions.

I have an API that uses the JsSIP:

public SIPMute(): Observable<any> {
	return Observable.create((observer: any) => {
		if (this.session !== null) {
			this.session.mute({'audio': true, 'video': false});
			const muteStateStr = "audio muted";
			observer.next({ resCode: qvError.SUCCESS, resData: muteStateStr });
		} else {
			observer.error({ resCode: qvError.GENERIC_ERROR, resData: "nullSession" });
		}
	});
}

public SIPUnMute(): Observable<any> {
	return Observable.create((observer: any) => {
		if (this.session !== null) {
			this.session.unmute({'audio': true, 'video': false});
			const muteStateStr = "audio unmuted";
			observer.next({ resCode: qvError.SUCCESS, resData: muteStateStr });
		} else {
			observer.error({ resCode: qvError.GENERIC_ERROR, resData: "nullSession" });
		}
	});
}

The variable this.session contains the rtcsession previously stored during the negotiation

this.ua.on("newRTCSession", (e: any) => {
    this.session = e.session;
         ...

I tried this code in Android and iOS devices (hybrid apps with ionic), as well as webclients (chrome and safari). It works good in every device but iOS.

I've chased it and I found what was happening. The issue was the toggleMuteAudio function in the JsSIP library.

key: "_toggleMuteAudio",
value: function _toggleMuteAudio(mute) {
  var senders = this._connection.getSenders().filter(function (sender) {
    return sender.track && sender.track.kind === 'audio';
  });

  var _iterator8 = _createForOfIteratorHelper(senders),
      _step8;

  try {
    for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
      var sender = _step8.value;
      sender.track.enabled = !mute;
    }
  } catch (err) {
    _iterator8.e(err);
  } finally {
    _iterator8.f();
  }
}

In iOS devices, the value of sender.track is undefined. It seems to be one level up, so accessing sender.track should be sender. I thought that it may be an error in the ontrack event, but having it working in Android confuses me.

This is the solution that works for me:

key: "_toggleMuteAudio",
value: function _toggleMuteAudio(mute) {
  var senders = this._connection.getSenders().filter(function (sender) {
  var senderTrack = (sender.track) ? sender.track : sender;
      return senderTrack && senderTrack.kind === 'audio';
  });

  var _iterator8 = _createForOfIteratorHelper(senders),
      _step8;

  try {
    for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
       var sender = _step8.value;
       var senderTrack = (sender.track) ? sender.track : sender;
       senderTrack.enabled = !mute;
    }
  } catch (err) {
    _iterator8.e(err);
  } finally {
    _iterator8.f();
  }
}

Please, note that the only fix was to add the ternary operation.

And this is the ontrack function:

 this.session.connection.ontrack = (ev: any) => {
     this.audioElementOut.srcObject = ev.streams[0];							 
     this.audioElementOut.play();
 };

I'd like you guys to shed some light here, if possible.

Thank you and cheers,
Borja.

@ibc
Copy link
Member

ibc commented Apr 13, 2020

Please use the mailing list for questions. We cannot handle discussions about JsSIP usage as if they were JsSIP issues/bugs.

Also, it seems that you have modified the transpiled code (in lib-es5/) instead of the original one (in lib/).

@ibc ibc closed this as completed Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants