Implementing Hold/UnHold and Mute/UnMute

1,577 views
Skip to first unread message

shrey shah

unread,
Sep 15, 2021, 8:53:41 AM9/15/21
to SIP.js
Hello, I am using the latest version 0.20.0 and I want to add hold and mute functionality.
I have found out instance methods that has these methods in older version's documentation ( https://sipjs.com/api/0.6.0/session/ ) but these method does not seem to be in the latest version. 
Can someone provide me a proper way of implementing these two things with the current version.

Thanks,
Shrey

shrey shah

unread,
Sep 21, 2021, 1:14:44 AM9/21/21
to SIP.js
Any update or response for this? I need to implement hold and mute functionalities with 0.20.0.

Benjamin Flügel

unread,
Sep 21, 2021, 3:01:56 AM9/21/21
to SIP.js
Hey Shrey,

you can do something like this:

toggleHold
(enable) {
   this.isOnHold = enable == null ? !this.isOnHold : enable;

   if (this.session) {
     const options: SessionInviteOptions = {sessionDescriptionHandlerModifiers: this.isOnHold ? [Web.holdModifier] : []};
     this.session.invite(this.sdhOptions(options)).then(() => {
       //do stuff or do nothing
     }).catch((error: Error) => {
       //Exception handling
     });

     //toggle the audio to pause and unpause it
   }
}


And for mute and unmute you can do it like that:

let peer = this.session.sessionDescriptionHandler.peerConnection;
let senders = peer.getSenders();

if (!senders.length) return;

let that = this;
senders.forEach(function(sender) {
   if (sender.track) sender.track.enabled = !that.isMuted;
});
 
I hope my answer helps you

Greetings,
Ben

shrey shah

unread,
Sep 22, 2021, 2:17:38 AM9/22/21
to SIP.js
Hi Benjamin,
Thanks a lot for the answer, really helped a lot and the functionalities are working properly. Thanks again.

jazeb Sheraz

unread,
May 23, 2023, 4:38:44 AM5/23/23
to SIP.js
Hi Banjamin,
i am not able to hold the session. Following is my code.

const holdOptions = {
    sessionDescriptionHandlerOptions: {
        constraints: {
            audio: false,  // Set audio to false to put the session on hold
            video: false
        },
        sessionDescriptionHandlerModifiers:false
    }
};

session.invite(holdOptions)
    .then(() => {
        console.log("Session held successfully.");
    })
    .catch((error) => {
        console.error("Failed to hold the session:", error);
    });


it logs in console that ' Session held successfully. ' but actually it does not hold. please guide me what i am doing wrong. I am currently using sip.js version 0.21.2 in my JavaScript project. 

Waiting for your kind response. Thanks .

Marcos Mariani

unread,
May 26, 2023, 3:16:49 PM5/26/23
to SIP.js
Check how it is done at the SessionManager setHold function:


Alternatively you can just add the Web.holdModifier exported as Benjamin Flügel showed on his code.

Hector Arroyo

unread,
Jul 1, 2024, 5:15:12 PM7/1/24
to SIP.js

toggleHold works perfectly. I implemented it on a Next.js project. Thx!   
const holdCall = useCallback(
(hold: boolean) => {
if (currentCall) {
const options: SessionInviteOptions = {
sessionDescriptionHandlerModifiers: hold ? [Web.holdModifier] : [],
};
currentCall.invite(options).then(() => {
setIsHold(hold);
});
}
},
[currentCall]
);

Hector Arroyo

unread,
Jul 1, 2024, 5:16:11 PM7/1/24
to SIP.js
Thanks @Benjamin Flügel
Reply all
Reply to author
Forward
0 new messages