Screen share

70 views
Skip to first unread message

Madhesh

unread,
Oct 30, 2024, 4:52:57 AMOct 30
to discuss-webrtc
i have an issue while screen share using sipjs and react without a webcam i can't share the screen stream like without existing video track the stream is missed how to fix this

 const videoSender = peerconnection.getSenders().find((s: any) => s.track && s.track.kind === 'video');
        if (videoSender) {
          videoSender.replaceTrack(screenTrack);
        } else {
          pc.addTrack(screenTrack,screenStream);
        }
using this method is right the remote user does't receve the stream properly

Philipp Hancke

unread,
Oct 30, 2024, 5:46:23 AMOct 30
to discuss...@googlegroups.com
if you add a track this requires renegotiation (createOffer, setLocalDescription and setRemoteDescription) and if you do not renegotiate the remote end will not see the track.

--
This list falls under the WebRTC Code of Conduct - https://webrtc.org/support/code-of-conduct.
---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/discuss-webrtc/bfb1e6a6-aac7-4b67-a7c9-37bda882c432n%40googlegroups.com.

guest271314

unread,
Oct 30, 2024, 1:29:52 PMOct 30
to discuss-webrtc
you can add a video track with canvas capturestream or mediastreamteackgenerator

Madhesh

unread,
Nov 3, 2024, 3:18:08 PMNov 3
to discuss...@googlegroups.com
const startScreenShare = async () => {
    try {
      const screenStream = await navigator.mediaDevices.getDisplayMedia({
        video: true,
        audio: true,
      });

      if (sessionRef.current) {
        const senders = sessionRef.current.sessionDescriptionHandler.peerConnection.getSenders();

        // Replace the video track with the screen share track
        const videoTrack = screenStream.getVideoTracks()[0];
        const audioTrack = screenStream.getAudioTracks()[0];

        senders.forEach(sender => {
          if (sender.track.kind === 'video') {
            sender.replaceTrack(videoTrack);
          } else if (sender.track.kind === 'audio') {
            sender.replaceTrack(audioTrack);
          }
        });  Great I am using above function on  Sipjs , react and freeswitch for backend above code is working on while video like replacing the stream while on audio call without webcam it not working,  also I just studied some contents like , you told that you need to re negotiate the peerConnection that correct,  in freeswitch server any configuration need or not while making audio to screenShare in sipjs

Madhesh

unread,
Nov 3, 2024, 3:18:10 PMNov 3
to discuss...@googlegroups.com
How to add the canva element could please provide the details above?

guest271314

unread,
Nov 3, 2024, 10:30:46 PMNov 3
to discuss-webrtc

var ctx = document.createElement("canvas").getContext("2d");
var stream = ctx.canvas.captureStream(0);
var [track] = stream.getVideoTracks();
track.onmute = track.onunmute = (e) => console.log(e.type);
var processor = new MediaStreamTrackProcessor(track);
processor.readable.pipeTo(
  new WritableStream({
    start() {
      console.log(track);
    },
    async write(v) {
      console.log(v);
      await scheduler.postTask(() => {
        writeFrame();
      }, {
        delay: 300,
        priority: "user-visible",
      });
    },
    close() {
      console.log("closed");
    },
  }),
).catch(console.error);
writeFrame();

function writeFrame() {
  ctx.fillStyle = "#000";
  ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  track.requestFrame();

}

// Replace the video track with the screen share track
const videoTrack = track;

// To stop the track
// track.stop();

Madhesh

unread,
Nov 3, 2024, 10:43:48 PMNov 3
to discuss...@googlegroups.com

I am using sipjs and freeswitch for making screen sharing during audio call while this process codec is changed like audio to video ,is any configuration needed in freeswitch or not like accepting sip session re negotiation and dialplan for screen sharing or others


guest271314

unread,
Nov 4, 2024, 12:34:13 AMNov 4
to discuss...@googlegroups.com
I have not tried sipjs and freeswitch. You can add the
MediaStreamTrack the MediaStream created by canvas.captureStream()
that streams black frames to the MediaStream from getDisplayMedia()
for the case of no video track.
> You received this message because you are subscribed to a topic in the Google Groups "discuss-webrtc" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/discuss-webrtc/VGSA3fRJVHo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to discuss-webrt...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/discuss-webrtc/CAKSscJCNfHw%2BOVjzU5m1%3DK8OdaUjT9n6Y%3Dwi9vEDJ2jonbGX0Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages