Skip to content

Commit d1d1140

Browse files
Wait for the document to be synced (#148)
* Wait for the document to be synced * Automatic application of license header --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1cb07c8 commit d1d1140

File tree

13 files changed

+81
-23
lines changed

13 files changed

+81
-23
lines changed

docs/source/developer/contributing.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.. Copyright (c) Jupyter Development Team.
2+
.. Distributed under the terms of the Modified BSD License.
3+
14
Developer documentation
25
=======================
36

jupyter_collaboration/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
14
from typing import Any, Dict, List
25

36
from ._version import __version__ # noqa

jupyter_collaboration/loaders.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
14
from __future__ import annotations
25

36
import asyncio

jupyter_collaboration/rooms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
14
from __future__ import annotations
25

36
import asyncio

jupyter_collaboration/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
14
import pathlib
25
from enum import Enum
36
from typing import Tuple

packages/collaboration-extension/src/filebrowser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright (c) Jupyter Development Team.
3+
* Distributed under the terms of the Modified BSD License.
4+
*/
5+
16
import {
27
ILabShell,
38
IRouter,

packages/docprovider/src/requests.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,25 @@ import { ServerConnection, Contents } from '@jupyterlab/services';
1212
*/
1313
const DOC_SESSION_URL = 'api/collaboration/session';
1414

15+
/**
16+
* Document session model
17+
*/
1518
export interface ISessionModel {
19+
/**
20+
* Document format; 'text', 'base64',...
21+
*/
1622
format: Contents.FileFormat;
23+
/**
24+
* Document type
25+
*/
1726
type: Contents.ContentType;
27+
/**
28+
* File unique identifier
29+
*/
1830
fileId: string;
31+
/**
32+
* Server session identifier
33+
*/
1934
sessionId: string;
2035
}
2136

packages/docprovider/src/yprovider.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { DocumentChange, YDocument } from '@jupyter/ydoc';
1616
import { Awareness } from 'y-protocols/awareness';
1717
import { WebsocketProvider as YWebsocketProvider } from 'y-websocket';
1818

19-
import { ISessionModel, requestDocSession } from './requests';
19+
import { requestDocSession } from './requests';
2020

2121
/**
2222
* An interface for a document provider.
@@ -60,7 +60,7 @@ export class WebSocketProvider implements IDocumentProvider {
6060
.catch(e => console.error(e));
6161
user.userChanged.connect(this._onUserChanged, this);
6262

63-
this._connect();
63+
this._connect().catch(e => console.warn(e));
6464
}
6565

6666
/**
@@ -86,31 +86,31 @@ export class WebSocketProvider implements IDocumentProvider {
8686
}
8787
this._isDisposed = true;
8888
this._yWebsocketProvider?.off('connection-close', this._onConnectionClosed);
89+
this._yWebsocketProvider?.off('sync', this._onSync);
8990
this._yWebsocketProvider?.destroy();
9091
Signal.clearData(this);
9192
}
9293

93-
private _connect(): void {
94-
requestDocSession(this._format, this._contentType, this._path)
95-
.then((session: ISessionModel) => {
96-
this._yWebsocketProvider = new YWebsocketProvider(
97-
this._serverUrl,
98-
`${session.format}:${session.type}:${session.fileId}`,
99-
this._sharedModel.ydoc,
100-
{
101-
disableBc: true,
102-
params: { sessionId: session.sessionId },
103-
awareness: this._awareness
104-
}
105-
);
106-
107-
this._yWebsocketProvider.on(
108-
'connection-close',
109-
this._onConnectionClosed
110-
);
111-
})
112-
.then(r => this._ready.resolve())
113-
.catch(e => console.warn(e));
94+
private async _connect(): Promise<void> {
95+
const session = await requestDocSession(
96+
this._format,
97+
this._contentType,
98+
this._path
99+
);
100+
101+
this._yWebsocketProvider = new YWebsocketProvider(
102+
this._serverUrl,
103+
`${session.format}:${session.type}:${session.fileId}`,
104+
this._sharedModel.ydoc,
105+
{
106+
disableBc: true,
107+
params: { sessionId: session.sessionId },
108+
awareness: this._awareness
109+
}
110+
);
111+
112+
this._yWebsocketProvider.on('sync', this._onSync);
113+
this._yWebsocketProvider.on('connection-close', this._onConnectionClosed);
114114
}
115115

116116
private _onUserChanged(user: User.IManager): void {
@@ -141,6 +141,14 @@ export class WebSocketProvider implements IDocumentProvider {
141141
}
142142
};
143143

144+
private _onSync = (isSynced: boolean) => {
145+
console.log(`_onSync ${isSynced}`);
146+
if (isSynced) {
147+
this._ready.resolve();
148+
this._yWebsocketProvider?.off('sync', this._onSync);
149+
}
150+
};
151+
144152
private _awareness: Awareness;
145153
private _contentType: string;
146154
private _format: string;

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
14
[build-system]
25
build-backend = "hatchling.build"
36
requires = ["hatchling>=1.4.0", "hatch-nodejs-version", "jupyterlab>=4.0.0rc0"]

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
14
# setup.py shim for use with applications that require it.
25
__import__("setuptools").setup()

0 commit comments

Comments
 (0)