tin-can, a simple websocket server and client wrapper
tin-can is a simple wrapper around 'ws'
, exposing a simple API to get started on websocket apps quickly.
Probably wouldn't use it for production.
Since the 'ws'
package does not support the browser, tin-can
shims it and uses the windows WebSocket
if you use this in a browser. That means you can use the client module in either node
or the browser! (works with webpack)
usage
server
const Server = ;const wsServer = ;wsServer; wsServer
aysnc/await
)
client (with const WebSocketClient = Client; const client = ; { await client; // Send a plain event down the pipe to the server. socket; // Wait for callback const handshakeResult = await client; console; // { auth: true }} ;
Promises
)
client (with const WebSocketClient = Client; const client = ;client;
usage with webpack
Note: if using webpack
, make sure to shim out the ws
module by adding it to your externals
const path = ; moduleexports = entry: './client.js' output: path: path filename: 'bundle.js' externals: ws: "{}" ;