import { Panel } from '@lumino/widgets' ; import { JupyterFrontEnd , JupyterFrontEndPlugin , ILayoutRestorer , IRouter , } from '@jupyterlab/application' ; import { ICommandPalette , WidgetTracker } from '@jupyterlab/apputils' ; import { ISettingRegistry } from '@jupyterlab/settingregistry' ; import { ILauncher } from '@jupyterlab/launcher' ; import { CommandIds , IVideoChatManager , URL_PARAM , NS , CSS } from './tokens' ; import { IChatArgs } from './types' ; import { VideoChatManager } from './manager' ; import { VideoChat } from './widget' ; import { chatIcon , prettyChatIcon } from './icons' ; const DEFAULT_LABEL = 'Video Chat' ; const category = 'Video Chat' ; async function activate ( app , palette , router , settingRegistry , launcher ? , restorer ? ) { const manager = new VideoChatManager ( ) ; const { commands , shell } = app ; let widget ; let chat ; let subject = null ; const tracker = new WidgetTracker < Panel > ( { namespace : NS } ) ; if ( ! widget || widget . isDisposed ) { chat = new VideoChat ( manager , { onToggleSidebar : ( ) => { commands . execute ( CommandIds . toggleArea , { } ) . catch ( console . warn ) ; } , } ) ; widget = new Panel ( ) ; widget . addClass ( `${ CSS }-wrapper` ) ; widget . id = `id-${ NS }` ; widget . title . caption = DEFAULT_LABEL ; widget . title . closable = false ; widget . title . icon = chatIcon ; widget . addWidget ( chat ) ; } function updateTitle ( ) { if ( subject != null ) { widget . title . caption = subject ; } else { widget . title . caption = DEFAULT_LABEL ; } widget . title . label = manager . currentArea === 'main' ? widget . title . caption : '' ; } function addToShell ( area ? ) { area = area || manager . currentArea ; shell . add ( widget , area ) ; updateTitle ( ) ; widget . update ( ) ; if ( ! tracker . has ( widget ) ) { tracker . add ( widget ) . catch ( void 0 ) ; } shell . activateById ( widget . id ) ; } manager . meetChanged . connect ( ( ) => { if ( manager . meet ) { manager . meet . on ( 'subjectChange' , ( args ) => { subject = args . subject ; updateTitle ( ) ; } ) ; } else { subject = null ; } updateTitle ( ) ; } ) ; settingRegistry . load ( plugin . id ) . then ( ( settings ) => { manager . settings = settings ; settings . changed . connect ( ( ) => addToShell ( ) ) ; addToShell ( ) ; } ) . catch ( ( ) => addToShell ( ) ) ; commands . addCommand ( CommandIds . open , { label : 'Video Chat' , icon : prettyChatIcon , execute : async ( args ) => { await manager . initialized ; addToShell ( ) ; if ( manager . currentRoom ?. displayName !== args . displayName ) { manager . currentRoom = { displayName : args . displayName } ; } } , } ) ; commands . addCommand ( CommandIds . toggleArea , { label : 'Toggle Video Chat Sidebar' , execute : async ( ) => { manager . currentArea = [ 'right' , 'left' ] . includes ( manager . currentArea ) ? 'main' : 'right' ; } , } ) ; commands . addCommand ( CommandIds . routerStart , { label : 'Open Video Chat from URL' , execute : async ( args ) => { const { request } = args as IRouter . ILocation ; const url = new URL ( `http://example.com${ request }` ) ; const params = url . searchParams ; const displayName = params . get ( URL_PARAM ) ; const chatAfterRoute = async ( ) => { router . routed . disconnect ( chatAfterRoute ) ; if ( manager . currentRoom ?. displayName != displayName ) { await commands . execute ( CommandIds . open , { displayName } ) ; } } ; router . routed . connect ( chatAfterRoute ) ; } , } ) ; palette . addItem ( { command : CommandIds . open , category } ) ; palette . addItem ( { command : CommandIds . toggleArea , category } ) ; router . register ( { command : CommandIds . routerStart , pattern : /.*/ , rank : 29 , } ) ; if ( launcher ) { launcher . add ( { command : CommandIds . open , args : { area : 'main' } } ) ; } if ( restorer ) { restorer . restore ( tracker , { command : CommandIds . open , name : ( ) => `id-${ NS }` } ) . catch ( console . warn ) ; } manager . initialize ( ) ; return manager ; } /**
 * Initialization data for the jupyter-jitsi extension.
 */ const plugin = { id : `${ NS }:plugin` , autoStart : true , requires : [ ICommandPalette , IRouter , ISettingRegistry ] , optional : [ ILauncher , ILayoutRestorer ] , provides : IVideoChatManager , activate , } ; export default [ plugin ] ;