rxjs-protoo-client
TypeScript icon, indicating that this package has built-in type declarations

4.0.10 • Public • Published

rxjs-protoo-client CI

A protoo client written with direct RxJS support. Using RxJS results in a substantially smaller bundle size compared to the original protoo-client, assuming the client is also using RxJS.

Installation

npm install rxjs-protoo-client

Usage

import { Peer, webSocketTransport, RequestError } from "rxjs-protoo-client";

const transport = await webSocketTransport(url);

const peer = Peer.overTransport(transport);

// Send a request.
const response = await peer.request("method", {});

// Send a notification.
peer.notify("method", {});

// Listen for requests.
peer.subscribe(
  (message) => {
    if ("request" in message) {
      // Respond to the request.
      peer.next([message, {}]);

      // Alternatively, send an error.
      peer.error(new RequestError(request, 500, "Some error description."));
    } else {
      // Handle the notification.
    }
  },
  (err) => {
    // The peer unexpectedly closed.
  },
  () => {
    // The peer terminated successfully.
  }
);

// Close the connection.
peer.complete();

Differences

Besides the API difference, the one difference with this library is that this library does not auto-retry unexpectedly closed connections. Instead, handle the error and re-establish the peer with a new transport manually.

Dependencies (2)

Dev Dependencies (13)

Package Sidebar

Install

npm i rxjs-protoo-client

Homepage

protoojs.org

Weekly Downloads

0

Version

4.0.10

License

MIT

Unpacked Size

43.1 kB

Total Files

22

Last publish

Collaborators

  • kevmo314