@@ -33,14 +33,17 @@ resolutions.set(fixedResolutions.resolution720p,{width: 1280, height: 720})
33
33
resolutions . set ( fixedResolutions . resolution480p , { width :854 , height : 480 } )
34
34
resolutions . set ( fixedResolutions . resolution360p , { width : 640 , height :360 } )
35
35
36
+ const DEFAULT_MAX_FRAMERATE = 60
37
+ const DEFAULT_IDEAL_FRAMERATE = 30
38
+
36
39
let stream : MediaStream | undefined
37
40
let unlistenerStreamingSignal : ( ( ) => void ) | undefined
38
41
39
- async function getDisplayMediaStream ( resolution : fixedResolutions = fixedResolutions . resolution720p ) {
42
+ async function getDisplayMediaStream ( resolution : fixedResolutions = fixedResolutions . resolution720p , idealFrameRate = DEFAULT_IDEAL_FRAMERATE , maxFramerate = DEFAULT_MAX_FRAMERATE ) {
40
43
try {
41
44
const mediastream = await navigator . mediaDevices . getDisplayMedia ( {
42
45
video : {
43
- frameRate : { ideal :30 , max : 60 } ,
46
+ frameRate : { ideal : idealFrameRate , max : maxFramerate } ,
44
47
...( resolutions . get ( resolution ) ?? { } ) ,
45
48
noiseSuppression : true ,
46
49
autoGainControl : true ,
@@ -73,7 +76,7 @@ export function StopStreaming() {
73
76
}
74
77
}
75
78
76
- export function CreateHostStream ( resolution : fixedResolutions = fixedResolutions . resolution720p ) {
79
+ export function CreateHostStream ( resolution : fixedResolutions = fixedResolutions . resolution720p , idealFrameRate = DEFAULT_IDEAL_FRAMERATE , maxFramerate = DEFAULT_MAX_FRAMERATE ) {
77
80
initStreamingPeerConnection ( ) ;
78
81
79
82
if ( ! peerConnection ) {
@@ -135,9 +138,8 @@ export function CreateHostStream(resolution: fixedResolutions = fixedResolutions
135
138
if ( ! offer || offerArrived ) return ;
136
139
await peerConnection . setRemoteDescription ( offer ) ;
137
140
offerArrived = true
138
- console . log ( "displaymedia" ) ;
139
141
// eslint-disable-next-line no-case-declarations
140
- stream = await getDisplayMediaStream ( resolution ) ;
142
+ stream = await getDisplayMediaStream ( resolution , idealFrameRate , maxFramerate ) ;
141
143
142
144
stream ?. getTracks ( ) . forEach ( ( track ) => {
143
145
if ( ! stream ) return
@@ -149,7 +151,7 @@ export function CreateHostStream(resolution: fixedResolutions = fixedResolutions
149
151
}
150
152
params . encodings . forEach ( ( _ , i ) => {
151
153
params . encodings [ i ] . maxBitrate = 5_000_000
152
- params . encodings [ i ] . maxFramerate = 60
154
+ params . encodings [ i ] . maxFramerate = maxFramerate
153
155
// params.encodings[i].scaleResolutionDownBy = 1.25
154
156
params . encodings [ i ] . priority = "high"
155
157
} )
0 commit comments