onsip / SIP.js

A simple, intuitive, and powerful JavaScript signaling library
https://sipjs.com
MIT License
1.84k stars 693 forks source link

Convert an Audio Call to Video Call (Update SDP / Re-invite) #1075

Open MuneebAhmed568 opened 4 months ago

MuneebAhmed568 commented 4 months ago

Hey, I hope you are doing good.

I am trying to Convert an already Established Audio call to Video Call but getting error on Ice-Candicate I am using SIPJS : 0.21.2

Error

Screenshot 2024-03-18 at 1 58 39 PM

I can't identify why it's not working. I also tried Simple Audio Call , Audio and Video call and even screen share they are working Just fine, error occurs when I try to update SDP.

CODE

userAgentOptions = {
    authorizationPassword: userPassword.value,
    authorizationUsername: userID.value,
    transportOptions : transportOptionss,
    uri: uriUserAgent,
    delegate: userDelegate,
    contactName: userID.value,
    displayName: userID.value,
    viaHost: viaHost,
    userAgentString: userID.value,
    sessionDescriptionHandlerFactoryOptions: {
      iceCheckingTimeout : 50,
      peerConnectionConfiguration : {
        iceServers: [
          // { 
          //   urls: "stun:stun.l.google.com:19302" 
          // },
          {
            urls: "stun:stun.relay.metered.ca:80",
          }
        ], 
        // iceTransportPolicy : "all",
        // bundlePolicy : "max-compat"
        alwaysAcquireMediaFirst : true,

        iceCandidatePoolSize:0,
      },
      constraints: {
        audio: true,
        video: true
      },
    },
    logLevel: 'debug'
  };

  userAgent = new UserAgent(userAgentOptions);
 inviter = new Inviter(userAgent, destination, {
    sessionDescriptionHandlerOptions: {
      constraints: { audio: true, video: false }
    }
  });
 outgoingSession = inviter;
 outgoingSession.invite({requestDelegate : OutgoingRequestDelegate})
 //FOR Re-Invite after call state. = Established
  outgoingSession.invite({
      sessionDescriptionHandlerOptions: {
        constraints: { 
          // audio: true, 
          video: true 
        }
      },
      requestDelegate: OutgoingRequestDelegate
    })
MuneebAhmed568 commented 4 months ago

Nevermind Solved it myself, Just needed to add offerOptions.iceRestart : true. This option is not available by default so I have to manually add it

export interface SessionDescriptionHandlerOptions {
  constraints?: object;
  offerOptions?: RTCOfferOptions;  // added this manually 

}

sessionDescriptionHandlerOptions: {
        constraints: { 
          audio: true, 
          video: true 
        },
        offerOptions : {
          iceRestart : true
        }
      },

Rest of code is same as above mentioned in question