Uncaught (in promise) DOMException: Not supported (Screensharing Using The WebRTC)

I have electronjs app for the MAC Catalyst. I have implemented audio/video calling functionalities. Those works well.

I have also implemented functionality to share the screen by using below code.

navigator.mediaDevices.getDisplayMedia(options).then((streams) => {
    var peer_connection = session.sessionDescriptionHandler.peerConnection;
    var video_track = streams.getVideoTracks()[0];
    var sender_kind = peer_connection.getSenders().find((sender) => {
        return sender.track.kind == video_track.kind;
    });
    sender_kind.replaceTrack(video_track);

    video_track.onended = () => {
    };
},
    () => {
        console.log("Error occurred while sharing screen");
    }
);

But when I hit the button to share the screen by using above code, I am getting below error.

Uncaught (in promise) DOMException: Not supported

I have also tried navigator.getUserMedia(options,success,error). It's supported by the Mac Catalyst desktop apps. But it's only giving the streams of the webcam.

I have also checked online if navigator.mediaDevices.getDisplayMedia(options) is supported in the Mac Catalyst or not. It's supports in the Mac Catalyst. But still I am facing this issue.

I have also tried with the desktopCapturer API of the electronjs. But I don't know how can I get the streams from it.

//CODE OF 'main.js'

ipcMain.on("ask_permission", () => {
  desktopCapturer
    .getSources({ types: ["window", "screen"] })
    .then(async (sources) => {
      for (const source of sources) {
        // console.log(source);
        if (source.name === "Entire screen") {
          win.webContents.send("SET_SOURCE", source.id);
          return;
        }
      }
    });
});

I have tried to get streams by using the below code in the preload.js. But I was getting the error Cannot read property 'srcObject' of undefined.

window.addEventListener("DOMContentLoaded", (event) => {
  ipcRenderer.on("SET_SOURCE", async (event, sourceId) => {
    try {
      const stream = await navigator.mediaDevices.getUserMedia({
        audio: false,
        video: {
          mandatory: {
            chromeMediaSource: "desktop",
            chromeMediaSourceId: sourceId,
            minWidth: 1280,
            maxWidth: 1280,
            minHeight: 720,
            maxHeight: 720,
          },
        },
      });
      handleStream(stream);
    } catch (e) {
      handleError(e);
    }
  });
  let btn = document.getElementById("btnStartShareOutgoingScreens");
  btn.addEventListener("click", () => {
    if (isSharing == false) {
      ipcRenderer.send("ask_permission");
    } else {
      console.error("USer is already sharing the screen..............");
    }
  });
});

function handleStream(stream) {
  const video = document.createElement("video");
  video.srcObject = stream;
  video.muted = true;
  video.id = "screenShareVideo";
  video.style.display = "none";
  const box = document.getElementById("app");
  box.appendChild(video);
  isSharing = true;
}

How can I resolve it. If this is not supported in the MAC Catalyst, Is there is any other way to share the screen from the MAC Catalyst app by using WebRTC.

Post not yet marked as solved Up vote post of win23 Down vote post of win23
736 views