diff --git a/jupyter_rtc_core/app.py b/jupyter_rtc_core/app.py index 8a4f0c4..3a4196f 100644 --- a/jupyter_rtc_core/app.py +++ b/jupyter_rtc_core/app.py @@ -3,7 +3,7 @@ import asyncio from traitlets import Instance, Type -from .handlers import RouteHandler, YRoomSessionHandler, FileIDIndexHandler +from .handlers import RouteHandler, FileIDIndexHandler from .websockets import GlobalAwarenessWebsocket, YRoomWebsocket from .rooms.yroom_manager import YRoomManager diff --git a/jupyter_rtc_core/handlers.py b/jupyter_rtc_core/handlers.py index 73e3422..8dc9a85 100644 --- a/jupyter_rtc_core/handlers.py +++ b/jupyter_rtc_core/handlers.py @@ -41,36 +41,4 @@ class RouteHandler(APIHandler): def get(self): self.finish(json.dumps({ "data": "This is /jupyter-rtc-core/get-example endpoint!" - })) - - -# TODO: remove this by v1.0.0 if deemed unnecessary. Just adding this for -# compatibility with the `jupyter_collaboration` frontend. -class YRoomSessionHandler(APIHandler): - SESSION_ID = str(uuid.uuid4()) - - @tornado.web.authenticated - def put(self, path): - body = json.loads(self.request.body) - format = body["format"] - content_type = body["type"] - # self.log.info("IN HANDLER") - # for k, v in self.settings.items(): - # print(f"{k}: {v}") - # print(len(self.settings.items())) - # print(id(self.settings)) - - file_id_manager = self.settings["file_id_manager"] - file_id = file_id_manager.index(path) - - data = json.dumps( - { - "format": format, - "type": content_type, - "fileId": file_id, - "sessionId": self.SESSION_ID, - } - ) - self.set_status(200) - self.finish(data) - + })) \ No newline at end of file diff --git a/jupyter_rtc_core/session_manager.py b/jupyter_rtc_core/session_manager.py index fce54aa..a82e17e 100644 --- a/jupyter_rtc_core/session_manager.py +++ b/jupyter_rtc_core/session_manager.py @@ -1,3 +1,4 @@ +import os from typing import Optional, Any from jupyter_server.services.sessions.sessionmanager import SessionManager, KernelName, ModelName from jupyter_server.serverapp import ServerApp @@ -65,10 +66,23 @@ async def create_session( ) if kernel_id is None: kernel_id = output["kernel"]["id"] - + # Connect this session's yroom to the kernel. - if type == "notebook": - yroom = self.get_yroom(path, type) + if type == "notebook": + # If name or path is None, we cannot map to a yroom, + # so just move on. + if name is None or path is None: + self.log.debug("`name` or `path` was not given, so a yroom was not set up for this session.") + return output + # When JupyterLab creates a session, it uses a fake path + # which is the relative path + UUID, i.e. the notebook + # name is incorrect temporarily. It later makes multiple + # updates to the session to correct the path. + # + # Here, we create the true path to store in the fileID service + # by dropping the UUID and appending the file name. + real_path = os.path.join(os.path.split(path)[0], name) + yroom = self.get_yroom(real_path, type) # TODO: we likely have a race condition here... need to # think about it more. Currently, the kernel client gets # created after the kernel starts fully. We need the