A cross platform websocket (client). Supports browser and node environments.
yarn add git+https://github.com/SeedV/cross-platform-websocket.git#<branch|tag>
Note: Browser does not support the options parameter.
const ws = new WebSocket('key', 'ws://localhost:8888/ws');
ws.onopen = key => console.warn(key, 'ws open');
ws.onmessage = (key, data) => console.warn(key, 'ws message', data);
ws.onclose = key => console.warn(key, 'ws close');
const ws = new WebSocket(
'key',
'ws://localhost:8888/ws',
undefined,
{headers: {['Authorization']: 'token'}}
);
ws.onopen = key => console.warn(key, 'ws open');
ws.onmessage = (key, data) => console.warn(key, 'ws message', data);
ws.onclose = key => console.warn(key, 'ws close');