@jupyterlab/application#IRouter TypeScript Examples
The following examples show how to use
@jupyterlab/application#IRouter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 5 votes |
/**
* Create the server room plugin
*
* In the future, this might `provide` itself with some reasonable API,
* but is already accessible from the manager, which is likely preferable.
*/
function activateServerRooms(
app: JupyterFrontEnd,
chat: IVideoChatManager,
router?: IRouter
): void {
const { __ } = chat;
const { commands } = app;
const provider = new ServerRoomProvider({
serverSettings: app.serviceManager.serverSettings,
});
chat.registerRoomProvider({
id: 'server',
label: __('Server'),
rank: 0,
provider,
});
// If available, Add to the router
if (router) {
commands.addCommand(CommandIds.serverRouterStart, {
label: 'Open Server 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(SERVER_URL_PARAM);
const chatAfterRoute = async () => {
router.routed.disconnect(chatAfterRoute);
if (chat.currentRoom?.displayName != displayName) {
await commands.execute(CommandIds.open, { displayName });
}
};
router.routed.connect(chatAfterRoute);
},
});
router.register({
command: CommandIds.serverRouterStart,
pattern: /.*/,
rank: 29,
});
}
}
Example #2
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 5 votes |
serverRoomsPlugin: JupyterFrontEndPlugin<void> = {
id: `${NS}:rooms-server`,
autoStart: true,
requires: [IVideoChatManager],
optional: [IRouter],
activate: activateServerRooms,
}
Example #3
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 5 votes |
publicRoomsPlugin: JupyterFrontEndPlugin<void> = {
id: `${NS}:rooms-public`,
autoStart: true,
requires: [IVideoChatManager],
optional: [IRouter, ICommandPalette],
activate: activatePublicRooms,
}
Example #4
Source File: plugin.ts From jupyter-videochat with BSD 3-Clause "New" or "Revised" License | 4 votes |
/**
* Create the public room plugin
*
* In the future, this might `provide` itself with some reasonable API,
* but is already accessible from the manager, which is likely preferable.
*/
async function activatePublicRooms(
app: JupyterFrontEnd,
chat: IVideoChatManager,
router?: IRouter,
palette?: ICommandPalette
): Promise<void> {
const { commands } = app;
const { __ } = chat;
chat.registerRoomProvider({
id: 'public',
label: __('Public'),
rank: 999,
provider: {
updateRooms: async () => [],
canCreateRooms: false,
updateConfig: async () => {
return {} as any;
},
},
});
commands.addCommand(CommandIds.togglePublicRooms, {
label: __('Toggle Video Chat Public Rooms'),
isVisible: () => !!chat.settings,
isToggleable: true,
isToggled: () => !chat.settings?.composite.disablePublicRooms,
execute: async () => {
if (!chat.settings) {
console.warn(__('Video chat settings not loaded'));
return;
}
await chat.settings.set(
'disablePublicRooms',
!chat.settings?.composite.disablePublicRooms
);
},
});
// If available, Add to the router
if (router) {
commands.addCommand(CommandIds.publicRouterStart, {
label: __('Open Public 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 roomId = params.get(PUBLIC_URL_PARAM);
const chatAfterRoute = async () => {
router.routed.disconnect(chatAfterRoute);
if (chat.currentRoom?.displayName != roomId) {
chat.currentRoom = {
id: roomId,
displayName: roomId,
description: __('A Public Room'),
};
}
};
router.routed.connect(chatAfterRoute);
},
});
router.register({
command: CommandIds.publicRouterStart,
pattern: /.*/,
rank: 99,
});
}
// If available, add to command palette
if (palette) {
palette.addItem({ command: CommandIds.togglePublicRooms, category });
}
}