src/index.js
/**
 * Validate WebSocket connection state
 * @param {object} webSocket - WebSocket connection
 * @throws {Error} Throws an error if the websocket connection is not open.
 * @throws {TypeError} Throws a type error if the state of the websocket is undefined or unknown.
 * @returns {object} - WebSocket
 */
Validate WebSocket connection state
@param {object} webSocket - WebSocket connection
@throws {Error} Throws an error if the websocket connection is not open.
@throws {TypeError} Throws a type error if the state of the websocket is undefined or unknown.
@returns {object} - WebSocket
Validate WebSocket connection state @param { object } webSocket - WebSocket connection @throws { Error } Throws an error if the websocket connection is not open . @throws { TypeError } Throws a type error if the state of the websocket is undefined or unknown . @returns { object } - WebSocket
function ensureOpen(webSocket) {
    switch (webSocket.readyState) {
    case 0:
        throw Error("WebSocket connection is in the process of connecting");
    case 1:
        return webSocket;
    case 2:
        throw Error("WebSocket connection is in the process of closing");
    case 3:
        throw Error("WebSocket connection is closed");
    default:
        throw TypeError("WebSocket is in unknown state");
    }
}
function ensureOpen ( webSocket ) { switch ( webSocket . readyState ) { case 0 : throw Error ( "WebSocket connection is in the process of connecting" ) ; case 1 : return webSocket ; case 2 : throw Error ( "WebSocket connection is in the process of closing" ) ; case 3 : throw Error ( "WebSocket connection is closed" ) ; default : throw TypeError ( "WebSocket is in unknown state" ) ; } }
Validate WebSocket connection state
 @param {object} webSocket - WebSocket connection
 @throws {Error} Throws an error if the websocket connection is not open.
Validate WebSocket connection state @param { object } webSocket - WebSocket connection @throws { Error } Throws an error if the websocket connection is not open .