ataraxia-ws-client
TypeScript icon, indicating that this package has built-in type declarations

0.12.0 • Public • Published

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.

/ataraxia-ws-client/

    Package Sidebar

    Install

    npm i ataraxia-ws-client

    Weekly Downloads

    2

    Version

    0.12.0

    License

    MIT

    Unpacked Size

    76.7 kB

    Total Files

    48

    Last publish

    Collaborators

    • aholstenson