raise screen share quality and stop the grid from overflowing
Screen share was capped by WebRTC's default ~2.5 Mbps and by window capture resolution, and fixed aspect-video cards forced the page to scroll. Adds minimal [sejong-rtc] logs to diagnose ICE failures. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
14028e5d7c
commit
47a7a717ec
8 files changed
+241
-34
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { rtcLog, rtcWarn } from '~/utils/rtcLog'
|
||||
|
||||
export function useScreenShare() {
|
||||
const localStream = ref<MediaStream | null>(null)
|
||||
const streamId = ref<string | null>(null)
|
||||
const error = ref<string | null>(null)
|
||||
const settings = ref<MediaTrackSettings | null>(null)
|
||||
const isSharing = computed(() => Boolean(localStream.value))
|
||||
|
||||
async function startShare(clientId: string) {
|
||||
@@ -9,11 +12,12 @@ export function useScreenShare() {
|
||||
try {
|
||||
const stream = await navigator.mediaDevices.getDisplayMedia({
|
||||
video: {
|
||||
width: { ideal: 1920 },
|
||||
height: { ideal: 1080 },
|
||||
width: { ideal: 1920, max: 1920 },
|
||||
height: { ideal: 1080, max: 1080 },
|
||||
frameRate: { ideal: 60, max: 60 },
|
||||
// Monitor capture reaches full 1080p; window capture is capped by the window size.
|
||||
// @ts-expect-error displaySurface is supported in Chromium
|
||||
displaySurface: 'window',
|
||||
displaySurface: 'monitor',
|
||||
},
|
||||
audio: {
|
||||
// @ts-expect-error Chromium system audio options
|
||||
@@ -27,9 +31,30 @@ export function useScreenShare() {
|
||||
streamId.value = `${clientId}-${Date.now()}`
|
||||
|
||||
const videoTrack = stream.getVideoTracks()[0]
|
||||
videoTrack?.addEventListener('ended', () => {
|
||||
stopShare()
|
||||
})
|
||||
if (videoTrack) {
|
||||
// Games favour framerate over per-frame sharpness.
|
||||
videoTrack.contentHint = 'motion'
|
||||
try {
|
||||
await videoTrack.applyConstraints({
|
||||
width: { ideal: 1920 },
|
||||
height: { ideal: 1080 },
|
||||
frameRate: { ideal: 60 },
|
||||
})
|
||||
} catch (e) {
|
||||
rtcWarn('applyConstraints failed', String(e))
|
||||
}
|
||||
settings.value = videoTrack.getSettings()
|
||||
rtcLog('capture:settings', settings.value)
|
||||
if ((settings.value.height || 0) < 1080) {
|
||||
rtcWarn(
|
||||
'capture below 1080p — pick a full monitor (window capture is limited to the window size)',
|
||||
{ width: settings.value.width, height: settings.value.height },
|
||||
)
|
||||
}
|
||||
videoTrack.addEventListener('ended', () => {
|
||||
stopShare()
|
||||
})
|
||||
}
|
||||
|
||||
return { stream, streamId: streamId.value }
|
||||
} catch (e) {
|
||||
@@ -42,11 +67,12 @@ export function useScreenShare() {
|
||||
localStream.value?.getTracks().forEach((t) => t.stop())
|
||||
localStream.value = null
|
||||
streamId.value = null
|
||||
settings.value = null
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopShare()
|
||||
})
|
||||
|
||||
return { localStream, streamId, isSharing, error, startShare, stopShare }
|
||||
return { localStream, streamId, settings, isSharing, error, startShare, stopShare }
|
||||
}
|
||||
Reference in new issue
Block a user