0.12.0 • Published 4 years ago
ataraxia-ws-client v0.12.0
ataraxia-ws-client
Client that connects to a Ataraxia network
using a websocket. This module makes it possible for NodeJS-instances (using
ws) and browsers to connect to a network running websocket server.
Installation
npm install ataraxia-ws-clientUsage
import { Network, AnonymousAuth } from 'ataraxia';
import { WebSocketClientTransport } from 'ataraxia-ws-client';
// Setup a network with a WebSocket client
const net = new Network({
name: 'name-of-your-app-or-network',
transports: [
new WebSocketClientTransport({
// URL to the websocket on the server
url: 'ws://localhost:7000',
// If using outside a browser, define how a WebSocket is created
factory: url => new WebSocket(url),
// Use anonymous authentication
authentication: [
new AnonymousAuth()
]
})
]
});
await net.join();API
new WebSocketClientTransport(options)Create a new instance of this transport.
optionsurl: string, the URL to connect to, this will be where aWebSocketServerTransportis running.factory?: (url) => WebSocket, factory used to create aWebSocketinstance, used to support running both in a browser and in Node via libraries such asws.authentication: AuthProvider[], array containing all of the authentication methods supported.