-
-
Notifications
You must be signed in to change notification settings - Fork 43
Respect autosave setting in RTC backend #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
c9d8dc8
789c874
40fba54
19a0335
45b9ec2
cecb9eb
de5267e
28c1ac9
72fd92b
7e84bf8
6b94adb
9ddd24d
cd23070
518fec4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -21,10 +21,19 @@ import { | |||||||
ISharedModelFactory | ||||||||
} from '@jupyter/collaborative-drive'; | ||||||||
import { Awareness } from 'y-protocols/awareness'; | ||||||||
import { ISettingRegistry } from '@jupyterlab/settingregistry'; | ||||||||
import * as encoding from 'lib0/encoding'; | ||||||||
|
||||||||
const DISABLE_RTC = | ||||||||
PageConfig.getOption('disableRTC') === 'true' ? true : false; | ||||||||
|
||||||||
const SAVE_MESSAGE = (() => { | ||||||||
const encoder = encoding.createEncoder(); | ||||||||
encoding.writeVarUint(encoder, 2); | ||||||||
encoding.writeVarString(encoder, 'save'); | ||||||||
return encoding.toUint8Array(encoder); | ||||||||
})(); | ||||||||
|
||||||||
/** | ||||||||
* The url for the default drive service. | ||||||||
*/ | ||||||||
|
@@ -42,6 +51,7 @@ namespace RtcContentProvider { | |||||||
user: User.IManager; | ||||||||
trans: TranslationBundle; | ||||||||
globalAwareness: Awareness | null; | ||||||||
docmanagerSettings: ISettingRegistry.ISettings | null; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
@@ -57,6 +67,7 @@ export class RtcContentProvider | |||||||
this._serverSettings = options.serverSettings; | ||||||||
this.sharedModelFactory = new SharedModelFactory(this._onCreate); | ||||||||
this._providers = new Map<string, WebSocketProvider>(); | ||||||||
this._docmanagerSettings = options.docmanagerSettings; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
|
@@ -123,7 +134,7 @@ export class RtcContentProvider | |||||||
const provider = this._providers.get(key); | ||||||||
|
||||||||
if (provider) { | ||||||||
// Save is done from the backend | ||||||||
provider.wsProvider?.ws?.send(SAVE_MESSAGE); | ||||||||
const fetchOptions: Contents.IFetchOptions = { | ||||||||
type: options.type, | ||||||||
format: options.format, | ||||||||
|
@@ -150,6 +161,19 @@ export class RtcContentProvider | |||||||
if (typeof options.format !== 'string') { | ||||||||
return; | ||||||||
} | ||||||||
// Set initial autosave value, used to determine backend autosave (default: true) | ||||||||
const autosave = | ||||||||
(this._docmanagerSettings?.composite?.['autosave'] as boolean) ?? true; | ||||||||
|
||||||||
sharedModel.awareness.setLocalStateField('autosave', autosave); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we should also send the The reason I ask is that currently, JupyterLab (frontend) automatically calls If we want to respect the autosave interval properly, I think we could consider removing the jupyter-collaboration/projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py Lines 235 to 237 in 9059310
Here's why:
One potential caveat is that if multiple clients with different Would love to hear your thoughts on this approach and whether you see any concerns or alternatives. CC: @davidbrochart There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should move the discussion to a new issue and address this in a separate PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is reasonable. We could create a new issue after this PR gets merged. |
||||||||
|
||||||||
// Watch for changes in settings | ||||||||
this._docmanagerSettings?.changed.connect(() => { | ||||||||
const newAutosave = | ||||||||
(this._docmanagerSettings?.composite?.['autosave'] as boolean) ?? true; | ||||||||
sharedModel.awareness.setLocalStateField('autosave', newAutosave); | ||||||||
}); | ||||||||
|
||||||||
try { | ||||||||
const provider = new WebSocketProvider({ | ||||||||
url: URLExt.join(this._serverSettings.wsUrl, DOCUMENT_PROVIDER_URL), | ||||||||
|
@@ -235,6 +259,7 @@ export class RtcContentProvider | |||||||
private _providers: Map<string, WebSocketProvider>; | ||||||||
private _ydriveFileChanged = new Signal<this, Contents.IChangedArgs>(this); | ||||||||
private _serverSettings: ServerConnection.ISettings; | ||||||||
private _docmanagerSettings: ISettingRegistry.ISettings | null; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.