Skip to content

Commit dc546d1

Browse files
committed
handle binary data (e.g. compressed frames)
1 parent b18dd5a commit dc546d1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/json-rpc/upstream/server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function createUpstreamServer({
3333
maxConnections = DEFAULT_MAX_CONNECTIONS,
3434
retryDelay = DEFAULT_RETRY_DELAY_MS,
3535
}: UpstreamServerConfig): UpstreamServer {
36+
const decoder = new TextDecoder();
3637
const connection$ = new BehaviorSubject<WebSocket | null>(null);
3738
const unsubscribers = new Map<string, () => void>();
3839
const states = new Map<string, unknown>();
@@ -89,7 +90,9 @@ export function createUpstreamServer({
8990
};
9091

9192
ws.onmessage = ({ data }) => {
92-
queueMicrotask(() => handleMessage(data.toString()));
93+
queueMicrotask(() =>
94+
handleMessage(typeof data === "string" ? data : decoder.decode(data)),
95+
);
9396
};
9497

9598
ws.onclose = (event) => {

0 commit comments

Comments
 (0)