Skip to content

Commit e92faaf

Browse files
authored
Use the real path in session creation to start a yroom (#49)
* Use the real path in session creation to start a yroom * Handle no path or name
1 parent d23e9f7 commit e92faaf

File tree

3 files changed

+19
-37
lines changed

3 files changed

+19
-37
lines changed

jupyter_rtc_core/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44

55
from traitlets import Instance, Type
6-
from .handlers import RouteHandler, YRoomSessionHandler, FileIDIndexHandler
6+
from .handlers import RouteHandler, FileIDIndexHandler
77
from .websockets import GlobalAwarenessWebsocket, YRoomWebsocket
88
from .rooms.yroom_manager import YRoomManager
99

jupyter_rtc_core/handlers.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,4 @@ class RouteHandler(APIHandler):
4141
def get(self):
4242
self.finish(json.dumps({
4343
"data": "This is /jupyter-rtc-core/get-example endpoint!"
44-
}))
45-
46-
47-
# TODO: remove this by v1.0.0 if deemed unnecessary. Just adding this for
48-
# compatibility with the `jupyter_collaboration` frontend.
49-
class YRoomSessionHandler(APIHandler):
50-
SESSION_ID = str(uuid.uuid4())
51-
52-
@tornado.web.authenticated
53-
def put(self, path):
54-
body = json.loads(self.request.body)
55-
format = body["format"]
56-
content_type = body["type"]
57-
# self.log.info("IN HANDLER")
58-
# for k, v in self.settings.items():
59-
# print(f"{k}: {v}")
60-
# print(len(self.settings.items()))
61-
# print(id(self.settings))
62-
63-
file_id_manager = self.settings["file_id_manager"]
64-
file_id = file_id_manager.index(path)
65-
66-
data = json.dumps(
67-
{
68-
"format": format,
69-
"type": content_type,
70-
"fileId": file_id,
71-
"sessionId": self.SESSION_ID,
72-
}
73-
)
74-
self.set_status(200)
75-
self.finish(data)
76-
44+
}))

jupyter_rtc_core/session_manager.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import Optional, Any
23
from jupyter_server.services.sessions.sessionmanager import SessionManager, KernelName, ModelName
34
from jupyter_server.serverapp import ServerApp
@@ -65,10 +66,23 @@ async def create_session(
6566
)
6667
if kernel_id is None:
6768
kernel_id = output["kernel"]["id"]
68-
69+
6970
# Connect this session's yroom to the kernel.
70-
if type == "notebook":
71-
yroom = self.get_yroom(path, type)
71+
if type == "notebook":
72+
# If name or path is None, we cannot map to a yroom,
73+
# so just move on.
74+
if name is None or path is None:
75+
self.log.debug("`name` or `path` was not given, so a yroom was not set up for this session.")
76+
return output
77+
# When JupyterLab creates a session, it uses a fake path
78+
# which is the relative path + UUID, i.e. the notebook
79+
# name is incorrect temporarily. It later makes multiple
80+
# updates to the session to correct the path.
81+
#
82+
# Here, we create the true path to store in the fileID service
83+
# by dropping the UUID and appending the file name.
84+
real_path = os.path.join(os.path.split(path)[0], name)
85+
yroom = self.get_yroom(real_path, type)
7286
# TODO: we likely have a race condition here... need to
7387
# think about it more. Currently, the kernel client gets
7488
# created after the kernel starts fully. We need the

0 commit comments

Comments
 (0)