Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/docprovider/ydrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export class RtcContentProvider
if (typeof options.format !== 'string') {
return;
}


try {
const provider = new WebSocketProvider({
Expand Down
46 changes: 29 additions & 17 deletions src/docprovider/yprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,10 @@ export class WebSocketProvider implements IDocumentProvider {

private async _connect(): Promise<void> {
// Fetch file ID from the file ID service.
let resp = await requestAPI(
"api/fileid/index?path=" + this._path,
{
method: "POST"
}
)
const fileId = resp["id"];
const resp = await requestAPI(`api/fileid/index?path=${this._path}`, {
method: 'POST'
});
const fileId: string = resp['id'];

this._yWebsocketProvider = new YWebsocketProvider(
this._serverUrl,
Expand Down Expand Up @@ -131,18 +128,33 @@ export class WebSocketProvider implements IDocumentProvider {
this._awareness.setLocalStateField('user', user.identity);
}

/**
* Handles disconnections from the YRoom Websocket.
*
* TODO: handle disconnections more gracefully by reseting the YDoc to an
* empty state on disconnect. Unfortunately the shared model does not provide
* any methods for this, so we are just asking disconnected clients to
* refresh for now.
*
* TODO: distinguish between disconnects when server YDoc history is the same
* (i.e. SS1 + SS2 is sufficient), and when the history
* differs (client's YDoc has to be reset before SS1 + SS2).
*/
private _onConnectionClosed = (event: any): void => {
if (event.code === 1003) {
console.error('Document provider closed:', event.reason);

showErrorMessage(this._trans.__('Document session error'), event.reason, [
Dialog.okButton()
]);
// Log error to console for debugging
console.error('WebSocket connection was closed. Close event: ', event);

// Show dialog to tell user to refresh the page
showErrorMessage(
this._trans.__('Document session error'),
'Please refresh the browser tab.',
[Dialog.okButton()]
);

// Dispose shared model immediately. Better break the document model,
// than overriding data on disk.
this._sharedModel.dispose();
}
// Delete this client's YDoc by disposing of the shared model.
// This is the only way we know of to stop `y-websocket` from constantly
// attempting to re-connect.
this._sharedModel.dispose();
};

private _onSync = (isSynced: boolean) => {
Expand Down
Loading