Skip to content

Commit

Permalink
Rooms (#201)
Browse files Browse the repository at this point in the history
* Split rooms in different files

* Split rooms in different files and creates a room manager

* Swap websocket server by room manager

* Small improvements and documentation
  • Loading branch information
hbcarlos authored Oct 13, 2023
1 parent 8879800 commit 3997dde
Show file tree
Hide file tree
Showing 19 changed files with 379 additions and 351 deletions.
4 changes: 2 additions & 2 deletions docs/source/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jupyter lab --YDocExtension.file_poll_interval=2
# If None, the document will be kept in memory forever.
jupyter lab --YDocExtension.document_cleanup_delay=100

# The YStore class to use for storing Y updates (default: JupyterSQLiteYStore).
jupyter lab --YDocExtension.ystore_class=ypy_websocket.ystore.TempFileYStore
# The Store class used for storing Y updates (default: SQLiteYStore).
jupyter lab --YDocExtension.ystore_class=jupyter_collaboration.stores.FileYStore
```
9 changes: 9 additions & 0 deletions docs/source/developer/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

COMING...

### Opening a document
![initialization](../images/initialization_diagram.png)

### Autosave
![autosave](../images/autosave_diagram.png)

### Conflict
![autosave](../images/conflict_diagram.png)

## Early attempts

Prior to the current implementation based on [Yjs](https://docs.yjs.dev/), other attempts using
Expand Down
Binary file added docs/source/images/autosave_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/conflict_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/initialization_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 13 additions & 16 deletions jupyter_collaboration/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from .handlers import DocSessionHandler, YDocWebSocketHandler
from .loaders import FileLoaderMapping
from .rooms import RoomManager
from .stores import BaseYStore, SQLiteYStore
from .utils import EVENTS_SCHEMA_PATH
from .websocketserver import JupyterWebsocketServer


class YDocExtension(ExtensionApp):
Expand All @@ -21,8 +21,6 @@ class YDocExtension(ExtensionApp):
Enables Real Time Collaboration in JupyterLab
"""

_store: BaseYStore = None

disable_rtc = Bool(False, config=True, help="Whether to disable real time collaboration.")

file_poll_interval = Float(
Expand Down Expand Up @@ -81,14 +79,7 @@ def initialize_handlers(self):
for k, v in self.config.get(self.ystore_class.__name__, {}).items():
setattr(self.ystore_class, k, v)

# Instantiate the store
self._store = self.ystore_class(log=self.log)

self.ywebsocket_server = JupyterWebsocketServer(
rooms_ready=False,
auto_clean_rooms=False,
log=self.log,
)
self.store = self.ystore_class(log=self.log)

# self.settings is local to the ExtensionApp but here we need
# the global app settings in which the file id manager will register
Expand All @@ -97,17 +88,23 @@ def initialize_handlers(self):
self.serverapp.web_app.settings, self.log, self.file_poll_interval
)

self.room_manager = RoomManager(
self.store,
self.file_loaders,
self.serverapp.event_logger,
self.document_save_delay,
self.log,
)

self.handlers.extend(
[
(
r"/api/collaboration/room/(.*)",
YDocWebSocketHandler,
{
"document_cleanup_delay": self.document_cleanup_delay,
"document_save_delay": self.document_save_delay,
"file_loaders": self.file_loaders,
"store": self._store,
"ywebsocket_server": self.ywebsocket_server,
"store": self.store,
"room_manager": self.room_manager,
},
),
(r"/api/collaboration/session/(.*)", DocSessionHandler),
Expand All @@ -118,7 +115,7 @@ async def stop_extension(self):
# Cancel tasks and clean up
await asyncio.wait(
[
asyncio.create_task(self.ywebsocket_server.clean()),
asyncio.create_task(self.room_manager.clear()),
asyncio.create_task(self.file_loaders.clear()),
],
timeout=3,
Expand Down
Loading

0 comments on commit 3997dde

Please sign in to comment.