@jupyter/docprovider 2.0.0-alpha.2 → 2.0.0-alpha.4
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 +2 -1
- package/lib/utils.js +1 -0
- package/lib/yprovider.d.ts +2 -0
- package/lib/yprovider.js +19 -4
- package/package.json +1 -1
package/lib/utils.d.ts
CHANGED
package/lib/utils.js
CHANGED
|
@@ -14,4 +14,5 @@ export var RoomMessage;
|
|
|
14
14
|
RoomMessage[RoomMessage["FILE_CHANGED"] = 2] = "FILE_CHANGED";
|
|
15
15
|
RoomMessage[RoomMessage["FILE_OVERWRITTEN"] = 3] = "FILE_OVERWRITTEN";
|
|
16
16
|
RoomMessage[RoomMessage["DOC_OVERWRITTEN"] = 4] = "DOC_OVERWRITTEN";
|
|
17
|
+
RoomMessage[RoomMessage["SESSION_TOKEN"] = 5] = "SESSION_TOKEN";
|
|
17
18
|
})(RoomMessage || (RoomMessage = {}));
|
package/lib/yprovider.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare class WebSocketProvider implements IDocumentProvider {
|
|
|
42
42
|
private _onSync;
|
|
43
43
|
private _handleRoomMessage;
|
|
44
44
|
private _handleFileChanged;
|
|
45
|
+
private _handleSessionToken;
|
|
45
46
|
private _sendReloadMsg;
|
|
46
47
|
private _sendOverwriteMsg;
|
|
47
48
|
private _dialog;
|
|
@@ -50,6 +51,7 @@ export declare class WebSocketProvider implements IDocumentProvider {
|
|
|
50
51
|
private _format;
|
|
51
52
|
private _isDisposed;
|
|
52
53
|
private _path;
|
|
54
|
+
private _session;
|
|
53
55
|
private _ready;
|
|
54
56
|
private _serverUrl;
|
|
55
57
|
private _sharedModel;
|
package/lib/yprovider.js
CHANGED
|
@@ -7,6 +7,7 @@ import { PromiseDelegate } from '@lumino/coreutils';
|
|
|
7
7
|
import { Signal } from '@lumino/signaling';
|
|
8
8
|
import * as decoding from 'lib0/decoding';
|
|
9
9
|
import * as encoding from 'lib0/encoding';
|
|
10
|
+
import * as url from 'lib0/url';
|
|
10
11
|
import { WebsocketProvider as YWebsocketProvider } from 'y-websocket';
|
|
11
12
|
import { requestDocSession } from './requests';
|
|
12
13
|
import { MessageType, RoomMessage } from './utils';
|
|
@@ -24,7 +25,7 @@ export class WebSocketProvider {
|
|
|
24
25
|
*/
|
|
25
26
|
constructor(options) {
|
|
26
27
|
this._onConnectionClosed = (event) => {
|
|
27
|
-
if (event.code >=
|
|
28
|
+
if (event.code >= 4000 && event.code < 4005) {
|
|
28
29
|
console.error('Document provider closed:', event.code, event.reason);
|
|
29
30
|
showErrorMessage(this._trans.__('Document error'), event.reason, [
|
|
30
31
|
Dialog.okButton()
|
|
@@ -45,6 +46,7 @@ export class WebSocketProvider {
|
|
|
45
46
|
this._ready = new PromiseDelegate();
|
|
46
47
|
this._isDisposed = false;
|
|
47
48
|
this._path = options.path;
|
|
49
|
+
this._session = null;
|
|
48
50
|
this._contentType = options.contentType;
|
|
49
51
|
this._format = options.format;
|
|
50
52
|
this._serverUrl = options.url;
|
|
@@ -88,9 +90,11 @@ export class WebSocketProvider {
|
|
|
88
90
|
Signal.clearData(this);
|
|
89
91
|
}
|
|
90
92
|
async _connect() {
|
|
91
|
-
|
|
92
|
-
const params =
|
|
93
|
-
|
|
93
|
+
this._session = await requestDocSession(this._format, this._contentType, this._path);
|
|
94
|
+
const params = this._session.sessionId !== null
|
|
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, {
|
|
94
98
|
disableBc: true,
|
|
95
99
|
params,
|
|
96
100
|
awareness: this._awareness
|
|
@@ -118,6 +122,9 @@ export class WebSocketProvider {
|
|
|
118
122
|
this._dialog = null;
|
|
119
123
|
}
|
|
120
124
|
break;
|
|
125
|
+
case RoomMessage.SESSION_TOKEN:
|
|
126
|
+
this._handleSessionToken(data);
|
|
127
|
+
break;
|
|
121
128
|
}
|
|
122
129
|
}
|
|
123
130
|
_handleFileChanged(data) {
|
|
@@ -139,6 +146,14 @@ export class WebSocketProvider {
|
|
|
139
146
|
}
|
|
140
147
|
});
|
|
141
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
|
+
}
|
|
142
157
|
_sendReloadMsg(data) {
|
|
143
158
|
var _a;
|
|
144
159
|
const encoder = encoding.createEncoder();
|