Skip to content

Commit a2d1832

Browse files
committed
simplify fake screenshare option
1 parent 12afa23 commit a2d1832

File tree

6 files changed

+14
-33
lines changed

6 files changed

+14
-33
lines changed

scripts/common.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Global namespace.
2-
const webrtcperf = {}
1+
/* global webrtcperf */
32

43
// Capture console messages in a serialized format.
54
webrtcperf.safeStringify = obj => {
@@ -422,8 +421,6 @@ webrtcperf.enabledForSession = value => {
422421
// Common page actions
423422
let actionsStarted = false
424423

425-
webrtcperf.elapsedTime = () => Date.now() - window.WEBRTC_PERF_START_TIMESTAMP
426-
427424
webrtcperf.setupActions = async () => {
428425
if (!window.PARAMS?.actions || actionsStarted) {
429426
return

scripts/get-user-media.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,16 @@ function overrideGetDisplayMedia(constraints) {
5050
}
5151

5252
async function applyGetDisplayMediaCrop(mediaStream) {
53-
if (!window.GET_DISPLAY_MEDIA_CROP) {
54-
return
55-
}
56-
const element = document.querySelector(window.GET_DISPLAY_MEDIA_CROP)
53+
if (!webrtcperf.GET_DISPLAY_MEDIA_CROP) return
54+
const element = document.querySelector(webrtcperf.GET_DISPLAY_MEDIA_CROP)
5755
const videoTrack = mediaStream.getVideoTracks()[0]
5856
if (element && videoTrack) {
5957
if ('RestrictionTarget' in window && 'fromElement' in window.RestrictionTarget) {
60-
log(`applyGetDisplayMediaCrop with RestrictionTarget to "${window.GET_DISPLAY_MEDIA_CROP}"`)
58+
log(`applyGetDisplayMediaCrop with RestrictionTarget to "${webrtcperf.GET_DISPLAY_MEDIA_CROP}"`)
6159
const restrictionTarget = await window.RestrictionTarget.fromElement(element)
6260
await videoTrack.restrictTo(restrictionTarget)
6361
} else {
64-
log(`applyGetDisplayMediaCrop to "${window.GET_DISPLAY_MEDIA_CROP}"`)
62+
log(`applyGetDisplayMediaCrop to "${webrtcperf.GET_DISPLAY_MEDIA_CROP}"`)
6563
element.style.zIndex = 99999
6664
const cropTarget = await window.CropTarget.fromElement(element)
6765
await videoTrack.cropTo(cropTarget)
@@ -194,7 +192,7 @@ if (navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia) {
194192
navigator.mediaDevices.getDisplayMedia = async function (constraints, ...args) {
195193
log(`getDisplayMedia:`, JSON.stringify(constraints, null, 2))
196194
let stopFakeScreenshare = null
197-
if (window.PARAMS?.fakeScreenshare) {
195+
if (webrtcperf.GET_DISPLAY_MEDIA_TYPE === 'browser') {
198196
stopFakeScreenshare = await webrtcperf.setupFakeScreenshare(window.PARAMS?.fakeScreenshare)
199197
}
200198
overrideGetDisplayMedia(constraints)

scripts/peer-connection.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,11 @@ window.RTCPeerConnection = function (conf, options) {
307307
webrtcperf
308308
.waitTrackMedia(receiver.track)
309309
.then(({ now }) => {
310+
const t = webrtcperf.elapsedTime / 1000
310311
if (receiver.track.kind === 'video') {
311-
webrtcperf.videoStartFrameDelayStats.push(now, (now - window.WEBRTC_PERF_START_TIMESTAMP) / 1000)
312+
webrtcperf.videoStartFrameDelayStats.push(now, t)
312313
} else if (receiver.track.kind === 'audio') {
313-
webrtcperf.audioStartFrameDelayStats.push(now, (now - window.WEBRTC_PERF_START_TIMESTAMP) / 1000)
314+
webrtcperf.audioStartFrameDelayStats.push(now, t)
314315
}
315316
})
316317
.catch(err => log(`waitTrackMedia error: ${err.message}`))

scripts/screenshare.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
webrtcperf.setupFakeScreenshare = ({
44
embed = '',
55
slides = 4,
6-
delay = 15000,
6+
delay = 5000,
77
animationDuration = 1000,
88
width = 1920,
99
height = 1080,
@@ -42,7 +42,7 @@ webrtcperf.setupFakeScreenshare = ({
4242
`all: unset; position: fixed; top: 0; left: 0; width: ${width}px; height: ${height}px; z-index: -1; background-color: black; isolation: isolate; transform-style: flat;`,
4343
)
4444
document.body.appendChild(wrapper)
45-
window.GET_DISPLAY_MEDIA_CROP = '#webrtcperf-fake-screenshare'
45+
webrtcperf.GET_DISPLAY_MEDIA_CROP = '#webrtcperf-fake-screenshare'
4646

4747
let running = true
4848
let timeout = 0

src/config.ts

-8
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,6 @@ e.g. \`{"video": {"width": 360, "height": 640}}\``,
428428
env: 'GET_DISPLAY_MEDIA_TYPE',
429429
arg: 'get-display-media-type',
430430
},
431-
getDisplayMediaCrop: {
432-
doc: `An HTML selector used for cropping the \`getDisplayMedia\` video track.`,
433-
format: String,
434-
nullable: true,
435-
default: '',
436-
env: 'GET_DISPLAY_MEDIA_CROP',
437-
arg: 'get-display-media-crop',
438-
},
439431
localStorage: {
440432
doc: `A JSON string with the \`localStorage\` object to be set on page \
441433
load.`,

src/session.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ export interface SessionParams {
150150
disabledVideoCodecs: string
151151
getDisplayMediaOverride: string
152152
getDisplayMediaType: string
153-
getDisplayMediaCrop: string
154153
localStorage: string
155154
clearCookies: boolean
156155
scriptPath: string
@@ -222,7 +221,6 @@ export class Session extends EventEmitter {
222221
// eslint-disable-next-line @typescript-eslint/no-explicit-any
223222
private readonly getDisplayMediaOverride: any | null
224223
private readonly getDisplayMediaType: string
225-
private readonly getDisplayMediaCrop: string | null
226224
// eslint-disable-next-line @typescript-eslint/no-explicit-any
227225
private readonly localStorage?: any
228226
private readonly clearCookies: boolean
@@ -355,7 +353,6 @@ export class Session extends EventEmitter {
355353
disabledVideoCodecs,
356354
getDisplayMediaOverride,
357355
getDisplayMediaType,
358-
getDisplayMediaCrop,
359356
localStorage,
360357
clearCookies,
361358
scriptPath,
@@ -444,7 +441,6 @@ export class Session extends EventEmitter {
444441
this.disabledVideoCodecs = []
445442
}
446443
this.getDisplayMediaType = getDisplayMediaType
447-
this.getDisplayMediaCrop = getDisplayMediaCrop
448444
if (localStorage) {
449445
try {
450446
this.localStorage = JSON5.parse(localStorage)
@@ -840,7 +836,8 @@ export class Session extends EventEmitter {
840836

841837
// Export config to page.
842838
let cmd = `\
843-
window.WEBRTC_PERF_START_TIMESTAMP = ${this.startTimestamp};
839+
webrtcperf = {};
840+
webrtcperf.elapsedTime = () => Date.now() - ${this.startTimestamp};
844841
window.WEBRTC_PERF_URL = "${hideAuth(url)}";
845842
window.WEBRTC_PERF_SESSION = ${this.id};
846843
window.WEBRTC_PERF_TAB_INDEX = ${tabIndex};
@@ -854,6 +851,7 @@ window.RANDOM_AUDIO_PERIOD = ${this.randomAudioPeriod};
854851
try {
855852
window.PARAMS = JSON.parse('${JSON.stringify(this.scriptParams)}' || '{}');
856853
} catch (err) {}
854+
webrtcperf.GET_DISPLAY_MEDIA_TYPE = "${this.getDisplayMediaType}";
857855
`
858856

859857
if (this.serverPort) {
@@ -881,11 +879,6 @@ window.SERVER_USE_HTTPS = ${this.serverUseHttps};
881879
)}');\n`
882880
}
883881

884-
if (this.getDisplayMediaCrop) {
885-
log.debug('Using getDisplayMedia crop:', this.getDisplayMediaCrop)
886-
cmd += `window.GET_DISPLAY_MEDIA_CROP = "${this.getDisplayMediaCrop}";\n`
887-
}
888-
889882
if (this.localStorage) {
890883
log.debug('Using localStorage:', this.localStorage)
891884
Object.entries(this.localStorage).map(([key, value]) => {

0 commit comments

Comments
 (0)