ataraxia-ws-client
v0.12.0
Published
WebSocket client for Ataraxia P2P messaging
Downloads
17
Readme
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-client
Usage
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.
options
url: string
, the URL to connect to, this will be where aWebSocketServerTransport
is running.factory?: (url) => WebSocket
, factory used to create aWebSocket
instance, 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.