diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index c09459e..428b103 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -68,9 +68,12 @@ export const makeSocket = ({ const sendPromise = promisify(ws.send) /** send a raw buffer */ - const sendRawMessage = (data: Buffer | Uint8Array) => { + const sendRawMessage = async(data: Buffer | Uint8Array) => { + if(ws.readyState !== ws.OPEN) { + throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }) + } const bytes = noise.encodeFrame(data) - return sendPromise.call(ws, bytes) as Promise + await sendPromise.call(ws, bytes) as Promise } /** send a binary node */ const sendNode = (node: BinaryNode) => {