Skip to content

fix: reject mute before the peer connection exists - #1004

Open
mvanhorn wants to merge 1 commit into
versatica:masterfrom
mvanhorn:fix/685-mute-before-answer
Open

mvanhorn wants to merge 1 commit into
versatica:masterfrom
mvanhorn:fix/685-mute-before-answer

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Dec 4, 2026 •

Copy link
Copy Markdown

Problem

On an incoming call that has not been answered yet, RTCSession.mute() throws a TypeError. #connection is still null when #toggleMuteAudio() calls getSenders(). This happens on JsSIP 3.6.1 and on current master.

The throw leaves the session in a bad state. mute() sets #audioMuted = true before it touches the peer connection, so isMuted() reports muted after the call fails. Once the call is answered, a second mute() sees the flag already set and skips the senders, so the audio track stays enabled. unmute() has the same ordering: it clears #audioMuted / #videoMuted first.

Steps to reproduce:

  1. Receive an incoming call and do not answer it.
  2. Call session.mute({ audio: true }). It throws TypeError, and session.isMuted().audio is now true.
  3. Answer the call and call session.mute({ audio: true }) again. The local audio track is still enabled.

Fix

mute() and unmute() now throw Exceptions.InvalidStateError before changing any state when audio or video is requested and the peer connection does not exist yet. isMuted() stays unchanged. Mute with neither audio nor video stays a no-op. This matches hold() and unhold(), which already return false without changing #localHold outside WAITING_FOR_ACK and CONFIRMED. The doc comments for all four methods now describe this.

Tests

The new test in src/test/test-RTCSession.ts mutes, unmutes and holds an unanswered incoming call, answers it, mutes again and checks that the audio track is disabled.

  • On master without the fix, the test fails (1 failing).
  • With the fix, npm test passes on macOS, and all 117 tests pass on Linux (Node 22).

Fixes #685

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Attempting to mute a unanswered call makes it unmuteable after answer

1 participant