1- import React , { useEffect , useState } from 'react' ;
1+ import React , { useState } from 'react' ;
22import {
33 LiveKitRoom ,
44 BarVisualizer ,
@@ -15,46 +15,16 @@ import type { SVGProps } from 'react';
1515import { ConnectionState } from 'livekit-client' ;
1616
1717
18- export async function fetchJoinInfo ( ) : Promise < { url : string ; token : string } > {
19- const invoke = ( window as any ) . google ?. colab ?. kernel ?. invokeFunction ;
20- if ( invoke ) {
21- const res = await invoke ( "get_join_token" , [ ] ) ;
22- return res . data [ "application/json" ] ;
23- }
24-
25-
26- // This requires that JupyterLab was started with --LabApp.expose_app_in_browser,
27- if ( ( window as any ) . jupyterapp && ( window as any ) . jupyterapp . shell ) {
28- const currentWidget = ( window as any ) . jupyterapp . shell . currentWidget ;
29- if ( currentWidget && currentWidget . context ?. sessionContext ) {
30- const session = currentWidget . context . sessionContext . session ;
31- if ( session && session . kernel ) {
32- try {
33- const comm = session . kernel . createComm ( "get_join_token_comm" ) ;
34- comm . open ( ) ;
35- comm . send ( { request : "token" } ) ;
36- return new Promise ( ( resolve ) => {
37- comm . onMsg = ( msg : any ) => {
38- resolve ( msg . content . data ) ;
39- } ;
40- } ) ;
41- } catch ( error ) {
42- throw new Error ( "Error creating comm channel: " + error ) ;
43- }
44- }
45- }
46- }
47-
18+ export function getJoinInfo ( ) : { url : string ; token : string } {
4819 if ( import . meta. env . MODE === "development" ) {
4920 const url = import . meta. env . VITE_LIVEKIT_URL ;
5021 const token = import . meta. env . VITE_LIVEKIT_TOKEN ;
5122 return { url, token } ;
5223 }
5324
54- throw new Error ( "No suitable kernel connection available" ) ;
25+ return { url : "##livekit-url-placeholder##" , token : "##livekit-token-placeholder##" } ;
5526}
5627
57-
5828const LeaveIcon = ( props : SVGProps < SVGSVGElement > ) => (
5929 < svg xmlns = "http://www.w3.org/2000/svg" width = { 16 } height = { 16 } fill = "none" { ...props } >
6030 < path
@@ -107,20 +77,12 @@ const ConnectedContent: React.FC<{ onDisconnect: () => void }> = ({ onDisconnect
10777} ;
10878
10979const App = ( ) => {
110- const [ joinInfo , setJoinInfo ] = useState < { url : string ; token : string } | null > ( null ) ;
11180 const [ error , setError ] = useState < string | null > ( null ) ;
11281 const [ isConnected , setIsConnected ] = useState ( true ) ;
113-
114- useEffect ( ( ) => {
115- fetchJoinInfo ( )
116- . then ( ( info ) => setJoinInfo ( info ) )
117- . catch ( ( err ) => setError ( err . message ) ) ;
118- } , [ ] ) ;
82+ const joinInfo = getJoinInfo ( ) ;
11983
12084 if ( error ) return < div > Error: { error } </ div > ;
12185
122- if ( ! joinInfo ) return < div > Loading...</ div > ;
123-
12486 if ( ! isConnected ) {
12587 return (
12688 < div className = "content" >
0 commit comments