@@ -36,24 +36,6 @@ export interface SandboxOpts extends SandboxOptsBase {
36
36
* @type {string }
37
37
*/
38
38
display ?: string
39
-
40
- /**
41
- * Port number for the VNC server.
42
- * @type {number }
43
- */
44
- vncPort ?: number
45
-
46
- /**
47
- * Port number for the noVNC proxy server.
48
- * @type {number }
49
- */
50
- port ?: number
51
-
52
- /**
53
- * Whether to enable authentication for noVNC connections.
54
- * @type {boolean }
55
- */
56
- enableAuth ?: boolean
57
39
}
58
40
59
41
@@ -413,7 +395,7 @@ export class Sandbox extends SandboxBase {
413
395
interface VNCServerOptions {
414
396
vncPort ?: number ;
415
397
port ?: number ;
416
- enableAuth ?: boolean ;
398
+ requireAuth ?: boolean ;
417
399
}
418
400
419
401
// Modified VNCServer class
@@ -424,21 +406,27 @@ class VNCServer {
424
406
private url : URL | null = null ;
425
407
private vncHandle : CommandHandle | null = null ;
426
408
private novncHandle : CommandHandle | null = null ;
427
- private readonly password : string ;
409
+ private password : string | undefined ;
428
410
private vncCommand : string = "" ;
429
411
private readonly novncCommand : string ;
430
412
private readonly desktop : Sandbox ;
431
413
432
414
constructor ( desktop : Sandbox ) {
433
415
this . desktop = desktop ;
434
- this . password = generateRandomString ( ) ;
435
-
436
416
this . novncCommand = (
437
417
`cd /opt/noVNC/utils && ./novnc_proxy --vnc localhost:${ this . vncPort } ` +
438
418
`--listen ${ this . port } --web /opt/noVNC > /tmp/novnc.log 2>&1`
439
419
) ;
440
420
}
441
421
422
+ public getAuthKey ( ) : string {
423
+ if ( ! this . password ) {
424
+ throw new Error ( 'Unable to retrieve stream auth key, check if requireAuth is enabled' ) ;
425
+ }
426
+
427
+ return this . password ;
428
+ }
429
+
442
430
/**
443
431
* Set the VNC command to start the VNC server.
444
432
*/
@@ -465,9 +453,10 @@ class VNCServer {
465
453
/**
466
454
* Get the URL to connect to the VNC server.
467
455
* @param autoConnect - Whether to automatically connect to the server after opening the URL.
456
+ * @param authKey - The password to use to connect to the server.
468
457
* @returns The URL to connect to the VNC server.
469
458
*/
470
- public getUrl ( autoConnect : boolean = true ) : string {
459
+ public getUrl ( { autoConnect = true , authKey } : { autoConnect ?: boolean , authKey ?: string } = { } ) : string {
471
460
if ( this . url === null ) {
472
461
throw new Error ( 'Server is not running' ) ;
473
462
}
@@ -476,8 +465,8 @@ class VNCServer {
476
465
if ( autoConnect ) {
477
466
url . searchParams . set ( 'autoconnect' , 'true' ) ;
478
467
}
479
- if ( this . novncAuthEnabled ) {
480
- url . searchParams . set ( "password" , this . password ) ;
468
+ if ( authKey ) {
469
+ url . searchParams . set ( "password" , authKey ) ;
481
470
}
482
471
return url . toString ( )
483
472
}
@@ -493,7 +482,8 @@ class VNCServer {
493
482
494
483
this . vncPort = opts . vncPort ?? this . vncPort ;
495
484
this . port = opts . port ?? this . port ;
496
- this . novncAuthEnabled = opts . enableAuth ?? this . novncAuthEnabled ;
485
+ this . novncAuthEnabled = opts . requireAuth ?? this . novncAuthEnabled ;
486
+ this . password = this . novncAuthEnabled ? generateRandomString ( ) : undefined ;
497
487
this . url = new URL ( `https://${ this . desktop . getHost ( this . port ) } /vnc.html` ) ;
498
488
499
489
// Stop both servers in case one of them is running.
0 commit comments