Skip to content

Commit

Permalink
stop using String.fromCharCode.apply in favor of Buffer.from to avoid…
Browse files Browse the repository at this point in the history
… errors
  • Loading branch information
marcj committed Oct 11, 2019
1 parent aff78e4 commit 32a229a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/exchange-prot.ts
Expand Up @@ -69,7 +69,7 @@ export function encodeMessage(messageId: number, type: string, arg: any, payload
}

export function uintToString(array: Uint8Array): string {
return String.fromCharCode.apply(null, array as any);
return Buffer.from(array).toString();
}

export function str2ab(str: string): ArrayBuffer {
Expand Down
4 changes: 0 additions & 4 deletions packages/server/src/exchange-server.ts
Expand Up @@ -34,14 +34,10 @@ export class ExchangeServer {
idleTimeout: 0,
/* Handlers */
open: (ws, req) => {
console.log('new exchange client');
},
message: async (ws, message: ArrayBuffer, isBinary) => {
this.onMessage(ws, message);
},
drain: (ws) => {
console.log('WebSocket exchange backpressure: ' + ws.getBufferedAmount());
},
close: (ws, code, message) => {
}
});
Expand Down
5 changes: 1 addition & 4 deletions packages/server/src/worker.ts
Expand Up @@ -53,12 +53,9 @@ export class Worker {
injectorMap.set(ws, this.mainInjector.resolveAndCreateChild(provider));
},
message: async (ws, message: ArrayBuffer, isBinary) => {
const json = String.fromCharCode.apply(null, new Uint8Array(message) as any);
const json = Buffer.from(message).toString();
await injectorMap.get(ws)!.get(ClientConnection).onMessage(json);
},
drain: (ws) => {
console.log('WebSocket backpressure: ' + ws.getBufferedAmount());
},
close: (ws, code, message) => {
injectorMap.get(ws)!.get(ClientConnection).destroy();
injectorMap.delete(ws);
Expand Down

0 comments on commit 32a229a

Please sign in to comment.