Skip to content

Commit

Permalink
Adds a flag to disable RTC (#177)
Browse files Browse the repository at this point in the history
* Adds a flag to disable RTC

* Temporarily fix for tests
  • Loading branch information
hbcarlos authored Jul 13, 2023
1 parent 8267706 commit 5190a17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
12 changes: 11 additions & 1 deletion jupyter_collaboration/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import asyncio

from jupyter_server.extension.application import ExtensionApp
from traitlets import Float, Type
from traitlets import Bool, Float, Type
from ypy_websocket.ystore import BaseYStore

from .handlers import DocSessionHandler, YDocWebSocketHandler
Expand All @@ -17,6 +17,12 @@

class YDocExtension(ExtensionApp):
name = "jupyter_collaboration"
app_name = "Collaboration"
description = """
Enables Real Time Collaboration in JupyterLab
"""

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

file_poll_interval = Float(
1,
Expand Down Expand Up @@ -66,6 +72,10 @@ def initialize_settings(self):
)

def initialize_handlers(self):
self.serverapp.web_app.settings.setdefault(
"page_config_data", {"disableRTC": self.disable_rtc}
)

# Set configurable parameters to YStore class
for k, v in self.config.get(self.ystore_class.__name__, {}).items():
setattr(self.ystore_class, k, v)
Expand Down
9 changes: 6 additions & 3 deletions packages/docprovider/src/ydrive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { URLExt } from '@jupyterlab/coreutils';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { TranslationBundle } from '@jupyterlab/translation';
import { Contents, Drive, User } from '@jupyterlab/services';

Expand All @@ -14,6 +14,9 @@ import {
SharedDocumentFactory
} from './tokens';

const DISABLE_RTC =
PageConfig.getOption('disableRTC') === 'true' ? true : false;

/**
* The url for the default drive service.
*/
Expand Down Expand Up @@ -177,7 +180,7 @@ class SharedModelFactory implements ISharedModelFactory {
/**
* Whether the IDrive supports real-time collaboration or not.
*/
readonly collaborative = true;
readonly collaborative = !DISABLE_RTC;

/**
* Register a SharedDocumentFactory.
Expand Down Expand Up @@ -208,7 +211,7 @@ class SharedModelFactory implements ISharedModelFactory {
return;
}

if (!options.collaborative) {
if (!this.collaborative || !options.collaborative) {
// Bail if the document model does not support collaboration
// the `sharedModel` will be the default one.
return;
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ dependencies = [
"jupyter_ydoc>=1.1.0a0,<2.0.0",
"ypy-websocket>=0.12.1,<0.13.0",
"jupyter_events",
"jupyter_server_fileid>=0.6.0,<1"
"jupyter_server_fileid>=0.6.0,<1",
"jsonschema[format-nongpl,format_nongpl]<4.18.0" # https://github.com/jupyter/jupyter_events/pull/80
]
dynamic = ["version", "description", "authors", "urls", "keywords"]

Expand Down

0 comments on commit 5190a17

Please sign in to comment.