@jupyter/docprovider 4.1.0-rc.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ydrive.d.ts +1 -0
- package/lib/ydrive.js +55 -8
- package/package.json +2 -2
package/lib/ydrive.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export declare class RtcContentProvider extends RestContentProvider implements I
|
|
|
52
52
|
get fileChanged(): ISignal<this, Contents.IChangedArgs>;
|
|
53
53
|
private _onCreate;
|
|
54
54
|
private _user;
|
|
55
|
+
private _saveCounter;
|
|
55
56
|
private _trans;
|
|
56
57
|
private _globalAwareness;
|
|
57
58
|
private _providers;
|
package/lib/ydrive.js
CHANGED
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
|
|
4
4
|
import { RestContentProvider } from '@jupyterlab/services';
|
|
5
|
+
import { PromiseDelegate } from '@lumino/coreutils';
|
|
5
6
|
import { Signal } from '@lumino/signaling';
|
|
6
7
|
import { WebSocketProvider } from './yprovider';
|
|
8
|
+
import * as decoding from 'lib0/decoding';
|
|
7
9
|
import * as encoding from 'lib0/encoding';
|
|
8
10
|
const DISABLE_RTC = PageConfig.getOption('disableRTC') === 'true' ? true : false;
|
|
9
11
|
const RAW_MESSAGE_TYPE = 2;
|
|
10
|
-
const SAVE_MESSAGE = (() => {
|
|
11
|
-
const encoder = encoding.createEncoder();
|
|
12
|
-
encoding.writeVarUint(encoder, RAW_MESSAGE_TYPE);
|
|
13
|
-
encoding.writeVarString(encoder, 'save');
|
|
14
|
-
return encoding.toUint8Array(encoder);
|
|
15
|
-
})();
|
|
16
12
|
/**
|
|
17
13
|
* The url for the default drive service.
|
|
18
14
|
*/
|
|
@@ -102,6 +98,7 @@ export class RtcContentProvider extends RestContentProvider {
|
|
|
102
98
|
console.error(`Failed to open websocket connection for ${options.path}.\n:${error}`);
|
|
103
99
|
}
|
|
104
100
|
};
|
|
101
|
+
this._saveCounter = 0;
|
|
105
102
|
this._ydriveFileChanged = new Signal(this);
|
|
106
103
|
this._user = options.user;
|
|
107
104
|
this._trans = options.trans;
|
|
@@ -154,13 +151,63 @@ export class RtcContentProvider extends RestContentProvider {
|
|
|
154
151
|
* file is saved.
|
|
155
152
|
*/
|
|
156
153
|
async save(localPath, options = {}) {
|
|
157
|
-
var _a
|
|
154
|
+
var _a;
|
|
158
155
|
// Check that there is a provider - it won't e.g. if the document model is not collaborative.
|
|
159
156
|
if (options.format && options.type) {
|
|
160
157
|
const key = `${options.format}:${options.type}:${localPath}`;
|
|
161
158
|
const provider = this._providers.get(key);
|
|
159
|
+
const saveId = ++this._saveCounter;
|
|
162
160
|
if (provider) {
|
|
163
|
-
|
|
161
|
+
const ws = (_a = provider.wsProvider) === null || _a === void 0 ? void 0 : _a.ws;
|
|
162
|
+
if (ws) {
|
|
163
|
+
const delegate = new PromiseDelegate();
|
|
164
|
+
const handler = (event) => {
|
|
165
|
+
const data = new Uint8Array(event.data);
|
|
166
|
+
const decoder = decoding.createDecoder(data);
|
|
167
|
+
try {
|
|
168
|
+
const messageType = decoding.readVarUint(decoder);
|
|
169
|
+
if (messageType !== RAW_MESSAGE_TYPE) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (_a) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const rawReply = decoding.readVarString(decoder);
|
|
177
|
+
let reply = null;
|
|
178
|
+
try {
|
|
179
|
+
reply = JSON.parse(rawReply);
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
console.debug('The raw reply received was not a JSON reply');
|
|
183
|
+
}
|
|
184
|
+
if (reply &&
|
|
185
|
+
reply['type'] === 'save' &&
|
|
186
|
+
reply['responseTo'] === saveId) {
|
|
187
|
+
if (reply.status === 'success') {
|
|
188
|
+
delegate.resolve();
|
|
189
|
+
}
|
|
190
|
+
else if (reply.status === 'failed') {
|
|
191
|
+
delegate.reject('Saving failed');
|
|
192
|
+
}
|
|
193
|
+
else if (reply.status === 'skipped') {
|
|
194
|
+
delegate.reject('Saving already in progress');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
delegate.reject('Unrecognised save reply status');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
ws.addEventListener('message', handler);
|
|
202
|
+
const encoder = encoding.createEncoder();
|
|
203
|
+
encoding.writeVarUint(encoder, RAW_MESSAGE_TYPE);
|
|
204
|
+
encoding.writeVarString(encoder, 'save');
|
|
205
|
+
encoding.writeVarUint(encoder, saveId);
|
|
206
|
+
const saveMessage = encoding.toUint8Array(encoder);
|
|
207
|
+
ws.send(saveMessage);
|
|
208
|
+
await delegate.promise;
|
|
209
|
+
ws.removeEventListener('message', handler);
|
|
210
|
+
}
|
|
164
211
|
const fetchOptions = {
|
|
165
212
|
type: options.type,
|
|
166
213
|
format: options.format,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter/docprovider",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "JupyterLab - Document Provider",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyter-collaboration",
|
|
6
6
|
"bugs": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"watch": "tsc -b --watch"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@jupyter/collaborative-drive": "^4.1.
|
|
44
|
+
"@jupyter/collaborative-drive": "^4.1.1",
|
|
45
45
|
"@jupyter/ydoc": "^2.1.3 || ^3.0.0",
|
|
46
46
|
"@jupyterlab/apputils": "^4.4.0",
|
|
47
47
|
"@jupyterlab/cells": "^4.4.0",
|