admin管理员组文章数量:1355540
How to share and stream screen with livekit in electron app? I've tried this which works on web
await localParticipant.setScreenShareEnabled(true, {
video: {
displaySurface: "monitor",
},
});
but electron doesn't prompt screen share so what I tried is I used electron's desktopCapturer
to collect screen sources and show it on ui and then publish track with selected screen using livekit. But it's didn't work, here is what I've tried
get screen sources using desktopCapturer
in main
async function getScreenSources() {
return await desktopCapturer.getSources({
types: ["window", "screen"],
thumbnailSize: { width: 800, height: 600 },
});
}
used it in the renderer process
const getSources = async () => {
const fetchedSources = await window.ipc.getScreenSources();
setSources(
fetchedSources.map((src) => ({
id: src.id,
name: src.name,
thumbnail: src.thumbnail.toDataURL(),
}))
);
};
getSources();
UI to get a selectedSource
<div className="grid grid-cols-2 gap-4">
{sources.map((source) => (
<div
key={source.id}
className={`p-2 border ${
selectedSource?.id === source.id
? "border-blue-500"
: "border-gray-300"
} cursor-pointer`}
onClick={() => {
if (source.name.toLowerCase() !== "entire screen") {
toast({
title: "Please share entire screen",
});
return;
}
setSelectedSource(source);
}}
>
<img
src={source.thumbnail}
alt={source.name}
className="w-full h-auto"
/>
<p className="text-center">{source.name}</p>
</div>
))}
</div>
share screen with the selected source id, then publish track.
const shareScreen = async () => {
try {
const constraints = {
audio: false,
video: {
mandatory: {
chromeMediaSource: "desktop",
chromeMediaSourceId: selectedSource?.id,
},
},
} as MediaStreamConstraints;
const stream = await navigator.mediaDevices.getUserMedia(constraints);
const videoTrack = stream.getVideoTracks()[0];
// const livekitVideoTrack = new LocalVideoTrack(videoTrack); //tried uncommenting this as well didn't work
await localParticipant.publishTrack(videoTrack, {
name: "screen",
source: Track.Source.ScreenShare,
});
} catch (error) {
console.error("Error starting screen share:", error);
}
};
本文标签: livekit stream screen share in electron not workingStack Overflow
版权声明:本文标题:livekit stream screen share in electron not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744051617a2582527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论