ataraxia-ws-client

WebSocket client for Ataraxia P2P messaging

Usage no npm install needed!

<script type="module">
  import ataraxiaWsClient from 'https://cdn.skypack.dev/ataraxia-ws-client';
</script>

README

ataraxia-ws-client

npm version Dependencies Typedoc

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 a WebSocketServerTransport is running.
      • factory?: (url) => WebSocket, factory used to create a WebSocket instance, used to support running both in a browser and in Node via libraries such as ws.
      • authentication: AuthProvider[], array containing all of the authentication methods supported.