Sip.js: Property 'peerConnection' does not exist on type 'SessionDescriptionHandler'

Created on 28 May 2020  ·  5Comments  ·  Source: onsip/SIP.js

Hello,
I got the following problem when trying to migrate from sipjs 0.15.11 to sjipjs 0.16.1. Am I missing something here?

Describe the bug
Property 'peerConnection' does not exist on type 'SessionDescriptionHandler'

Logs

error TS2339: Property 'peerConnection' does not exist on type 'SessionDescriptionHandler'.

To Reproduce
Steps to reproduce the behavior:

  1. Create a user agent and handle incoming call
  2. Try to attach a media as mentioned here attach-media
    Using this code
// Assumes you have a media element on the DOM
const mediaElement = document.getElementById('mediaElement');

const remoteStream = new MediaStream();
function setupRemoteMedia(session: Session) {
  session.sessionDescriptionHandler.peerConnection.getReceivers().forEach((receiver) => {
    if (receiver.track) {
      remoteStream.addTrack(receiver.track);
    }
  });
  mediaElement.srcObject = remoteStream;
  mediaElement.play();
}

Expected behavior
Property 'peerConnection' should exist on type 'SessionDescriptionHandler'

Observed behavior
Compilation throws the error :
Property 'peerConnection' does not exist on type 'SessionDescriptionHandler'

Environment Information

  • SipJS 0.16.1
Typescript

Most helpful comment

I meet the same issue, and I import the SessionDescriptionHandler from '_sip.js/lib/platform/web_' to fix it, it works well so far.

All 5 comments

To be more precise peerConnection does exist on the file platform/web/session-description-handler/session-description-handler.ts

  public peerConnection!: RTCPeerConnection;

But not on api/session-description-handler.ts

Is that why it's not part of the definition file?

I meet the same issue, and I import the SessionDescriptionHandler from '_sip.js/lib/platform/web_' to fix it, it works well so far.

Everything in _'sip.js/lib/platform/web'_ is exported in the Web namespace, so you may also import { Web } from "sip.js" and then reference as Web.SessionDescriptionHandler.

Type peerConnection will not exist on the SessionDescriptionHandler Interface. The idea is that you could write a SDH for an environment that is not SIP.js and therefore has no peer connection. Import and use types from the Web.SessionDescriptionHandler if you know you are using the web implementation. This is intentional.

If someone should also have this problem. That's how it worked for me:

import '{ SessionDescriptionHandler } from 'sip.js/lib/platform/web'

case SessionState.Established:
        let sessionDescriptionHandler: SessionDescriptionHandler = inviter.sessionDescriptionHandler as SessionDescriptionHandler;
        setupRemoteMedia(sessionDescriptionHandler);
        break;

function setupRemoteMedia(session: SessionDescriptionHandler) {
  let receiversList: any = session.peerConnection.getReceivers();
  receiversList.forEach((receiver: RTCRtpReceiver) => {
    if (receiver.track) {
      remoteStream.addTrack(receiver.track);
    }
  });
  mediaElement.srcObject = remoteStream;
  mediaElement.play();
}

Improvements and remarks are gladly accepted.

Was this page helpful?
0 / 5 - 0 ratings