@@ -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