Help to send response 401

33 views
Skip to first unread message

WebRTC

unread,
Jul 1, 2022, 12:16:08 PMJul 1
to JsSIP
Hello.
When making the connection, the server responds with a 401, I have tried to make a second register but I have not been able to do it. Could you please give me an example of how to take the WWW-Authenticate that they send me in the 401 and how to respond with a second register?
Thank you.

My code is:

callRTC () {
    var options = {
      mediaConstraints: { audio: true, video: false },
      eventHandlers: eventHandlers,
      pcConfig: {
        iceServers: [{ urls: ['stun:stun.l.google.com:19302'] }]
      }
    }

    try {
      var socket = new jsSip.WebSocketInterface(
        'wss://********/webrtc/'
      )


      var config = {
        sockets: [socket],
        uri: 'sip:Test@******',
        authorizationUser: 'Test',
        password: '********',
        noAnswerTimeout: 120
      }

      ua = new jsSip.UA(config)
    } catch (error) {
      console.log(error)
    }

    ua.on('connecting', () => {
      console.log('UA "connecting" event')
    })
    ua.on('connected', () => {
      console.log('call is connected');
    })
    ua.on('disconnected', () => {
      console.log('UA "disconnected" event')
    })
    ua.on('registered', data => {
      console.log('UA "registered" event', data)
    })
    ua.on('unregistered', () => {
      console.log('UA "unregistered" event')
    })
    ua.on('registrationFailed', data => {
      console.log('UA "registrationFailed" event', data)
    })
    /* ua.on(
      'newRTCSession',
      ({
        originator,
        session: rtcSession,
        request: rtcRequest,
        response: rtcResponse
      }) => {
        console.log('UA "newRTCSession" event')

        // identify call direction
        if (originator === 'local') {
          const foundUri = rtcRequest.to.toString()
          const delimiterPosition = foundUri.indexOf(';') || null

          console.log(`foundUri: ${foundUri}`)
        } else if (originator === 'remote') {
          const foundUri = rtcRequest.from.toString()
          const delimiterPosition = foundUri.indexOf(';') || null

          console.log(`foundUri: ${foundUri}`)
        }

        if (session) {
          // hangup any existing call
          session.terminate()
        }

        session = rtcSession

        session.on('canceled', message => {})
        session.on('failed', data => {
          console.log('rtcSession "failed" event', data)
          session = null
        })
        session.on('ended', () => {
          console.log('rtcSession "ended" event')
          session = null
        })
        session.on('accepted', () => {
          console.log('rtcSession "accepted" event')
        })
      }
    ) */

    ua.start()

    var eventHandlers = {
      'progress': function(e) {
          console.log('call is in progress');
      },
      'failed': function(e) {
          console.log('call failed with cause: '+ e.data.cause);
      },
      'ended': function(e) {
          console.log('call ended with cause: '+ e.data.cause);
      },
      'confirmed': function(e) {
          console.log('call confirmed');
      }
      };

    jsSip.debug.enable('JsSIP:*')

    ua.register()

    ua.call('****')
Reply all
Reply to author
Forward
0 new messages