Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,8 @@ dmypy.json

# Yarn cache
.yarn/

# Miscellaneous
playground/

.vscode/
36 changes: 31 additions & 5 deletions jupyter_rtc_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,44 @@
warnings.warn("Importing 'jupyter_rtc_core' outside a proper installation.")
__version__ = "dev"

from .app import RtcExtensionApp
from traitlets.config import Config

from .handlers import setup_handlers
from .outputs.connection import RTCWebsocketConnection
from .outputs.handlers import setup_handlers as setup_output_handlers
from .outputs.manager import OutputsManager


def _jupyter_labextension_paths():
return [{
"src": "labextension",
"dest": "@jupyter/rtc-core"
}]


def _jupyter_server_extension_points():
return [{
"module": "jupyter_rtc_core",
"app": RtcExtensionApp
"module": "jupyter_rtc_core"
}]


def _link_jupyter_server_extension(server_app):
"""Setup custom config needed by this extension."""
server_app.kernel_websocket_connection_class = RTCWebsocketConnection
c = Config()
c.ServerApp.kernel_websocket_connection_class = "jupyter_rtc_core.outputs.connection.RTCWebsocketConnection"
server_app.update_config(c)


def _load_jupyter_server_extension(server_app):
"""Registers the API handler to receive HTTP requests from the frontend extension.
Parameters
----------
server_app: jupyterlab.labapp.LabApp
JupyterLab application instance
"""
setup_handlers(server_app.web_app)
setup_output_handlers(server_app.web_app)
om = OutputsManager(config=server_app.config)
server_app.web_app.settings["outputs_manager"] = om

name = "jupyter_rtc_core"
server_app.log.info(f"Registered {name} server extension")
12 changes: 6 additions & 6 deletions jupyter_rtc_core/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from jupyter_server.extension.application import ExtensionApp
from traitlets.config import Config

from .handlers import RouteHandler
from .websockets import GlobalAwarenessWebsocket, YRoomWebsocket
Expand All @@ -13,11 +14,10 @@ class RtcExtensionApp(ExtensionApp):
# this can be deleted prior to initial release.
(r"jupyter-rtc-core/get-example/?", RouteHandler),
# global awareness websocket
(r"api/collaboration/room/JupyterLab:globalAwareness/?", GlobalAwarenessWebsocket),
# ydoc websocket
(r"api/collaboration/room/(.*)", YRoomWebsocket)
# (r"api/collaboration/room/JupyterLab:globalAwareness/?", GlobalAwarenessWebsocket),
# # ydoc websocket
# (r"api/collaboration/room/(.*)", YRoomWebsocket)
]

def initialize(self):
super().initialize()



9 changes: 9 additions & 0 deletions jupyter_rtc_core/handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from jupyter_server.base.handlers import APIHandler
from jupyter_server.utils import url_path_join
import tornado

class RouteHandler(APIHandler):
Expand All @@ -12,3 +13,11 @@ def get(self):
self.finish(json.dumps({
"data": "This is /jupyter-rtc-core/get-example endpoint!"
}))

def setup_handlers(web_app):
host_pattern = ".*$"

base_url = web_app.settings["base_url"]
route_pattern = url_path_join(base_url, "jupyter-rtc-core", "get-example")
handlers = [(route_pattern, RouteHandler)]
web_app.add_handlers(host_pattern, handlers)
Empty file.
Loading