Skip to content

Commit

Permalink
Update to latest version of the protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Jul 9, 2024
1 parent 9025f5c commit 38d180f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 76 deletions.
19 changes: 9 additions & 10 deletions packages/collaboration/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{
"name": "@theia/collaboration",
"version": "1.50.0",
"version": "1.51.0",
"description": "Theia - Collaboration Extension",
"dependencies": {
"@theia/core": "1.50.0",
"@theia/editor": "1.50.0",
"@theia/filesystem": "1.50.0",
"@theia/monaco": "1.50.0",
"@theia/core": "1.51.0",
"@theia/editor": "1.51.0",
"@theia/filesystem": "1.51.0",
"@theia/monaco": "1.51.0",
"@theia/monaco-editor-core": "1.83.101",
"@theia/workspace": "1.50.0",
"open-collaboration-protocol": "0.0.8",
"open-collaboration-rpc": "0.0.7",
"open-collaboration-yjs": "0.0.1",
"@theia/workspace": "1.51.0",
"open-collaboration-protocol": "0.0.11",
"open-collaboration-yjs": "0.0.4",
"socket.io-client": "^4.5.3",
"yjs": "^13.6.7",
"lib0": "^0.2.52",
Expand Down Expand Up @@ -50,7 +49,7 @@
"watch": "theiaext watch"
},
"devDependencies": {
"@theia/ext-scripts": "1.50.0"
"@theia/ext-scripts": "1.51.0"
},
"nyc": {
"extends": "../../configs/nyc.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
FileChange, FileDeleteOptions,
FileOverwriteOptions, FileSystemProviderCapabilities, FileType, Stat, WatchOptions, FileSystemProviderWithFileReadWriteCapability, FileWriteOptions
} from '@theia/filesystem/lib/common/files';
import { ProtocolBroadcastConnection, Workspace } from 'open-collaboration-protocol';
import { ProtocolBroadcastConnection, Workspace, Peer } from 'open-collaboration-protocol';

export namespace CollaborationURI {

Expand Down Expand Up @@ -55,7 +55,7 @@ export class CollaborationFileSystemProvider implements FileSystemProviderWithFi
}
}

constructor(readonly connection: ProtocolBroadcastConnection, readonly yjs: Y.Doc) {
constructor(readonly connection: ProtocolBroadcastConnection, readonly host: Peer, readonly yjs: Y.Doc) {
}

protected encoder = new TextEncoder();
Expand Down Expand Up @@ -95,20 +95,20 @@ export class CollaborationFileSystemProvider implements FileSystemProviderWithFi
return Disposable.NULL;
}
stat(resource: URI): Promise<Stat> {
return this.connection.fs.stat('', this.getHostPath(resource));
return this.connection.fs.stat(this.host.id, this.getHostPath(resource));
}
mkdir(resource: URI): Promise<void> {
return this.connection.fs.mkdir('', this.getHostPath(resource));
return this.connection.fs.mkdir(this.host.id, this.getHostPath(resource));
}
async readdir(resource: URI): Promise<[string, FileType][]> {
const record = await this.connection.fs.readdir('', this.getHostPath(resource));
const record = await this.connection.fs.readdir(this.host.id, this.getHostPath(resource));
return Object.entries(record);
}
delete(resource: URI, opts: FileDeleteOptions): Promise<void> {
return this.connection.fs.delete('', this.getHostPath(resource));
return this.connection.fs.delete(this.host.id, this.getHostPath(resource));
}
rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> {
return this.connection.fs.rename('', this.getHostPath(from), this.getHostPath(to));
return this.connection.fs.rename(this.host.id, this.getHostPath(from), this.getHostPath(to));
}

protected getHostPath(uri: URI): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import '../../src/browser/style/index.css';

import { Command, CommandContribution, CommandRegistry, MessageService, nls, Progress, QuickInputService, QuickPickItem } from '@theia/core';
import { inject, injectable, optional, postConstruct } from '@theia/core/shared/inversify';
import { ConnectionProvider } from 'open-collaboration-protocol';
import { JsonMessageEncoding, WebSocketTransportProvider } from 'open-collaboration-rpc';
import { ConnectionProvider, WebSocketTransportProvider } from 'open-collaboration-protocol';
import { WindowService } from '@theia/core/lib/browser/window/window-service';
import { CollaborationInstance, CollaborationInstanceFactory } from './collaboration-instance';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { CollaborationWorkspaceService } from './collaboration-workspace-service';
import { StatusBar, StatusBarAlignment, StatusBarEntry } from '@theia/core/lib/browser/status-bar';
import { codiconArray } from '@theia/core/lib/browser/widgets/widget';
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';

export const COLLABORATION_CATEGORY = 'Collaboration';

Expand All @@ -43,7 +43,7 @@ export const COLLABORATION_STATUS_BAR_ID = 'statusBar.collaboration';

export const COLLABORATION_AUTH_TOKEN = 'THEIA_COLLAB_AUTH_TOKEN';
export const COLLABORATION_SERVER_URL = 'COLLABORATION_SERVER_URL';
export const DEFAULT_COLLABORATION_SERVER_URL = 'https://api.open-collab.tools/';
export const DEFAULT_COLLABORATION_SERVER_URL = 'http://localhost:8100';

@injectable()
export class CollaborationFrontendContribution implements CommandContribution {
Expand Down Expand Up @@ -82,9 +82,9 @@ export class CollaborationFrontendContribution implements CommandContribution {
this.getCollaborationServerUrl().then(serverUrl => {
const authHandler = new ConnectionProvider({
url: serverUrl,
client: FrontendApplicationConfigProvider.get().applicationName,
fetch: window.fetch.bind(window),
opener: url => this.windowService.openNewWindow(url),
encodings: [JsonMessageEncoding],
transports: [WebSocketTransportProvider],
userToken: localStorage.getItem(COLLABORATION_AUTH_TOKEN) ?? undefined
});
Expand Down Expand Up @@ -256,7 +256,7 @@ export class CollaborationFrontendContribution implements CommandContribution {
localStorage.setItem(COLLABORATION_AUTH_TOKEN, roomClaim.loginToken);
}
this.currentInstance?.dispose();
const connection = await authHandler.connect(roomClaim.roomToken);
const connection = await authHandler.connect(roomClaim.roomToken, roomClaim.host);
this.currentInstance = this.collaborationInstanceFactory({
role: 'guest',
connection
Expand All @@ -265,7 +265,6 @@ export class CollaborationFrontendContribution implements CommandContribution {
this.setStatusBarEntryDefault();
});
this.setStatusBarEntryConnected(roomClaim.roomId);
await this.currentInstance.initialize();
} catch (err) {
joinRoomProgress?.cancel();
await this.messageService.error(nls.localize('theia/collaboration/failedJoin', 'Failed to join room: {0}', err.message));
Expand Down
66 changes: 30 additions & 36 deletions packages/collaboration/src/browser/collaboration-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,11 @@ export function createCollaborationInstanceContainer(parent: interfaces.Containe
return child;
}

export class CollaborationPeer implements types.Peer, Disposable {
id: string;
host: boolean;
name: string;
email?: string | undefined;
export class CollaborationPeer implements Disposable {
peer: types.Peer;

constructor(peer: types.Peer, protected disposable: Disposable) {
this.id = peer.id;
this.host = peer.host;
this.name = peer.name;
this.email = peer.email;
this.peer = peer;
}

dispose(): void {
Expand Down Expand Up @@ -160,7 +154,7 @@ export class CollaborationInstance implements Disposable {
}

get host(): types.Peer {
return Array.from(this.peers.values()).find(e => e.host)!;
return Array.from(this.peers.values()).find(e => e.peer.host)!.peer;
}

@postConstruct()
Expand Down Expand Up @@ -208,8 +202,23 @@ export class CollaborationInstance implements Disposable {
return undefined;
}
});
connection.room.onJoin((_, peer) => {
connection.room.onJoin(async (_, peer) => {
this.addPeer(peer);
if (this.isHost) {
const roots = await this.workspaceService.roots;
const data: types.InitData = {
protocol: types.VERSION,
host: await this.identity.promise,
guests: Array.from(this.peers.values()).map(e => e.peer),
capabilities: {},
permissions: this.permissions,
workspace: {
name: this.workspaceService.workspace?.name ?? nls.localize('theia/collaboration/collaboration', 'Collaboration'),
folders: roots.map(e => e.name)
}
};
connection.peer.init(peer.id, data);
}
});
connection.room.onLeave((_, peer) => {
this.peers.get(peer.id)?.dispose();
Expand All @@ -226,20 +235,8 @@ export class CollaborationInstance implements Disposable {
this.yjsAwareness.setLocalStateField('peer', peer.id);
this.identity.resolve(peer);
});
connection.peer.onInit(async () => {
const roots = await this.workspaceService.roots;
const response: types.InitResponse = {
protocol: '0.0.1',
host: await this.identity.promise,
guests: Array.from(this.peers.values()),
capabilities: {},
permissions: this.permissions,
workspace: {
name: this.workspaceService.workspace?.name ?? nls.localize('theia/collaboration/collaboration', 'Collaboration'),
folders: roots.map(e => e.name)
}
};
return response;
connection.peer.onInit(async (_, data) => {
await this.initialize(data);
});
}

Expand Down Expand Up @@ -298,7 +295,7 @@ export class CollaborationInstance implements Disposable {
if (uri) {
const content = await this.fileService.readFile(uri);
return {
content: Buffer.from(content.value.buffer).toString('base64')
content: content.value.buffer
};
} else {
throw new Error('Could find file: ' + path);
Expand Down Expand Up @@ -523,7 +520,7 @@ export class CollaborationInstance implements Disposable {
const path = this.utils.getProtocolPath(uri);
if (path) {
if (!this.isHost) {
this.options.connection.editor.open('', path);
this.options.connection.editor.open(this.host.id, path);
}
let currentSelection = widget.editor.selection;
// // Update presence information when the selection changes
Expand Down Expand Up @@ -587,19 +584,16 @@ export class CollaborationInstance implements Disposable {
&& a.end.character === b.end.character;
}

async initialize(): Promise<void> {
const response = await this.options.connection.peer.init('', {
protocol: '0.0.1'
});
this.permissions = response.permissions;
this.readonly = response.permissions.readonly;
for (const peer of [...response.guests, response.host]) {
async initialize(data: types.InitData): Promise<void> {
this.permissions = data.permissions;
this.readonly = data.permissions.readonly;
for (const peer of [...data.guests, data.host]) {
this.addPeer(peer);
}
this.fileSystem = new CollaborationFileSystemProvider(this.options.connection, this.yjs);
this.fileSystem = new CollaborationFileSystemProvider(this.options.connection, data.host, this.yjs);
this.fileSystem.readonly = this.readonly;
this.toDispose.push(this.fileService.registerProvider(CollaborationURI.scheme, this.fileSystem));
const workspaceDisposable = await this.workspaceService.setHostWorkspace(response.workspace, this.options.connection);
const workspaceDisposable = await this.workspaceService.setHostWorkspace(data.workspace, this.options.connection);
this.toDispose.push(workspaceDisposable);
}

Expand Down
41 changes: 24 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3370,7 +3370,7 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

base64-js@^1.3.1:
base64-js@^1.3.1, base64-js@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
Expand Down Expand Up @@ -5685,6 +5685,11 @@ fd-slicer@~1.1.0:
dependencies:
pend "~1.2.0"

fflate@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.8.2.tgz#fc8631f5347812ad6028bbe4a2308b2792aa1dea"
integrity sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==

figures@3.2.0, figures@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af"
Expand Down Expand Up @@ -9057,26 +9062,23 @@ onetime@^5.1.0, onetime@^5.1.2:
dependencies:
mimic-fn "^2.1.0"

open-collaboration-protocol@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/open-collaboration-protocol/-/open-collaboration-protocol-0.0.8.tgz#77222f0ef13f46f4ea0feadc1390df25a8901649"
integrity sha512-74c6C5VuumlVLXXXqeS/LTDE1wkTYp9IH1MnOfs+Y5GeROBTnniW+csVKB3BF0WFJvObwfzSRpI404HhWXJ1Hg==
open-collaboration-protocol@0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/open-collaboration-protocol/-/open-collaboration-protocol-0.0.11.tgz#a1becd5a4d7d92887235a566b5888ae2eecfcc69"
integrity sha512-yHFa6224+O1+r6qbg4r2DC31ltEXCm5MutoCA+JmsMKTQQXgvh/y29nmTkWrQiWES0SVSZNMRJtv8SSzXqpZng==
dependencies:
open-collaboration-rpc "0.0.7"

open-collaboration-rpc@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/open-collaboration-rpc/-/open-collaboration-rpc-0.0.7.tgz#39201d501ed0210a8dbb19410f684c733ae0309f"
integrity sha512-mSCEk1k8rRhN7hGUMKxheAJcoIbIBzuGQ+nZaSXkjnl3nyh4CkUA9d02wIe/jvVHNKpIfZGMmcdXmYQW7+y3Xg==
base64-js "^1.5.1"
fflate "^0.8.2"
msgpackr "^1.10.2"
semver "^7.6.2"

open-collaboration-yjs@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/open-collaboration-yjs/-/open-collaboration-yjs-0.0.1.tgz#68f302dceed747712942da815408c19c5797ec04"
integrity sha512-auKIMVXAcbPjTBPq67ApM4O1lNT+5DH7TALonbQ1lT7UmyKcvVAgYTz9XSIjpN96QF0iicurltFstDfByNMwbQ==
open-collaboration-yjs@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/open-collaboration-yjs/-/open-collaboration-yjs-0.0.4.tgz#2f88c958320d2460597b4bbd1230a7167e384d71"
integrity sha512-KO6NfaYOp7ilPtMOfxCsVsz3tSTiOam73VaY1U6vb3Z9p81HBRwJPP08m2vwb0oCOagRcTDWmOf5w1dyaq+lhA==
dependencies:
lib0 "^0.2.94"
open-collaboration-protocol "0.0.8"
open-collaboration-rpc "0.0.7"
open-collaboration-protocol "0.0.11"
y-protocols "^1.0.6"

open@^7.4.2:
Expand Down Expand Up @@ -10537,6 +10539,11 @@ semver@^7.0.0, semver@^7.1.1, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semve
dependencies:
lru-cache "^6.0.0"

semver@^7.6.2:
version "7.6.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13"
integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==

send@0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be"
Expand Down

0 comments on commit 38d180f

Please sign in to comment.