Skip to main content

horus_js 0.1.1 copy "horus_js: ^0.1.1" to clipboard
horus_js: ^0.1.1 copied to clipboard

Browser WebSocket client for Thoth, published into a Maat application's public directory.

horus_js #

[horus_js — Browser WebSocket client for Thoth, published into a Maat application's public directory.]

Horus is the browser client for Thoth, Maat's Pusher-compatible WebSocket server. horus_client covers Dart and Flutter; Horus JS covers the page — one dependency-free file, no build step.

Application.configure(...)
    .withExtensions([horusJsExtension])
    .create();

Install #

A server-rendered Maat application needs no npm at all — add horus_js to pubspec.yaml, wire .withExtensions([horusJsExtension]) in bootstrap/app.dart, and run the command:

maat horus:install     # publishes public/js/horus.js
<script src="{{ asset('js/horus.js') }}"></script>
<script>
  const horus = new Horus({ key: '...', host: 'localhost', port: 6001 });
  horus.channel('news').on('PostPublished', (post) => render(post));
</script>

A decoupled front end with its own bundler installs the same client from npm instead, versioned in lockstep with this package:

npm install @gaitco/horus
import Horus from '@gaitco/horus';

const horus = new Horus({ key: '...', host: 'localhost', port: 6001 });

What it does #

  • Subscribes to public, private, and presence channels, adding the private-/presence- prefix for you.
  • Presence channels track the member list (here, joining, leaving).
  • channel.whisper(event, data) sends a client event to the other subscribers, gated server-side on client_events.
  • Reconnects on its own with exponential backoff and jitter, re-authorizing every private and presence channel with a fresh signature.
  • horus.fetch(url, init) is fetch with this connection's socket id attached, so a request handled with broadcast(...).toOthers(request).send() doesn't apply its own broadcast twice.

Full guide: docs/realtime-browser.md.

0
likes
160
points
147
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Browser WebSocket client for Thoth, published into a Maat application's public directory.

Repository (GitHub)

License

MIT (license)

Dependencies

maat

More

Packages that depend on horus_js