Skip to content

Commit

Permalink
Fixes sending long messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hbcarlos committed Jul 19, 2023
1 parent 1d1a61c commit 3a4b86e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion jupyter_collaboration/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ async def on_message(self, message):

if message_type == MessageType.CHAT:
user = self.current_user
msg = message[2:].decode("utf-8")

# The fist bytes are the length of the message
pos = 1
while message[pos] >= 128:
pos += 1
pos += 1
msg = message[pos:].decode("utf-8")

data = json.loads(msg)
data["sender"] = user.username
Expand Down
5 changes: 4 additions & 1 deletion packages/collaboration-extension/src/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
EditorExtensionRegistry,
IEditorExtensionRegistry
} from '@jupyterlab/codemirror';
import { IAwarenessProvider, WebSocketAwarenessProvider } from '@jupyter/docprovider';
import {
IAwarenessProvider,
WebSocketAwarenessProvider
} from '@jupyter/docprovider';
import { SidePanel, usersIcon } from '@jupyterlab/ui-components';
import { URLExt } from '@jupyterlab/coreutils';
import { ServerConnection } from '@jupyterlab/services';
Expand Down
4 changes: 2 additions & 2 deletions packages/docprovider/src/awareness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ export class WebSocketAwarenessProvider
body: msg
}
};

const encoder = encoding.createEncoder();
encoding.writeVarUint(encoder, MessageType.CHAT);
encoding.writeVarString(encoder, JSON.stringify(message));
this.ws!.send(encoding.toUint8Array(encoder));
const data = encoding.toUint8Array(encoder);
this.ws!.send(data);

return { ...message, sender: this._user };
}
Expand Down

0 comments on commit 3a4b86e

Please sign in to comment.