From 3d465b504634c912a9b1c7ff3ef5d810dc09bf6c Mon Sep 17 00:00:00 2001 From: Dipanshu Gupta Date: Fri, 11 Oct 2024 16:51:19 +0530 Subject: [PATCH] Type added for BufferLike data --- backend/src/routes/wss/k8s/index.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/src/routes/wss/k8s/index.ts b/backend/src/routes/wss/k8s/index.ts index 0830239d71..622c7ed718 100644 --- a/backend/src/routes/wss/k8s/index.ts +++ b/backend/src/routes/wss/k8s/index.ts @@ -34,6 +34,24 @@ const waitConnection = (socket: WebSocket, write: () => void) => { } }; +type BufferLike = + | string + | Buffer + | DataView + | number + | ArrayBufferView + | Uint8Array + | ArrayBuffer + | SharedArrayBuffer + | readonly any[] + | readonly number[] + | { valueOf(): ArrayBuffer } + | { valueOf(): SharedArrayBuffer } + | { valueOf(): Uint8Array } + | { valueOf(): readonly number[] } + | { valueOf(): string } + | { [Symbol.toPrimitive](hint: string): string }; + export default async (fastify: KubeFastifyInstance): Promise => { fastify.get( '/*', @@ -85,7 +103,7 @@ export default async (fastify: KubeFastifyInstance): Promise => { ); // attach source socket listeners and forward requests to the target - source.on('message', (data: unknown, binary: boolean) => + source.on('message', (data: BufferLike, binary: boolean) => waitConnection(target, () => target.send(data, { binary })), ); source.on('ping', (data) => waitConnection(target, () => target.ping(data))); @@ -95,7 +113,7 @@ export default async (fastify: KubeFastifyInstance): Promise => { target.on('unexpected-response', onUnexpectedResponse); // attach target socket listeners and forward requests to the source - target.on('message', (data: unknown, binary: boolean) => source.send(data, { binary })); + target.on('message', (data: BufferLike, binary: boolean) => source.send(data, { binary })); target.on('ping', (data) => source.ping(data)); target.on('pong', (data) => source.pong(data)); target.on('close', close);