Action broadcaster for easy multiplayer web applications.

Overview

Hummingbird

Action broadcaster for easy multiplayer web applications.

About

Hummingbird is both an open-source software and a public live service that allows web applications based on action dispatching to relay actions to other connected clients.

Protocol

Hummingbird uses WebSocket to exchange messages between client and server. When the upgrade request is made, the pathname (e.g. /my/channel in wws://hummingbird.crz.li/my/channel) is used as channel and incoming messages are relayed to other clients connected on the same channel, like a broadcasting system, but it has a few extra steps to make state synchronization easier. Clients are flagged as either fresh or stale. Fresh clients are free to exchange messages but stale clients will require a state update from a fresh client before receiving any other messages. Also, all exchanged messages are expected to be JSON encoded objects with a type field.

Schema of the protocol

It's important to notice that there are limitations with this approach. See pitfalls below.

Usage

No setup is required and the service is free. Simply open a new connection and you're good to go.

const webSocket = new WebSocket("wws://hummingbird.crz.li/test");
webSocket.send(JSON.stringify({ type: "someAction" }));

Below is a contrived example using React, with important parts commented. You can also see the full code.

{ const action = { type: "+1" } as Action; // When we click the button we need to: // 1. Dispatch the action to update our own state. dispatch(action); // 2. Relay the action to ther connected clients. broadcast(action); }; if (readyState !== WebSocket.OPEN) { return

Connecting...

; } return (

Count: {count}

); }">
function reducer(state: number, action: Action) {
  switch (action.type) {
    // When we receive a state update we need to do some state reconciliation, since it could have changed between request and reply.
    case "stateUpdateReply":
      return state + action.payload;
    case "+1":
      return state + 1;
    default:
      return state;
  }
}

export default function App() {
  const [count, dispatch] = useReducer(reducer, 0);

  const [readyState, broadcast] = useWebSocket({
    onMessage(action) {
      // We must respond a state update request with our current state.
      if (action.type === "stateUpdateRequest") {
        broadcast({ type: "stateUpdateReply", payload: count });
      }
      dispatch(action);
    },
  });

  const handleClick = () => {
    const action = { type: "+1" } as Action;

    // When we click the button we need to:
    // 1. Dispatch the action to update our own state.
    dispatch(action);
    // 2. Relay the action to ther connected clients.
    broadcast(action);
  };

  if (readyState !== WebSocket.OPEN) {
    return <p>Connecting...</p>;
  }

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={handleClick}>Add 1</button>
    </div>
  );
}

See it in action. Open in two different tabs and check them out side by side.

Pitfalls

  • Actions dispatched by a stale client will be relayed to other fresh clients even before a state reconciliation has happened.
  • The client is responsible for state reconciliation upon getting a state update.
  • State updates are client authoritative, i.e. there's no security.

Legal

Terms of use

By using the service you agree that you will behave lawfully good.

License

Apache-2.0 © 2022 Arthur Corenzan.

You might also like...

Flexible and easy Dash/HLS/DRM integration for HTML5 video.

Flexible and easy Dash/HLS/DRM integration for HTML5 video.

This project is made possible with Plyr, Hls.js, Dash.js. Features 📑 HLS and DASH playback 🎥 Multi quality supported 🎬 Drm with custom header suppo

Nov 11, 2022

A simple and easy-to-use WhatsApp bot project based on Multi-Device Baileys and written in JavaScript

A simple and easy-to-use WhatsApp bot project based on Multi-Device Baileys and written in JavaScript

MIZUHARA ANIME THEMED FULL FLEDGED MULTI DEVICE WHATSAPP BOT WITH COOL FEATURES A Full Fledged MD Bot For Bot Lovers REQUIREMENTS • HOW TO INSTALL? •

Oct 25, 2022

🎬 super easy recording for p5.js animations

🎬 super easy recording for p5.js animations

About • Why p5.capture? • Getting started • API Options • Browser compatibility • Limitations About Assuming you would like to record p5.js animations

Jan 5, 2023

An easy way for users to appeal from a server ban. Hosted with Cloudflare workers.

An easy way for users to appeal from a server ban. Hosted with Cloudflare workers.

Discord Ban Appeal Make it possible for users to appeal their bans online With a simple configuration to make your form unqiue to your server and with

Aug 10, 2022

A lightweight easy-to-use minecraft chatbridge

A lightweight easy-to-use minecraft chatbridge

Kyuta Bot - Minecraft ChatBridge Kyuta is discord chat-bridge integration for minecraft based on the bedrock-protocol library and functions similarly

Sep 27, 2022

A Discord music bot that's easy to set up and run yourself!

Mocha Music Bot Template A discord music bot template built using node.js. Feel free to edit and host your own version of this music bot. The prominen

Oct 28, 2022

AmplitudeJS: Open Source HTML5 Web Audio Library. Design your web audio player, the way you want. No dependencies required.

AmplitudeJS: Open Source HTML5 Web Audio Library. Design your web audio player, the way you want. No dependencies required.

Documentation • Examples • Tutorials • Support Us • Get Professional Help AmplitudeJS is a lightweight JavaScript library that allows you to control t

Jan 2, 2023

A review aggregator web application that allows users to review albums by leveraging the Spotify Web API.

A review aggregator web application that allows users to review albums by leveraging the Spotify Web API.

Reviewify Summary Reviewify is a review aggregator platform that leverages the Spotify Web API. It allows users to: Login with their Spotify accounts

Oct 7, 2022

A bot builder on top of puppeteer's headless web browser mimicing your web.whatsapp.com functionalities.

A bot builder on top of puppeteer's headless web browser mimicing your web.whatsapp.com functionalities.

Welcome to the BizBook365 WhatsApp bot project A bot builder on top of puppeteer's headless web browser mimicing your web.whatsapp.com functionalities

Dec 1, 2022
Comments
  • Bump ws from 6.2.0 to 7.4.6

    Bump ws from 6.2.0 to 7.4.6

    Bumps ws from 6.2.0 to 7.4.6.

    Release notes

    Sourced from ws's releases.

    7.4.6

    Bug fixes

    • Fixed a ReDoS vulnerability (00c425ec).

    A specially crafted value of the Sec-Websocket-Protocol header could be used to significantly slow down a ws server.

    for (const length of [1000, 2000, 4000, 8000, 16000, 32000]) {
      const value = 'b' + ' '.repeat(length) + 'x';
      const start = process.hrtime.bigint();
    

    value.trim().split(/ *, */);

    const end = process.hrtime.bigint();

    console.log('length = %d, time = %f ns', length, end - start); }

    The vulnerability was responsibly disclosed along with a fix in private by Robert McLaughlin from University of California, Santa Barbara.

    In vulnerable versions of ws, the issue can be mitigated by reducing the maximum allowed length of the request headers using the --max-http-header-size=size and/or the maxHeaderSize options.

    7.4.5

    Bug fixes

    • UTF-8 validation is now done even if utf-8-validate is not installed (23ba6b29).
    • Fixed an edge case where websocket.close() and websocket.terminate() did not close the connection (67e25ff5).

    7.4.4

    Bug fixes

    • Fixed a bug that could cause the process to crash when using the permessage-deflate extension (92774377).

    7.4.3

    Bug fixes

    • The deflate/inflate stream is now reset instead of reinitialized when context takeover is disabled (#1840).

    7.4.2

    Bug fixes

    ... (truncated)

    Commits
    • f5297f7 [dist] 7.4.6
    • 00c425e [security] Fix ReDoS vulnerability
    • 990306d [lint] Fix prettier error
    • 32e3a84 [security] Remove reference to Node Security Project
    • 8c914d1 [minor] Fix nits
    • fc7e27d [ci] Test on node 16
    • 587c201 [ci] Do not test on node 15
    • f672710 [dist] 7.4.5
    • 67e25ff [fix] Fix case where abortHandshake() does not close the connection
    • 23ba6b2 [fix] Make UTF-8 validation work even if utf-8-validate is not installed
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Implement catch-up queue

    Implement catch-up queue

    Messages send from fresh clients between a state update request and a state update reply won't reach stale clients and by the time they receive the state update it will be outdated.

    The idea is to queue up such messages and then relay them to stale clients in order and right after the state update reply.

    opened by haggen 0
  • Bump minimist from 1.2.5 to 1.2.6

    Bump minimist from 1.2.5 to 1.2.6

    Bumps minimist from 1.2.5 to 1.2.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Allow to customize state update action types

    Allow to customize state update action types

    Perhaps we could accept a config querystring carrying a base64 encoded JSON of some config options.

    base64(
      JSON.stringify({
        stateUpdateReq: "STATE_UPDATE_REQ",
        stateUpdateReply: "STATE_UPDATE_REPLY",
      })
    );
    
    wws://hummingbird.crz.li/my/channel?config=eyJzdGF0ZVVwZGF0ZVJlcSI6IlNUQVRFX1VQREFURV9SRVEiLCJzdGF0ZVVwZGF0ZVJlcGx5IjoiU1RBVEVfVVBEQVRFX1JFUExZIn0=
    
    opened by haggen 2
GitHub action to update your discord status in a file using Lanyard API.

Discord Status Action This action fetches the status of a given user and updates that on a file. - Online - Idle - Do not disturb - Streaming - Offlin

Compey 11 Dec 15, 2022
Simple activity indicator for StimulusReflex (for Turbo/Turbolinks-enabled applications)

StimulusReflex Activity Indicator Uses the Turbo(links) progress bar to display activity while morphing. CleanShot.2021-07-23.at.12.04.05.mp4 Installa

StimulusReflex 15 May 26, 2022
tauOS 17 Jul 10, 2022
A lightweight, easy-to-use jQuery plugin for fluid width video embeds.

Introducing FitVids.js A lightweight, easy-to-use jQuery plugin for fluid width video embeds. FitVids automates the Intrinsic Ratio Method by Thierry

Dave Rupert 4.8k Dec 24, 2022
:musical_score: ts-audio is an agnostic library that makes it easy to work with AudioContext and create audio playlists in the browser

ts-audio · ts-audio is an agnostic and easy-to-use library to work with the AudioContext API and create Playlists. Features Simple API that abstracts

Evandro Leopoldino Gonçalves 284 Dec 25, 2022
An Easy to use and advanced working multiguild Waitingroom Bot written in discord.js v13 without any extra modules.

Multiguild-Waitingroom-v13 An Easy to use and advanced working multiguild Waitingroom Bot written in discord.js v13 without any extra modules. It is m

Tomato6966 17 Dec 11, 2022
An easy bot to create discord buttons easily.

Discord Buttons An easy bot to create discord buttons easily. Note: Node.js 16.6.0 or newer is required. Installation npm install You need to rename e

Fnr 7 Aug 19, 2022
Easy and automatic updating way

Changes: ENTER Intents for client! const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBE

Akif Yüce 4 Jul 16, 2022
A easy way for making bots using Discord.js/Node.js

Discord.js-Bot-Template This is a very simple template for making bots using Discord.js/Node.js Tutorial: To begin, Install Node.js here. After Node.J

Prosperity 4 Nov 8, 2022
Easy-to-use , actively maintained discord bot written in dJS V13 with customizable features

Multi-purpose discord bot Found a bug? Notes There are some modules missing, you can still start the bot but there are some things within the source t

locus 7 Nov 28, 2022