Skip to content

Commit

Permalink
fix lag in ff on websocket connection, e.g., when switching terminals…
Browse files Browse the repository at this point in the history
… and also to start collab and languageClient in editor
  • Loading branch information
srieger1 committed Jul 7, 2024
1 parent e6f64e4 commit 615b1d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
37 changes: 23 additions & 14 deletions frontend/src/components/FileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,19 @@ export default class FileEditor extends Component<FileEditorProps> {
}

const collaborationId = fileName + "-group" + group;
console.log(
"Starting collaboration for user: " +
this.username +
" in group: " +
group +
" on: " +
collaborationId,
);

// Avoid console.log in production code while opening websockets, as Firefox otherwise
// will will wait a long time before opening the connection, e.g., when switching terminals
// or files in the editor (y-websocket and/or monaco-languageclient)

// console.log(
// "Starting collaboration for user: " +
// this.username +
// " in group: " +
// group +
// " on: " +
// collaborationId,
// );

const doc = new Y.Doc();

Expand Down Expand Up @@ -422,7 +427,7 @@ export default class FileEditor extends Component<FileEditorProps> {
red.toString(16).padStart(2, "0") +
green.toString(16).padStart(2, "0") +
blue.toString(16).padStart(2, "0");
console.log("my color: " + hexColor);
//console.log("my color: " + hexColor);

awareness.on(
"update",
Expand Down Expand Up @@ -506,7 +511,7 @@ export default class FileEditor extends Component<FileEditorProps> {
//});
},
);
console.log("my client id: " + awareness.clientID);
//console.log("my client id: " + awareness.clientID);
awareness.setLocalStateField("user", {
name: username,
color: hexColor,
Expand Down Expand Up @@ -541,7 +546,7 @@ export default class FileEditor extends Component<FileEditorProps> {
return;
}
this.binding?.destroy();
// WebRTC provider problem is room is taken, cannot be joined/created again
// WebRTC provider problem if room is taken, cannot be joined/created again
//this.collaborationProvider?.room?.destroy();
this.collaborationProvider?.disconnect();
}
Expand All @@ -562,7 +567,11 @@ export default class FileEditor extends Component<FileEditorProps> {
}

if (lspLanguage !== "") {
console.log("Starting language client for language: " + lspLanguage);
// Avoid console.log in production code while opening websockets, as Firefox otherwise
// will will wait a long time before opening the connection, e.g., when switching terminals
// or files in the editor (y-websocket and/or monaco-languageclient)

//console.log("Starting language client for language: " + lspLanguage);

this.languageClientWebSocket = createWebSocket(
"/environment/" +
Expand All @@ -589,7 +598,7 @@ export default class FileEditor extends Component<FileEditorProps> {
this.languageClientWebSocket.onmessage = (e) => {
if (e.data === "backend websocket ready") {
// restore onmessage fn
console.log("backend websocket ready, starting language client");
//console.log("backend websocket ready, starting language client");
//this.languageClientWebSocket.onmessage = (e) => {
//console.log("received message from backend: " + e.data);
//if (e.data === "pong") {
Expand Down Expand Up @@ -661,7 +670,7 @@ export default class FileEditor extends Component<FileEditorProps> {
// if languageClient connection was closed, this.languageClient will be undefined
void this.languageClient?.dispose();
clearInterval(this.languageClientWSTimerId);
//this.languageClientWebSocket.close()
this.languageClientWebSocket.close()
}

findCommonPathPrefix(strings: string[]): string {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/Environment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class EnvironmentView extends Component<PropsType, StateType> {
providerInstanceStatus: "",
rootPath: "",
workspaceFolders: [],
useCollaboration: true,
useLanguageClient: true,
useCollaboration: false,
useLanguageClient: false,
};
this.restartEnvironment = this.restartEnvironment.bind(this);
this.storeTerminalState = this.storeTerminalState.bind(this);
Expand Down

0 comments on commit 615b1d4

Please sign in to comment.