Skip to content

Implementing Screen share  #1092

Open
Open

Description

@Madhesh456

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions