Skip to content

Commit 49951ba

Browse files
committed
apply reviewer suggestions
1 parent 8941b2b commit 49951ba

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

packages/data-connect/src/network/stream/websocket.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ export class WebSocketTransport extends AbstractDataConnectStreamTransport {
9090
);
9191
}
9292

93+
/** Decodes binary WebSocket responses to strings */
94+
private decoder: TextDecoder | undefined = undefined;
95+
96+
/**
97+
* Decodes a WebSocket response from a Uint8Array to a JSON object.
98+
* Emulator does not send messages as Uint8Arrays, but prod does.
99+
*/
100+
private decodeBinaryResponse(data: ArrayBuffer): string {
101+
if (!this.decoder) {
102+
this.decoder = new TextDecoder('utf-8');
103+
}
104+
return this.decoder.decode(data);
105+
}
106+
93107
/** The current connection to the server. Undefined if disconnected. */
94108
private connection: WebSocket | undefined = undefined;
95109

@@ -141,10 +155,7 @@ export class WebSocketTransport extends AbstractDataConnectStreamTransport {
141155
}
142156
const ws = new connectWebSocket(this.endpointUrl);
143157
this.connection = ws;
144-
if (!this._isUsingEmulator) {
145-
// emulator sends messages as JSON strings, prod sends as binary
146-
this.connection!.binaryType = 'arraybuffer';
147-
}
158+
this.connection!.binaryType = 'arraybuffer';
148159
ws.onopen = () => {
149160
this.onConnectionReady();
150161
resolve();
@@ -313,14 +324,4 @@ export class WebSocketTransport extends AbstractDataConnectStreamTransport {
313324
}
314325
return result as DataConnectStreamResponse<Data>;
315326
}
316-
317-
/**
318-
* Decodes a WebSocket response from a Uint8Array to a JSON object. Emulator does not
319-
* send messages as Uint8Arrays, but prod does.
320-
*/
321-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
322-
private decodeBinaryResponse(data: Uint8Array): any {
323-
const decoder = new TextDecoder('utf-8');
324-
return decoder.decode(data);
325-
}
326327
}

0 commit comments

Comments
 (0)