1.0.5 • Published 2 years ago
@mr-mahawar/lib-ws-web v1.0.5
Web Socket Library for Web
Simple wrapper to maintain Web Socket connection made in TypeScript. In development ⚙️
Install
npm i @mr-mahawar/lib-ws-web
Usage
import { createWebScoket } from '@mr-mahawar/lib-ws-web';
const done = createWebScoket(
WS_URL,
{
onOpen: yourOnOpenListener,
onMessage: yourOnMessageListener,
onClose: yourOnCloseListener,
onError: yourOnErrorListener
}
);
In your listeners you will receive the web-socket event directly. These are all optional.
For sending any message or closing the web-socket connection we have these functions that we can import: import { sendMessage, closeConnection } from '@mr-mahawar/lib-ws-web';
sendMessage('Your message!'); //Accepts string | ArrayBufferLike | Blob | ArrayBufferView
closeConnection(); //This will close the connection