@@ -11,6 +11,7 @@ import {
11
11
Input
12
12
} from './lib/input.js' ;
13
13
let decoder ;
14
+ let isSidebarOpen = false ;
14
15
let audioDecoderWorker = null ;
15
16
let canvas = null ;
16
17
let canvasContext = null ;
@@ -40,8 +41,10 @@ let micWorkletNode = null;
40
41
let preferredInputDeviceId = null ;
41
42
let preferredOutputDeviceId = null ;
42
43
let metricsIntervalId = null ;
43
- const METRICS_INTERVAL_MS = 50 ;
44
+ const METRICS_INTERVAL_MS = 500 ;
44
45
const UPLOAD_CHUNK_SIZE = ( 1024 * 1024 ) - 1 ;
46
+ const FILE_UPLOAD_THROTTLE_MS = 200 ;
47
+ let fileUploadProgressLastSent = { } ;
45
48
// Resources for resolution controls
46
49
window . isManualResolutionMode = false ;
47
50
let manualWidth = null ;
@@ -1220,6 +1223,9 @@ function receiveMessage(event) {
1220
1223
return ;
1221
1224
}
1222
1225
switch ( message . type ) {
1226
+ case 'sidebarVisibilityChanged' :
1227
+ isSidebarOpen = ! ! message . isOpen ;
1228
+ break ;
1223
1229
case 'setScaleLocally' :
1224
1230
if ( isSharedMode ) {
1225
1231
console . log ( "Shared mode: setScaleLocally message ignored (forced true behavior)." ) ;
@@ -2436,33 +2442,41 @@ function handleDecodedFrame(frame) { // frame.codedWidth/Height are physical pix
2436
2442
const sendClientMetrics = ( ) => {
2437
2443
if ( isSharedMode ) return ; // Shared mode does not have client-side FPS display in this context
2438
2444
2439
- const now = performance . now ( ) ;
2440
- const elapsedStriped = now - lastStripedFpsUpdateTime ;
2441
- const elapsedFullFrame = now - lastFpsUpdateTime ;
2442
- const fpsUpdateInterval = 1000 ; // ms
2443
-
2444
- if ( uniqueStripedFrameIdsThisPeriod . size > 0 ) {
2445
- if ( elapsedStriped >= fpsUpdateInterval ) {
2446
- const stripedFps = ( uniqueStripedFrameIdsThisPeriod . size * 1000 ) / elapsedStriped ;
2447
- window . fps = Math . round ( stripedFps ) ;
2448
- uniqueStripedFrameIdsThisPeriod . clear ( ) ;
2449
- lastStripedFpsUpdateTime = now ;
2450
- frameCount = 0 ; // Reset full frame count as striped is primary
2451
- lastFpsUpdateTime = now ; // Also reset its timer
2452
- }
2453
- } else if ( frameCount > 0 ) {
2454
- if ( elapsedFullFrame >= fpsUpdateInterval ) {
2455
- const fullFrameFps = ( frameCount * 1000 ) / elapsedFullFrame ;
2456
- window . fps = Math . round ( fullFrameFps ) ;
2457
- frameCount = 0 ;
2458
- lastFpsUpdateTime = now ;
2459
- lastStripedFpsUpdateTime = now ; // Reset its timer too
2445
+ if ( isSidebarOpen ) {
2446
+ const now = performance . now ( ) ;
2447
+ const elapsedStriped = now - lastStripedFpsUpdateTime ;
2448
+ const elapsedFullFrame = now - lastFpsUpdateTime ;
2449
+ const fpsUpdateInterval = 1000 ; // ms
2450
+
2451
+ if ( uniqueStripedFrameIdsThisPeriod . size > 0 ) {
2452
+ if ( elapsedStriped >= fpsUpdateInterval ) {
2453
+ const stripedFps = ( uniqueStripedFrameIdsThisPeriod . size * 1000 ) / elapsedStriped ;
2454
+ window . fps = Math . round ( stripedFps ) ;
2455
+ uniqueStripedFrameIdsThisPeriod . clear ( ) ;
2456
+ lastStripedFpsUpdateTime = now ;
2457
+ frameCount = 0 ; // Reset full frame count as striped is primary
2458
+ lastFpsUpdateTime = now ; // Also reset its timer
2459
+ }
2460
+ } else if ( frameCount > 0 ) {
2461
+ if ( elapsedFullFrame >= fpsUpdateInterval ) {
2462
+ const fullFrameFps = ( frameCount * 1000 ) / elapsedFullFrame ;
2463
+ window . fps = Math . round ( fullFrameFps ) ;
2464
+ frameCount = 0 ;
2465
+ lastFpsUpdateTime = now ;
2466
+ lastStripedFpsUpdateTime = now ; // Reset its timer too
2467
+ }
2468
+ } else {
2469
+ if ( elapsedStriped >= fpsUpdateInterval || elapsedFullFrame >= fpsUpdateInterval ) {
2470
+ window . fps = 0 ;
2471
+ lastFpsUpdateTime = now ;
2472
+ lastStripedFpsUpdateTime = now ;
2473
+ }
2460
2474
}
2461
- } else {
2462
- if ( elapsedStriped >= fpsUpdateInterval || elapsedFullFrame >= fpsUpdateInterval ) {
2463
- window . fps = 0 ;
2464
- lastFpsUpdateTime = now ;
2465
- lastStripedFpsUpdateTime = now ;
2475
+
2476
+ if ( audioWorkletProcessorPort ) {
2477
+ audioWorkletProcessorPort . postMessage ( {
2478
+ type : 'getBufferSize'
2479
+ } ) ;
2466
2480
}
2467
2481
}
2468
2482
@@ -3682,6 +3696,7 @@ function uploadFileObject(file, pathToSend) {
3682
3696
} , window . location . origin ) ;
3683
3697
websocket . send ( `FILE_UPLOAD_START:${ pathToSend } :${ file . size } ` ) ;
3684
3698
let offset = 0 ;
3699
+ fileUploadProgressLastSent [ pathToSend ] = 0 ;
3685
3700
const reader = new FileReader ( ) ;
3686
3701
reader . onload = function ( e ) {
3687
3702
if ( ! websocket || websocket . readyState !== WebSocket . OPEN ) {
@@ -3704,17 +3719,26 @@ function uploadFileObject(file, pathToSend) {
3704
3719
websocket . send ( prefixedView . buffer ) ;
3705
3720
offset += e . target . result . byteLength ;
3706
3721
const progress = file . size > 0 ? Math . round ( ( offset / file . size ) * 100 ) : 100 ;
3707
- window . postMessage ( {
3708
- type : 'fileUpload' ,
3709
- payload : {
3710
- status : 'progress' ,
3711
- fileName : pathToSend ,
3712
- progress : progress ,
3713
- fileSize : file . size
3714
- }
3715
- } , window . location . origin ) ;
3716
- if ( offset < file . size ) readChunk ( offset ) ;
3717
- else {
3722
+ const now = Date . now ( ) ;
3723
+ if ( now - fileUploadProgressLastSent [ pathToSend ] > FILE_UPLOAD_THROTTLE_MS ) {
3724
+ window . postMessage ( {
3725
+ type : 'fileUpload' ,
3726
+ payload : {
3727
+ status : 'progress' ,
3728
+ fileName : pathToSend ,
3729
+ progress : progress ,
3730
+ fileSize : file . size
3731
+ }
3732
+ } , window . location . origin ) ;
3733
+ fileUploadProgressLastSent [ pathToSend ] = now ;
3734
+ }
3735
+ if ( offset < file . size ) {
3736
+ setTimeout ( ( ) => readChunk ( offset ) , 0 ) ;
3737
+ } else {
3738
+ window . postMessage ( {
3739
+ type : 'fileUpload' ,
3740
+ payload : { status : 'progress' , fileName : pathToSend , progress : 100 , fileSize : file . size }
3741
+ } , window . location . origin ) ;
3718
3742
websocket . send ( `FILE_UPLOAD_END:${ pathToSend } ` ) ;
3719
3743
window . postMessage ( {
3720
3744
type : 'fileUpload' ,
0 commit comments