Skip to content
Open
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
13 changes: 8 additions & 5 deletions src/api/socketio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class SocketIOAPI {
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => {
reject('timeout');
}, 5000);
}, 15000);
});
const waitPromise = new Promise((resolve, reject) => {
this.socket.emit(event, ...args, (err:any, ...data:any[]) => {
Expand Down Expand Up @@ -144,7 +144,7 @@ export class SocketIOAPI {
console.log('SocketIOAPI: connectionRejected.', err.message);
});
this.socket.on('error', (err:any) => {
throw new Error(err);
console.error('SocketIOAPI error:', err);
});

if (this.scheme==='v2') {
Expand Down Expand Up @@ -230,7 +230,10 @@ export class SocketIOAPI {
this.socket.on('connectionAccepted', (_:any, publicId:any) => {
handler(publicId);
});
EventBus.on('socketioConnectedEvent', (arg:{publicId:string}) => {
if (this._busConnAcceptedDisposable) {
this._busConnAcceptedDisposable.dispose();
}
this._busConnAcceptedDisposable = EventBus.on('socketioConnectedEvent', (arg:{publicId:string}) => {
handler(arg.publicId);
});
break;
Expand Down Expand Up @@ -292,7 +295,7 @@ export class SocketIOAPI {
const timeoutPromise: Promise<ProjectEntity> = new Promise((_, reject) => {
setTimeout(() => {
reject('timeout');
}, 5000);
}, 15000);
});

switch(this.scheme) {
Expand All @@ -305,7 +308,7 @@ export class SocketIOAPI {
return project;
});
const rejectPromise = new Promise((_, reject) => {
this.socket.on('connectionRejected', (err:any) => {
this.socket.once('connectionRejected', (err:any) => {
this.scheme = 'v2';
reject(err.message);
});
Expand Down
20 changes: 15 additions & 5 deletions src/collaboration/clientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ export class ClientManager {
private readonly status: vscode.StatusBarItem;
private readonly onlineUsers: {[K:string]:ExtendedUpdateUserSchema} = {};
private connectedFlag: boolean = true;
private _handlers: any;
private readonly chatViewer: ChatViewProvider;

constructor(
private readonly vfs: VirtualFileSystem,
private readonly context: vscode.ExtensionContext,
private readonly publicId: string,
private readonly socket: SocketIOAPI,
private publicId: string,
private socket: SocketIOAPI,
) {
this.socket.updateEventHandlers({
this._handlers = {
onClientUpdated: (user:UpdateUserSchema) => {
if (user.id !== this.publicId) { this.setStatusActive(user.id); }
this.updatePosition(user.id, user.doc_id, user.row, user.column, user);
Expand All @@ -80,7 +81,8 @@ export class ClientManager {
onConnectionAccepted: (publicId:string) => {
this.connectedFlag = true;
}
});
};
this.socket.updateEventHandlers(this._handlers);
this.socket.getConnectedUsers().then(users => {
users.forEach(user => {
const onlineUser = {
Expand All @@ -105,6 +107,14 @@ export class ClientManager {
this.updateStatus();
}

reconnect() {
this.socket = this.vfs.socket;
this.publicId = this.vfs.publicId || '';
this.socket.updateEventHandlers(this._handlers);
this.connectedFlag = true;
this.onlineUsers = {};
}

private async jumpToUser(id?: string) {
if (id === undefined) {
const onlineUsers = Object.values(this.onlineUsers);
Expand Down Expand Up @@ -248,7 +258,7 @@ export class ClientManager {
this.status.tooltip = `${ELEGANT_NAME}: ${vscode.l10n.t('Not connected')}`;
// Kick out all users indication since the connection is lost
Object.keys(this.onlineUsers).forEach(clientId => {
this.removePosition(clientId);
try { this.removePosition(clientId); } catch (e) { /* vfs may be reconnecting */ }
});
break;
case true:
Expand Down
16 changes: 5 additions & 11 deletions src/core/remoteFileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,17 @@ export class VirtualFileSystem extends vscode.Disposable {
this.root = project;
const activeCondition = (vscode.workspace.workspaceFolders===undefined) || (vscode.workspace.workspaceFolders?.[0].uri.scheme!==ROOT_NAME) || (vscode.workspace.workspaceFolders?.[0].uri===this.origin);
// Register: [collaboration] ClientManager on Statusbar
if (activeCondition) {
if (this.clientManagerItem?.triggers) {
this.clientManagerItem.triggers.forEach((trigger) => trigger.dispose());
delete this.clientManagerItem;
}
if (activeCondition && !this.clientManagerItem) {
const clientManager = new ClientManager(this, this.context, this.publicId||'', this.socket);
this.clientManagerItem = {
manager: clientManager,
triggers: clientManager.triggers,
};
} else if (activeCondition && this.clientManagerItem) {
this.clientManagerItem.manager.reconnect();
}
// Register: [scm] SCMCollectionProvider in explorer
if (activeCondition) {
if (this.scmCollectionItem?.triggers) {
this.scmCollectionItem.triggers.forEach((trigger) => trigger.dispose());
delete this.scmCollectionItem;
}
if (activeCondition && !this.scmCollectionItem) {
const scmCollection = new SCMCollectionProvider(this, this.context);
this.scmCollectionItem = {
collection: scmCollection,
Expand Down Expand Up @@ -282,7 +276,7 @@ export class VirtualFileSystem extends vscode.Disposable {
parentFolder: FolderEntity, fileEntity: FileEntity, fileType:FileType, path:string
} | undefined {
if (!this.root) {
throw vscode.FileSystemError.FileNotFound();
return undefined;
}
root = root || this.root.rootFolder[0];
path = path || '/';
Expand Down