@@ -362,45 +362,24 @@ export function isLocalServer(hostname: string): boolean {
362362 * @param certAcceptanceLink - Container element for the certificate link
363363 * @param certLink - Anchor element for the certificate URL
364364 * @param location - Optional location object (defaults to window.location)
365- * @returns Certificate link controller with cleanup and verification helpers
365+ * @returns Cleanup function that removes listeners created by this helper
366366 */
367- export interface CertStatusInfo {
368- accepted : boolean ;
369- required : boolean ;
370- verified : boolean ;
371- }
372-
373- export interface CertLinkController {
374- /** Removes listeners created by setupCertificateAcceptanceLink(). */
375- ( ) : void ;
376- /** Forces a cert check for the current effective URL and updates status. */
377- verifyNow : ( ) => Promise < CertStatusInfo > ;
378- /** Waits for an in-flight cert check started elsewhere (if any). */
379- waitForPendingVerification : ( ) => Promise < CertStatusInfo > ;
380- }
381-
382367export function setupCertificateAcceptanceLink (
383368 serverIpInput : HTMLInputElement ,
384369 portInput : HTMLInputElement ,
385370 proxyUrlInput : HTMLInputElement ,
386371 certAcceptanceLink : HTMLElement ,
387372 certLink : HTMLAnchorElement ,
388- onStatusChange ?: ( status : CertStatusInfo ) => void ,
389373 location : Location = window . location ,
390374 fetchFn : typeof fetch = globalThis . fetch
391- ) : CertLinkController {
375+ ) : ( ) => void {
392376 let abortController : AbortController | null = null ;
393377 let accepted = false ;
394378 let certRequired = false ;
395- let verified = false ;
396379 let activeCertUrl : string | null = null ;
397- let pendingVerification : Promise < CertStatusInfo > | null = null ;
380+ let pendingVerification : Promise < void > | null = null ;
398381 let pendingVerificationUrl : string | null = null ;
399382
400- function notifyStatus ( ) : void {
401- onStatusChange ?.( { accepted, required : certRequired , verified } ) ;
402- }
403-
404383 function markAccepted ( url : string ) : void {
405384 if ( url !== activeCertUrl ) {
406385 return ;
@@ -409,35 +388,17 @@ export function setupCertificateAcceptanceLink(
409388 console . warn ( '[CloudXR] Certificate accepted for %s' , url ) ;
410389 }
411390 accepted = true ;
412- verified = true ;
413- certAcceptanceLink . classList . remove ( 'cert-unverified' ) ;
414391 certAcceptanceLink . classList . add ( 'cert-accepted' ) ;
415392 certLink . textContent = `Certificate accepted (${ url } )` ;
416- notifyStatus ( ) ;
417393 }
418394
419395 function markUnverified ( url : string ) : void {
420396 if ( url !== activeCertUrl ) {
421397 return ;
422398 }
423399 accepted = false ;
424- verified = false ;
425- certAcceptanceLink . classList . remove ( 'cert-accepted' ) ;
426- certAcceptanceLink . classList . add ( 'cert-unverified' ) ;
427- certLink . textContent = `Click ${ url } to accept cert` ;
428- notifyStatus ( ) ;
429- }
430-
431- function markPending ( url : string ) : void {
432- if ( url !== activeCertUrl ) {
433- return ;
434- }
435- accepted = false ;
436- verified = true ;
437- certAcceptanceLink . classList . remove ( 'cert-unverified' ) ;
438400 certAcceptanceLink . classList . remove ( 'cert-accepted' ) ;
439401 certLink . textContent = `Click ${ url } to accept cert` ;
440- notifyStatus ( ) ;
441402 }
442403
443404 async function checkCert ( url : string ) : Promise < void > {
@@ -459,7 +420,7 @@ export function setupCertificateAcceptanceLink(
459420 if ( err instanceof DOMException && err . name === 'AbortError' ) {
460421 return ;
461422 }
462- markPending ( url ) ;
423+ markUnverified ( url ) ;
463424 console . warn (
464425 '[CloudXR] Certificate not yet accepted — cert polling errors for %s are expected.' ,
465426 url
@@ -471,7 +432,7 @@ export function setupCertificateAcceptanceLink(
471432 * Updates the certificate acceptance link based on current configuration
472433 * Shows link only when in HTTPS mode without proxy (direct WSS)
473434 */
474- const updateCertLink = ( runCertCheck : boolean ) => {
435+ const updateCertLink = ( ) => {
475436 const isHttps = location . protocol === 'https:' ;
476437 const hasProxy = proxyUrlInput . value . trim ( ) . length > 0 ;
477438 const portValue = parseInt ( portInput . value , 10 ) ;
@@ -490,20 +451,13 @@ export function setupCertificateAcceptanceLink(
490451 activeCertUrl = url ;
491452 certAcceptanceLink . style . display = 'block' ;
492453 certLink . href = url ;
493- // Keep blue "unverified" until a probe result is known.
494454 markUnverified ( url ) ;
495- if ( runCertCheck ) {
496- void checkCert ( url ) ;
497- }
498455 } else {
499456 activeCertUrl = null ;
500457 accepted = false ;
501- verified = false ;
502458 if ( abortController ) abortController . abort ( ) ;
503- certAcceptanceLink . classList . remove ( 'cert-unverified' ) ;
504459 certAcceptanceLink . classList . remove ( 'cert-accepted' ) ;
505460 certAcceptanceLink . style . display = 'none' ;
506- notifyStatus ( ) ;
507461 }
508462 } ;
509463
@@ -514,13 +468,13 @@ export function setupCertificateAcceptanceLink(
514468 } ;
515469
516470 const onInput = ( ) => {
517- updateCertLink ( false ) ;
471+ updateCertLink ( ) ;
518472 } ;
519473 const onCommittedChange = ( ) => {
520474 void startVerification ( ) ;
521475 } ;
522476 const onProxyCommittedChange = ( ) => {
523- updateCertLink ( false ) ;
477+ updateCertLink ( ) ;
524478 if ( certRequired && activeCertUrl ) {
525479 void startVerification ( ) ;
526480 }
@@ -541,29 +495,16 @@ export function setupCertificateAcceptanceLink(
541495 // Run initial cert state after localStorage restoration.
542496 void startVerification ( ) ;
543497
544- async function verifyNow ( ) : Promise < CertStatusInfo > {
545- updateCertLink ( false ) ;
546- if ( certRequired && activeCertUrl ) {
547- await checkCert ( activeCertUrl ) ;
548- } else {
549- notifyStatus ( ) ;
550- }
551- return { accepted, required : certRequired , verified } ;
552- }
553-
554- function startVerification ( ) : Promise < CertStatusInfo > {
555- updateCertLink ( false ) ;
498+ function startVerification ( ) : Promise < void > {
499+ updateCertLink ( ) ;
556500 const currentUrl = certRequired ? activeCertUrl : null ;
557501 if ( pendingVerification && pendingVerificationUrl === currentUrl ) {
558502 return pendingVerification ;
559503 }
560504 const run = ( async ( ) => {
561505 if ( currentUrl ) {
562506 await checkCert ( currentUrl ) ;
563- } else {
564- notifyStatus ( ) ;
565507 }
566- return { accepted, required : certRequired , verified } ;
567508 } ) ( ) ;
568509 pendingVerification = run ;
569510 pendingVerificationUrl = currentUrl ;
@@ -575,18 +516,7 @@ export function setupCertificateAcceptanceLink(
575516 } ) ;
576517 }
577518
578- function waitForPendingVerification ( ) : Promise < CertStatusInfo > {
579- if ( pendingVerification ) {
580- return pendingVerification ;
581- }
582- if ( certRequired && ! verified ) {
583- return startVerification ( ) ;
584- }
585- return Promise . resolve ( { accepted, required : certRequired , verified } ) ;
586- }
587-
588- // Return callable controller with cleanup and verification helpers.
589- const cleanup = ( ) => {
519+ return ( ) => {
590520 serverIpInput . removeEventListener ( 'input' , onInput ) ;
591521 portInput . removeEventListener ( 'input' , onInput ) ;
592522 proxyUrlInput . removeEventListener ( 'input' , onInput ) ;
@@ -599,9 +529,4 @@ export function setupCertificateAcceptanceLink(
599529 window . removeEventListener ( 'focus' , onFocus ) ;
600530 if ( abortController ) abortController . abort ( ) ;
601531 } ;
602- const controller = Object . assign ( cleanup , {
603- verifyNow,
604- waitForPendingVerification,
605- } ) as CertLinkController ;
606- return controller ;
607532}
0 commit comments