Skip to content

Commit

Permalink
fix resizing buffer on .sendBytes(). bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Feb 19, 2025
1 parent d3b62b0 commit 1704a98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "colyseus.js",
"version": "0.16.1",
"version": "0.16.2",
"description": "Colyseus Multiplayer SDK for JavaScript/TypeScript",
"author": "Endel Dreyer",
"license": "MIT",
Expand Down
8 changes: 8 additions & 0 deletions src/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ export class Room<State= any> {
encode.number(this.packr.buffer, type, it);
}

// check if buffer needs to be resized
// TODO: can we avoid this?
if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {
const newBuffer = new Uint8Array(it.offset + bytes.byteLength);
newBuffer.set(this.packr.buffer);
this.packr.useBuffer(newBuffer);
}

this.packr.buffer.set(bytes, it.offset);
this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));
}
Expand Down

0 comments on commit 1704a98

Please sign in to comment.