1 | /**
|
2 | * This module defines shims for @jupyterlab/services that allows you to use the
|
3 | * old comm API. Use this, @jupyterlab/services, and the widget base manager to
|
4 | * embed live widgets in a context outside of the notebook.
|
5 | */
|
6 | import { Kernel, KernelMessage } from '@jupyterlab/services';
|
7 | /**
|
8 | * Callbacks for services shim comms.
|
9 | */
|
10 | export interface ICallbacks {
|
11 | shell?: {
|
12 | [key: string]: (msg: KernelMessage.IMessage) => void;
|
13 | };
|
14 | iopub?: {
|
15 | [key: string]: (msg: KernelMessage.IMessage) => void;
|
16 | };
|
17 | input?: (msg: KernelMessage.IMessage) => void;
|
18 | }
|
19 | export interface IClassicComm {
|
20 | /**
|
21 | * Comm id
|
22 | * @return {string}
|
23 | */
|
24 | comm_id: string;
|
25 | /**
|
26 | * Target name
|
27 | * @return {string}
|
28 | */
|
29 | target_name: string;
|
30 | /**
|
31 | * Opens a sibling comm in the backend
|
32 | * @param data
|
33 | * @param callbacks
|
34 | * @param metadata
|
35 | * @param buffers
|
36 | * @return msg id
|
37 | */
|
38 | open(data: any, callbacks: any, metadata?: any, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
39 | /**
|
40 | * Sends a message to the sibling comm in the backend
|
41 | * @param data
|
42 | * @param callbacks
|
43 | * @param metadata
|
44 | * @param buffers
|
45 | * @return message id
|
46 | */
|
47 | send(data: any, callbacks: any, metadata?: any, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
48 | /**
|
49 | * Closes the sibling comm in the backend
|
50 | * @param data
|
51 | * @param callbacks
|
52 | * @param metadata
|
53 | * @param buffers
|
54 | * @return msg id
|
55 | */
|
56 | close(data?: any, callbacks?: any, metadata?: any, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
57 | /**
|
58 | * Register a message handler
|
59 | * @param callback, which is given a message
|
60 | */
|
61 | on_msg(callback: (x: any) => void): void;
|
62 | /**
|
63 | * Register a handler for when the comm is closed by the backend
|
64 | * @param callback, which is given a message
|
65 | */
|
66 | on_close(callback: (x: any) => void): void;
|
67 | }
|
68 | export declare namespace shims {
|
69 | namespace services {
|
70 | /**
|
71 | * Public constructor
|
72 | * @param jsServicesKernel - @jupyterlab/services Kernel.IKernel instance
|
73 | */
|
74 | class CommManager {
|
75 | constructor(jsServicesKernel: Kernel.IKernelConnection);
|
76 | /**
|
77 | * Hookup kernel events.
|
78 | * @param {Kernel.IKernel} jsServicesKernel - /services Kernel.IKernel instance
|
79 | */
|
80 | init_kernel(jsServicesKernel: Kernel.IKernelConnection): void;
|
81 | /**
|
82 | * Creates a new connected comm
|
83 | */
|
84 | new_comm(target_name: string, data: any, callbacks: any, metadata: any, comm_id: string, buffers?: ArrayBuffer[] | ArrayBufferView[]): Promise<Comm>;
|
85 | /**
|
86 | * Register a comm target
|
87 | * @param {string} target_name
|
88 | * @param {(Comm, object) => void} f - callback that is called when the
|
89 | * comm is made. Signature of f(comm, msg).
|
90 | */
|
91 | register_target(target_name: string, f: (comm: Comm, object: KernelMessage.IMessage) => void): void;
|
92 | /**
|
93 | * Unregisters a comm target
|
94 | * @param {string} target_name
|
95 | */
|
96 | unregister_target(target_name: string, f: (comm: Comm, object: KernelMessage.IMessage) => void): void;
|
97 | /**
|
98 | * Register a comm in the mapping
|
99 | */
|
100 | register_comm(comm: Comm): string;
|
101 | targets: any;
|
102 | comms: any;
|
103 | kernel: Kernel.IKernelConnection;
|
104 | jsServicesKernel: Kernel.IKernelConnection;
|
105 | }
|
106 | /**
|
107 | * Public constructor
|
108 | * @param {IComm} jsServicesComm - @jupyterlab/services IComm instance
|
109 | */
|
110 | class Comm implements IClassicComm {
|
111 | constructor(jsServicesComm: Kernel.IComm);
|
112 | /**
|
113 | * Comm id
|
114 | * @return {string}
|
115 | */
|
116 | get comm_id(): string;
|
117 | /**
|
118 | * Target name
|
119 | * @return {string}
|
120 | */
|
121 | get target_name(): string;
|
122 | /**
|
123 | * Opens a sibling comm in the backend
|
124 | * @param data
|
125 | * @param callbacks
|
126 | * @param metadata
|
127 | * @return msg id
|
128 | */
|
129 | open(data: any, callbacks: any, metadata?: any, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
130 | /**
|
131 | * Sends a message to the sibling comm in the backend
|
132 | * @param data
|
133 | * @param callbacks
|
134 | * @param metadata
|
135 | * @param buffers
|
136 | * @return message id
|
137 | */
|
138 | send(data: any, callbacks: any, metadata?: any, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
139 | /**
|
140 | * Closes the sibling comm in the backend
|
141 | * @param data
|
142 | * @param callbacks
|
143 | * @param metadata
|
144 | * @return msg id
|
145 | */
|
146 | close(data?: any, callbacks?: any, metadata?: any, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
147 | /**
|
148 | * Register a message handler
|
149 | * @param callback, which is given a message
|
150 | */
|
151 | on_msg(callback: (x: any) => void): void;
|
152 | /**
|
153 | * Register a handler for when the comm is closed by the backend
|
154 | * @param callback, which is given a message
|
155 | */
|
156 | on_close(callback: (x: any) => void): void;
|
157 | /**
|
158 | * Hooks callback object up with @jupyterlab/services IKernelFuture
|
159 | * @param @jupyterlab/services IKernelFuture instance
|
160 | * @param callbacks
|
161 | */
|
162 | _hookupCallbacks(future: Kernel.IShellFuture, callbacks: ICallbacks): void;
|
163 | jsServicesComm: Kernel.IComm;
|
164 | kernel: Kernel.IKernelConnection;
|
165 | }
|
166 | }
|
167 | }
|
168 | //# sourceMappingURL=services-shim.d.ts.map |
\ | No newline at end of file |