@@ -21,10 +21,21 @@ import {
21
21
ISharedModelFactory
22
22
} from '@jupyter/collaborative-drive' ;
23
23
import { Awareness } from 'y-protocols/awareness' ;
24
+ import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
25
+ import * as encoding from 'lib0/encoding' ;
24
26
25
27
const DISABLE_RTC =
26
28
PageConfig . getOption ( 'disableRTC' ) === 'true' ? true : false ;
27
29
30
+ const RAW_MESSAGE_TYPE = 2 ;
31
+
32
+ const SAVE_MESSAGE = ( ( ) => {
33
+ const encoder = encoding . createEncoder ( ) ;
34
+ encoding . writeVarUint ( encoder , RAW_MESSAGE_TYPE ) ;
35
+ encoding . writeVarString ( encoder , 'save' ) ;
36
+ return encoding . toUint8Array ( encoder ) ;
37
+ } ) ( ) ;
38
+
28
39
/**
29
40
* The url for the default drive service.
30
41
*/
@@ -42,6 +53,7 @@ namespace RtcContentProvider {
42
53
user : User . IManager ;
43
54
trans : TranslationBundle ;
44
55
globalAwareness : Awareness | null ;
56
+ docmanagerSettings : ISettingRegistry . ISettings | null ;
45
57
}
46
58
}
47
59
@@ -57,6 +69,7 @@ export class RtcContentProvider
57
69
this . _serverSettings = options . serverSettings ;
58
70
this . sharedModelFactory = new SharedModelFactory ( this . _onCreate ) ;
59
71
this . _providers = new Map < string , WebSocketProvider > ( ) ;
72
+ this . _docmanagerSettings = options . docmanagerSettings ;
60
73
}
61
74
62
75
/**
@@ -123,7 +136,7 @@ export class RtcContentProvider
123
136
const provider = this . _providers . get ( key ) ;
124
137
125
138
if ( provider ) {
126
- // Save is done from the backend
139
+ provider . wsProvider ?. ws ?. send ( SAVE_MESSAGE ) ;
127
140
const fetchOptions : Contents . IFetchOptions = {
128
141
type : options . type ,
129
142
format : options . format ,
@@ -150,6 +163,19 @@ export class RtcContentProvider
150
163
if ( typeof options . format !== 'string' ) {
151
164
return ;
152
165
}
166
+ // Set initial autosave value, used to determine backend autosave (default: true)
167
+ const autosave =
168
+ ( this . _docmanagerSettings ?. composite ?. [ 'autosave' ] as boolean ) ?? true ;
169
+
170
+ sharedModel . awareness . setLocalStateField ( 'autosave' , autosave ) ;
171
+
172
+ // Watch for changes in settings
173
+ this . _docmanagerSettings ?. changed . connect ( ( ) => {
174
+ const newAutosave =
175
+ ( this . _docmanagerSettings ?. composite ?. [ 'autosave' ] as boolean ) ?? true ;
176
+ sharedModel . awareness . setLocalStateField ( 'autosave' , newAutosave ) ;
177
+ } ) ;
178
+
153
179
try {
154
180
const provider = new WebSocketProvider ( {
155
181
url : URLExt . join ( this . _serverSettings . wsUrl , DOCUMENT_PROVIDER_URL ) ,
@@ -235,6 +261,7 @@ export class RtcContentProvider
235
261
private _providers : Map < string , WebSocketProvider > ;
236
262
private _ydriveFileChanged = new Signal < this, Contents . IChangedArgs > ( this ) ;
237
263
private _serverSettings : ServerConnection . ISettings ;
264
+ private _docmanagerSettings : ISettingRegistry . ISettings | null ;
238
265
}
239
266
240
267
/**
0 commit comments