Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property 'peerConnection' does not exist on type 'SessionDescriptionHandler' #816

Closed
Fzwael opened this issue May 28, 2020 · 5 comments
Closed

Comments

@Fzwael
Copy link

Fzwael commented May 28, 2020

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
@Fzwael
Copy link
Author

Fzwael commented May 28, 2020

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?

@SD-Gaming
Copy link

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

@john-e-riordan
Copy link
Collaborator

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.

@egreenmachine
Copy link
Collaborator

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.

@floriandeubel
Copy link

floriandeubel commented Jul 1, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants