Skip to content

Commit

Permalink
Improve receive performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
vldr committed Jun 1, 2024
1 parent 3912398 commit 3afecab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/network/NetworkReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class NetworkReceiver {
private readonly leaveRoomCallback: () => void
) {
this.webSocket = new WebSocket(URI);
this.webSocket.binaryType = "arraybuffer";
this.webSocket.onopen = this.onOpen.bind(this);
this.webSocket.onclose = this.onClose.bind(this);
this.webSocket.onerror = this.onError.bind(this);
Expand Down Expand Up @@ -99,13 +100,12 @@ export class NetworkReceiver {
}

private async onMessage(event: MessageEvent) {
if (event.data instanceof Blob) {
const arrayBuffer = await event.data.arrayBuffer();
const data = new Uint8Array(arrayBuffer).slice(1);
if (event.data instanceof ArrayBuffer) {
const data = new Uint8Array(event.data).subarray(1);

if (this.sharedKey) {
const iv = data.slice(0, this.IV_SIZE);
const ciphertext = data.slice(this.IV_SIZE);
const iv = data.subarray(0, this.IV_SIZE);
const ciphertext = data.subarray(this.IV_SIZE);

try {
const plaintext = new Uint8Array(
Expand Down
10 changes: 5 additions & 5 deletions src/network/NetworkSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class NetworkSender {

public async init() {
this.webSocket = new WebSocket(this.URI);
this.webSocket.binaryType = "arraybuffer";
this.webSocket.onopen = this.onOpen.bind(this);
this.webSocket.onclose = this.onClose.bind(this);
this.webSocket.onerror = this.onError.bind(this);
Expand Down Expand Up @@ -60,13 +61,12 @@ export class NetworkSender {
}

private async onMessage(event: MessageEvent) {
if (event.data instanceof Blob) {
const arrayBuffer = await event.data.arrayBuffer();
const data = new Uint8Array(arrayBuffer).slice(1);
if (event.data instanceof ArrayBuffer) {
const data = new Uint8Array(event.data).subarray(1);

if (this.sharedKey) {
const iv = data.slice(0, this.IV_SIZE);
const ciphertext = data.slice(this.IV_SIZE);
const iv = data.subarray(0, this.IV_SIZE);
const ciphertext = data.subarray(this.IV_SIZE);

try {
const plaintext = new Uint8Array(
Expand Down

0 comments on commit 3afecab

Please sign in to comment.