Select Audio Device for Sip.js SimpleUser

1,140 views
Skip to first unread message

David Plappert

unread,
Mar 8, 2021, 2:53:09 PM3/8/21
to SIP.js
Hello!

I am able to find audio devices using:
navigator.mediaDevices.enumerateDevices();

I am then able to present them as a list to the end-user to select and save the id of the device selected to a variable.

How do I pass the id of the audio device to sip.js?

Can we change the audio device mid-call?

Thank you!

Alan Spurlock

unread,
Mar 8, 2021, 2:55:43 PM3/8/21
to sip...@googlegroups.com
You pass the element to sip.js. It will do the rest. You also have to set the element to use that device. 

And yes, you can switch devices during a call, you just update sip.js options so it knows what element to use. 

--
You received this message because you are subscribed to the Google Groups "SIP.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sip_js+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sip_js/286f8a46-4ea5-4317-a796-dcdcf64dcb5bn%40googlegroups.com.

David Plappert

unread,
Mar 8, 2021, 3:00:05 PM3/8/21
to SIP.js
Thank you for the reply. Can you show an example? I am a bit lost. 

I was searching for something in the options['media'] area but was unable to find anything for this.

This is what my code works like so far that is working:

    async setupSip(){
      var domain = "xxx";
      var user = xxx;
      var pass = xxx;

      var sip_url = user + '@' + domain;

      const options = {
        //aor: "sip:" + sip_url,
        media: {
          remote: {
            audio: document.getElementById('remoteAudio')
          }
        },
        reconnectionAttempts: 999,
        reconnectionDelay: 1,
        userAgentOptions: {
          authorizationPassword: pass,
          authorizationUsername: user,
        }
      };

      const server = "wss://" + domain;

      // this sets up the main object
      this.sip_simpleUser = new this.$Sip.SimpleUser(server, options);

      // this starts getting us connected
      this.sip_simpleUser.connect()
      .then(
        () => {
          if (this.goLiveBtnIsDisabled && this.hangUpBtnIsDisabled){
            this.connectionStatus = 'ready';
            this.goLiveBtnIsDisabled = false;
            this.hangUpBtnIsDisabled = true;
          }
        }
      )
      .catch((error) => {
        console.log(error);
      });

    },

Alan Spurlock

unread,
Mar 8, 2021, 3:01:24 PM3/8/21
to sip...@googlegroups.com
I would for sure, but I just moved and won't get the internet until Friday lol

David Plappert

unread,
Mar 8, 2021, 5:23:13 PM3/8/21
to SIP.js
I figured it out. Here is my code:

const options = {
        aor: "sip:" + sip_url,
        media: {
          constraints:{
            audio:{
              deviceId: {
                exact: this.active_device,
              }
            }
          }
        },
        reconnectionAttempts: 999,
        reconnectionDelay: 1,
        userAgentOptions: {
          authorizationPassword: pass,
          authorizationUsername: user,
        }
      };



Alan Spurlock

unread,
Mar 8, 2021, 7:33:34 PM3/8/21
to sip...@googlegroups.com
That till work! I use vue.js, so mine is little different. I don't have to set the id, just set the element. this.$refs.localAudio

Foxxy Di

unread,
Jun 7, 2021, 10:42:04 AM6/7/21
to SIP.js
Hi.Did you solve your problem?  I have the same problem .  Do you have a piece of code?

вторник, 9 марта 2021 г. в 01:23:13 UTC+3, David Plappert:
Reply all
Reply to author
Forward
0 new messages