Skip to content

Commit 9381437

Browse files
committed
Remove unwanted jupyter collaboration code; use fileID index API to create ID on kernel session creation
1 parent 2eb03bd commit 9381437

File tree

10 files changed

+55
-244
lines changed

10 files changed

+55
-244
lines changed

jupyter_rtc_core/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class RtcExtensionApp(ExtensionApp):
2020
# (r"api/collaboration/room/JupyterLab:globalAwareness/?", GlobalAwarenessWebsocket),
2121
# # ydoc websocket
2222
(r"api/collaboration/room/(.*)", YRoomWebsocket),
23-
# handler that just adds compatibility with Jupyter Collaboration's frontend
24-
(r"api/collaboration/session/(.*)", YRoomSessionHandler),
23+
# # handler that just adds compatibility with Jupyter Collaboration's frontend
24+
# (r"api/collaboration/session/(.*)", YRoomSessionHandler),
2525
(r"api/fileid/index", FileIDIndexHandler)
2626
]
2727

jupyter_rtc_core/kernels/websocket_connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def handle_incoming_message(self, incoming_msg):
3535
def handle_outgoing_message(self, channel_name, msg):
3636
"""Handle the ZMQ message."""
3737
try:
38+
# Remove signature from message to be compatible with Jupyter Server.
39+
# See here: https://github.com/jupyter-server/jupyter_server/blob/4ee6e1ddc058f87b2c5699cd6b9caf780a013044/jupyter_server/services/kernels/connection/channels.py#L504
40+
msg = msg[1:]
3841
msg = serialize_msg_to_ws_v1(msg, channel_name)
3942
self.websocket_handler.write_message(msg, binary=True)
4043
except WebSocketClosedError:

jupyter_rtc_core/session_manager.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ def get_kernel_client(self, kernel_id) -> DocumentAwareKernelClient:
3737

3838
def get_yroom(self, path) -> YRoom:
3939
"""Get the yroom for a given path."""
40-
file_id = self.file_id_manager.get_id(path)
41-
yroom = self.yroom_manager.get_room(file_id)
42-
return yroom
43-
40+
print("DO WE SEE THIS?")
41+
print(path)
42+
file_id = self.file_id_manager.index(path)
43+
room_id = f"json:notebook:{file_id}"
44+
yroom = self.yroom_manager.get_room(room_id)
45+
return yroom
46+
4447
async def create_session(
4548
self,
4649
path: Optional[str] = None,
@@ -53,27 +56,27 @@ async def create_session(
5356
After creating a session, connects the yroom to the kernel client.
5457
"""
5558
output = await super().create_session(
56-
path,
59+
path,
5760
name,
5861
type,
59-
kernel_name,
62+
kernel_name,
6063
kernel_id
6164
)
6265
if kernel_id is None:
6366
kernel_id = output["kernel"]["id"]
6467

65-
6668
# NOTE: Question - is room_id equivalent to file ID?
6769
# Connect this session's yroom to the kernel.
68-
yroom = self.get_yroom(path)
69-
# TODO: we likely have a race condition here... need to
70-
# think about it more. Currently, the kernel client gets
71-
# created after the kernel starts fully. We need the
72-
# kernel client instantiated _before_ trying to connect
73-
# the yroom.
74-
kernel_client = self.get_kernel_client(kernel_id)
75-
await kernel_client.add_yroom(yroom)
76-
self.log.info(f"Connected yroom {yroom.room_id} to kernel {kernel_id}. yroom: {yroom}")
70+
if type == "notebook":
71+
yroom = self.get_yroom(path)
72+
# TODO: we likely have a race condition here... need to
73+
# think about it more. Currently, the kernel client gets
74+
# created after the kernel starts fully. We need the
75+
# kernel client instantiated _before_ trying to connect
76+
# the yroom.
77+
kernel_client = self.get_kernel_client(kernel_id)
78+
await kernel_client.add_yroom(yroom)
79+
self.log.info(f"Connected yroom {yroom.room_id} to kernel {kernel_id}. yroom: {yroom}")
7780
return output
7881

7982
async def delete_session(self, session_id):

src/docprovider/executor.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/docprovider/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@
22
// Distributed under the terms of the Modified BSD License.
33

44
export * from './filebrowser'
5-
export * from './executor'
6-

src/docprovider/notebookCellExecutor.ts

Lines changed: 0 additions & 138 deletions
This file was deleted.

src/docprovider/requests.ts

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ServerConnection, Contents } from '@jupyterlab/services';
1010
* Document session endpoint provided by `jupyter_collaboration`
1111
* See https://github.com/jupyterlab/jupyter_collaboration
1212
*/
13-
const DOC_SESSION_URL = 'api/collaboration/session';
13+
// const DOC_SESSION_URL = 'api/collaboration/session';
1414

1515
/**
1616
* Document session model
@@ -71,44 +71,4 @@ export async function requestAPI<T = any>(
7171
}
7272

7373
return data;
74-
}
75-
76-
export async function requestDocSession(
77-
format: string,
78-
type: string,
79-
path: string
80-
): Promise<ISessionModel> {
81-
const settings = ServerConnection.makeSettings();
82-
const url = URLExt.join(
83-
settings.baseUrl,
84-
DOC_SESSION_URL,
85-
encodeURIComponent(path)
86-
);
87-
const body = {
88-
method: 'PUT',
89-
body: JSON.stringify({ format, type })
90-
};
91-
92-
let response: Response;
93-
try {
94-
response = await ServerConnection.makeRequest(url, body, settings);
95-
} catch (error) {
96-
throw new ServerConnection.NetworkError(error as Error);
97-
}
98-
99-
let data: any = await response.text();
100-
101-
if (data.length > 0) {
102-
try {
103-
data = JSON.parse(data);
104-
} catch (error) {
105-
console.log('Not a JSON response body.', response);
106-
}
107-
}
108-
109-
if (!response.ok) {
110-
throw new ServerConnection.ResponseError(response, data.message || data);
111-
}
112-
113-
return data;
114-
}
74+
}

src/docprovider/ydrive.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export class RtcContentProvider
143143
if (typeof options.format !== 'string') {
144144
return;
145145
}
146+
147+
146148
try {
147149
const provider = new WebSocketProvider({
148150
url: URLExt.join(this._serverSettings.wsUrl, DOCUMENT_PROVIDER_URL),

src/docprovider/yprovider.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ import { IDocumentProvider } from '@jupyter/collaborative-drive';
77
import { showErrorMessage, Dialog } from '@jupyterlab/apputils';
88
import { User } from '@jupyterlab/services';
99
import { TranslationBundle } from '@jupyterlab/translation';
10-
1110
import { PromiseDelegate } from '@lumino/coreutils';
1211
import { Signal } from '@lumino/signaling';
1312

1413
import { DocumentChange, YDocument } from '@jupyter/ydoc';
1514

1615
import { Awareness } from 'y-protocols/awareness';
1716
import { WebsocketProvider as YWebsocketProvider } from 'y-websocket';
18-
19-
import { requestDocSession } from './requests';
17+
import { requestAPI } from './requests';
2018

2119
/**
2220
* A class to provide Yjs synchronization over WebSocket.
@@ -95,19 +93,37 @@ export class WebSocketProvider implements IDocumentProvider {
9593
}
9694

9795
private async _connect(): Promise<void> {
98-
const session = await requestDocSession(
99-
this._format,
100-
this._contentType,
101-
this._path
102-
);
96+
let resp = await requestAPI(
97+
"api/fileid/index?path=" + this._path,
98+
{
99+
method: "POST"
100+
}
101+
)
102+
// let resp: any;
103+
// console.log(this._path);
104+
// while (true) {
105+
// try {
106+
// resp = await requestAPI(
107+
// "api/fileid/id?path=" + this._path
108+
// )
109+
// console.log(resp)
110+
// break;
111+
// } catch {
112+
// console.log("Didn't see a file ID; trying again.")
113+
// }
114+
// // Wait 1 second to try again
115+
// await new Promise(f => setTimeout(f, 5000));
116+
// }
117+
118+
const fileId = resp["id"];
103119

104120
this._yWebsocketProvider = new YWebsocketProvider(
105121
this._serverUrl,
106-
`${session.format}:${session.type}:${session.fileId}`,
122+
`${this._format}:${this._contentType}:${fileId}`,
107123
this._sharedModel.ydoc,
108124
{
109125
disableBc: true,
110-
params: { sessionId: session.sessionId },
126+
// params: { sessionId: session.sessionId },
111127
awareness: this._awareness
112128
}
113129
);

0 commit comments

Comments
 (0)