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

Implementing Screen share #1092

Open
Madhesh456 opened this issue Oct 22, 2024 · 0 comments
Open

Implementing Screen share #1092

Madhesh456 opened this issue Oct 22, 2024 · 0 comments

Comments

@Madhesh456
Copy link

Hi team,

I am creating VOIP call with screen share option using sipjs and react with freeswitch server , I can't implement screen sharing while on VOIP call but in video call screen sharing works fine , why this issue occurs .
below code snippet i am using for screen share implementation

` const startScreenSharing = async () => {
try {
if (!sessionRef.current) return;

  const screenStream = await navigator.mediaDevices.getDisplayMedia({ video: true });
  screenStreamRef.current = screenStream;
  const peerConnection = sessionRef.current.sessionDescriptionHandler.peerConnection;
  console.log(peerConnection,"peerConnection");
  
  if (!peerConnection) {
    console.error('Peer connection not available');
    return;
  }
  const screenTrack = screenStream.getVideoTracks()[0];
  console.log(screenTrack,"screenTrack");
  originalTrackRef.current = sessionRef.current.sessionDescriptionHandler.peerConnection
    .getSenders()
    .find((sender:any) => sender.track?.kind === 'video')?.track || null;
    console.log(   originalTrackRef.current,"   originalTrackRef.current");
    console.log(  sessionRef.current.sessionDescriptionHandler.peerConnection
      .getSenders(),"  getSenders");
      let videoSender = sessionRef.current?.sessionDescriptionHandler?.peerConnection .getSenders().find((sender:any) => sender.track?.kind === 'video');
      console.log(videoSender,"videoSender");
    if (videoSender) {
      await videoSender.replaceTrack(screenTrack); // Replace the video track with screen sharing track
      setIsScreenSharing(true);
    }   
    else {
      // If no video sender, add the screen-sharing track as a new video sender
      videoSender = peerConnection.addTrack(screenTrack, screenStream);
      console.log(videoSender,"videoSender");
 
      console.error('No video sender found to replace with screen sharing');
    }
    if (sessionRef.current && sessionRef.current.sessionDescriptionHandler) {
      console.log(Object.getOwnPropertyNames(Object.getPrototypeOf(sessionRef.current.sessionDescriptionHandler)),"bject.getOwnPropertyNames");
    }
    const newOffer = await sessionRef.current.sessionDescriptionHandler.getLocalSessionDescription();
    await sessionRef.current.sessionDescriptionHandler.setLocalSessionDescription(newOffer);
    

  setIsScreenSharing(true);
  setCallStatus('Screen sharing started');
} catch (error) {
  console.error('Failed to start screen sharing:', error);
}

};`

while VOIP call video track is missed then how to implement screen share help me fix this

No Video Track Added Yet: A video track has not yet been added to the WebRTC RTCPeerConnection, so when you try to find a sender with kind === 'video', there’s no match. while on audio call kind === 'video', is missed

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

No branches or pull requests

1 participant