@jupyter/docprovider 2.0.0-alpha.4 → 2.0.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/utils.d.ts +0 -9
- package/lib/utils.js +0 -10
- package/lib/yprovider.d.ts +0 -7
- package/lib/yprovider.js +6 -80
- package/package.json +4 -4
package/lib/utils.d.ts
CHANGED
package/lib/utils.js
CHANGED
|
@@ -4,15 +4,5 @@
|
|
|
4
4
|
|----------------------------------------------------------------------------*/
|
|
5
5
|
export var MessageType;
|
|
6
6
|
(function (MessageType) {
|
|
7
|
-
MessageType[MessageType["ROOM"] = 124] = "ROOM";
|
|
8
7
|
MessageType[MessageType["CHAT"] = 125] = "CHAT";
|
|
9
8
|
})(MessageType || (MessageType = {}));
|
|
10
|
-
export var RoomMessage;
|
|
11
|
-
(function (RoomMessage) {
|
|
12
|
-
RoomMessage[RoomMessage["RELOAD"] = 0] = "RELOAD";
|
|
13
|
-
RoomMessage[RoomMessage["OVERWRITE"] = 1] = "OVERWRITE";
|
|
14
|
-
RoomMessage[RoomMessage["FILE_CHANGED"] = 2] = "FILE_CHANGED";
|
|
15
|
-
RoomMessage[RoomMessage["FILE_OVERWRITTEN"] = 3] = "FILE_OVERWRITTEN";
|
|
16
|
-
RoomMessage[RoomMessage["DOC_OVERWRITTEN"] = 4] = "DOC_OVERWRITTEN";
|
|
17
|
-
RoomMessage[RoomMessage["SESSION_TOKEN"] = 5] = "SESSION_TOKEN";
|
|
18
|
-
})(RoomMessage || (RoomMessage = {}));
|
package/lib/yprovider.d.ts
CHANGED
|
@@ -40,18 +40,11 @@ export declare class WebSocketProvider implements IDocumentProvider {
|
|
|
40
40
|
private _onUserChanged;
|
|
41
41
|
private _onConnectionClosed;
|
|
42
42
|
private _onSync;
|
|
43
|
-
private _handleRoomMessage;
|
|
44
|
-
private _handleFileChanged;
|
|
45
|
-
private _handleSessionToken;
|
|
46
|
-
private _sendReloadMsg;
|
|
47
|
-
private _sendOverwriteMsg;
|
|
48
|
-
private _dialog;
|
|
49
43
|
private _awareness;
|
|
50
44
|
private _contentType;
|
|
51
45
|
private _format;
|
|
52
46
|
private _isDisposed;
|
|
53
47
|
private _path;
|
|
54
|
-
private _session;
|
|
55
48
|
private _ready;
|
|
56
49
|
private _serverUrl;
|
|
57
50
|
private _sharedModel;
|
package/lib/yprovider.js
CHANGED
|
@@ -5,12 +5,8 @@
|
|
|
5
5
|
import { showErrorMessage, Dialog } from '@jupyterlab/apputils';
|
|
6
6
|
import { PromiseDelegate } from '@lumino/coreutils';
|
|
7
7
|
import { Signal } from '@lumino/signaling';
|
|
8
|
-
import * as decoding from 'lib0/decoding';
|
|
9
|
-
import * as encoding from 'lib0/encoding';
|
|
10
|
-
import * as url from 'lib0/url';
|
|
11
8
|
import { WebsocketProvider as YWebsocketProvider } from 'y-websocket';
|
|
12
9
|
import { requestDocSession } from './requests';
|
|
13
|
-
import { MessageType, RoomMessage } from './utils';
|
|
14
10
|
/**
|
|
15
11
|
* A class to provide Yjs synchronization over WebSocket.
|
|
16
12
|
*
|
|
@@ -25,9 +21,9 @@ export class WebSocketProvider {
|
|
|
25
21
|
*/
|
|
26
22
|
constructor(options) {
|
|
27
23
|
this._onConnectionClosed = (event) => {
|
|
28
|
-
if (event.code
|
|
29
|
-
console.error('Document provider closed:', event.
|
|
30
|
-
showErrorMessage(this._trans.__('Document error'), event.reason, [
|
|
24
|
+
if (event.code === 1003) {
|
|
25
|
+
console.error('Document provider closed:', event.reason);
|
|
26
|
+
showErrorMessage(this._trans.__('Document session error'), event.reason, [
|
|
31
27
|
Dialog.okButton()
|
|
32
28
|
]);
|
|
33
29
|
// Dispose shared model immediately. Better break the document model,
|
|
@@ -42,11 +38,9 @@ export class WebSocketProvider {
|
|
|
42
38
|
(_a = this._yWebsocketProvider) === null || _a === void 0 ? void 0 : _a.off('sync', this._onSync);
|
|
43
39
|
}
|
|
44
40
|
};
|
|
45
|
-
this._dialog = null;
|
|
46
41
|
this._ready = new PromiseDelegate();
|
|
47
42
|
this._isDisposed = false;
|
|
48
43
|
this._path = options.path;
|
|
49
|
-
this._session = null;
|
|
50
44
|
this._contentType = options.contentType;
|
|
51
45
|
this._format = options.format;
|
|
52
46
|
this._serverUrl = options.url;
|
|
@@ -90,84 +84,16 @@ export class WebSocketProvider {
|
|
|
90
84
|
Signal.clearData(this);
|
|
91
85
|
}
|
|
92
86
|
async _connect() {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
? { sessionId: this._session.sessionId }
|
|
96
|
-
: undefined;
|
|
97
|
-
this._yWebsocketProvider = new YWebsocketProvider(this._serverUrl, `${this._session.format}:${this._session.type}:${this._session.fileId}`, this._sharedModel.ydoc, {
|
|
87
|
+
const session = await requestDocSession(this._format, this._contentType, this._path);
|
|
88
|
+
this._yWebsocketProvider = new YWebsocketProvider(this._serverUrl, `${session.format}:${session.type}:${session.fileId}`, this._sharedModel.ydoc, {
|
|
98
89
|
disableBc: true,
|
|
99
|
-
params,
|
|
90
|
+
params: { sessionId: session.sessionId },
|
|
100
91
|
awareness: this._awareness
|
|
101
92
|
});
|
|
102
93
|
this._yWebsocketProvider.on('sync', this._onSync);
|
|
103
94
|
this._yWebsocketProvider.on('connection-close', this._onConnectionClosed);
|
|
104
|
-
this._yWebsocketProvider.messageHandlers[MessageType.ROOM] = (encoder, decoder, provider, emitSynced, messageType) => {
|
|
105
|
-
const msgType = decoding.readVarUint(decoder);
|
|
106
|
-
const data = decoding.readVarString(decoder);
|
|
107
|
-
this._handleRoomMessage(msgType, data);
|
|
108
|
-
};
|
|
109
95
|
}
|
|
110
96
|
_onUserChanged(user) {
|
|
111
97
|
this._awareness.setLocalStateField('user', user.identity);
|
|
112
98
|
}
|
|
113
|
-
_handleRoomMessage(type, data) {
|
|
114
|
-
switch (type) {
|
|
115
|
-
case RoomMessage.FILE_CHANGED:
|
|
116
|
-
this._handleFileChanged(data);
|
|
117
|
-
break;
|
|
118
|
-
case RoomMessage.DOC_OVERWRITTEN:
|
|
119
|
-
case RoomMessage.FILE_OVERWRITTEN:
|
|
120
|
-
if (this._dialog) {
|
|
121
|
-
this._dialog.close();
|
|
122
|
-
this._dialog = null;
|
|
123
|
-
}
|
|
124
|
-
break;
|
|
125
|
-
case RoomMessage.SESSION_TOKEN:
|
|
126
|
-
this._handleSessionToken(data);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
_handleFileChanged(data) {
|
|
131
|
-
this._dialog = new Dialog({
|
|
132
|
-
title: this._trans.__('File changed'),
|
|
133
|
-
body: this._trans.__('Do you want to overwrite the file or reload it?'),
|
|
134
|
-
buttons: [
|
|
135
|
-
Dialog.okButton({ label: 'Reload' }),
|
|
136
|
-
Dialog.warnButton({ label: 'Overwrite' })
|
|
137
|
-
],
|
|
138
|
-
hasClose: false
|
|
139
|
-
});
|
|
140
|
-
this._dialog.launch().then(resp => {
|
|
141
|
-
if (resp.button.label === 'Reload') {
|
|
142
|
-
this._sendReloadMsg(data);
|
|
143
|
-
}
|
|
144
|
-
else if (resp.button.label === 'Overwrite') {
|
|
145
|
-
this._sendOverwriteMsg(data);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
_handleSessionToken(data) {
|
|
150
|
-
if (this._yWebsocketProvider && this._session) {
|
|
151
|
-
const room = `${this._session.format}:${this._session.type}:${this._session.fileId}`;
|
|
152
|
-
const encodedParams = url.encodeQueryParams({ sessionId: data });
|
|
153
|
-
this._yWebsocketProvider.url =
|
|
154
|
-
this._serverUrl + '/' + room + '?' + encodedParams;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
_sendReloadMsg(data) {
|
|
158
|
-
var _a;
|
|
159
|
-
const encoder = encoding.createEncoder();
|
|
160
|
-
encoding.writeVarUint(encoder, MessageType.ROOM);
|
|
161
|
-
encoding.writeVarUint(encoder, RoomMessage.RELOAD);
|
|
162
|
-
encoding.writeVarString(encoder, data);
|
|
163
|
-
(_a = this._yWebsocketProvider) === null || _a === void 0 ? void 0 : _a.ws.send(encoding.toUint8Array(encoder));
|
|
164
|
-
}
|
|
165
|
-
_sendOverwriteMsg(data) {
|
|
166
|
-
var _a;
|
|
167
|
-
const encoder = encoding.createEncoder();
|
|
168
|
-
encoding.writeVarUint(encoder, MessageType.ROOM);
|
|
169
|
-
encoding.writeVarUint(encoder, RoomMessage.OVERWRITE);
|
|
170
|
-
encoding.writeVarString(encoder, data);
|
|
171
|
-
(_a = this._yWebsocketProvider) === null || _a === void 0 ? void 0 : _a.ws.send(encoding.toUint8Array(encoder));
|
|
172
|
-
}
|
|
173
99
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter/docprovider",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "JupyterLab - Document Provider",
|
|
5
|
-
"homepage": "https://github.com/jupyterlab/
|
|
5
|
+
"homepage": "https://github.com/jupyterlab/jupyter-collaboration",
|
|
6
6
|
"bugs": {
|
|
7
|
-
"url": "https://github.com/jupyterlab/
|
|
7
|
+
"url": "https://github.com/jupyterlab/jupyter-collaboration/issues"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/jupyterlab/
|
|
11
|
+
"url": "https://github.com/jupyterlab/jupyter-collaboration.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "BSD-3-Clause",
|
|
14
14
|
"author": "Project Jupyter",
|