|
| 1 | +--- |
| 2 | +layout: "@/layouts/global.astro" |
| 3 | +title: "MoqBoy" |
| 4 | +author: kixelated |
| 5 | +description: "" |
| 6 | +cover: "/blog/monte-video/uruguay.png" |
| 7 | +date: 2026-04-14 |
| 8 | +--- |
| 9 | +import Boy from "@/components/boy.astro"; |
| 10 | + |
| 11 | +<center> |
| 12 | + <img src="/demo/moqboy.svg" class="h-40" alt="MoQ Boy" /> |
| 13 | +</center> |
| 14 | + |
| 15 | +<Boy /> |
| 16 | + |
| 17 | +# MoqBoy |
| 18 | +It's like Twitch Plays Pokemon, but I don't want to get sued so enjoy homebrew games lul. |
| 19 | + |
| 20 | +**EVERYTHING** uses a single connection to a generic MoQ CDN. Wowee. |
| 21 | + |
| 22 | +## On-Demand |
| 23 | +First I want to gloat about the most impressive feature: **SAVING MOOLAH**. |
| 24 | + |
| 25 | +When a viewer wants audio and/or video, they issue a `SUBSCRIBE` request. |
| 26 | +moq-relay takes that `SUBSCRIBE` and deduplicates it, combining it with other identical subscriptions. |
| 27 | +A few hops later, the underpowered cloud VM running the emulator gets zero or one `SUBSCRIBE` requests for each track. |
| 28 | + |
| 29 | +By default, a MoQ publisher will only transmit a track if there's an active subscription. |
| 30 | +So our emulator would still run and encode, while the precious pixels sit in RAM waiting for their time to shine. |
| 31 | + |
| 32 | +But we big brain. That not good enough. |
| 33 | +We turn the encoder on/off if there's an active subscription: |
| 34 | + |
| 35 | +- If there's no audio subscription, the Opus encoder sleep. |
| 36 | +- If there's no video subscription, the H.264 encoder sleep. |
| 37 | + |
| 38 | +But we even bigger brain than that: |
| 39 | + |
| 40 | +- If there's no audio AND video subscription, the emulator sleep. |
| 41 | + |
| 42 | +That's right, we're not burning through the CPU/GPU unless somebody needs it. |
| 43 | +And I mean _needs_ it; the web player will `UNSUBSCRIBE` to video if you scroll or tab away. |
| 44 | +Scroll back up to the demos and you might see a black screen while the encoder/emulator/subscription reinitializes. |
| 45 | + |
| 46 | +Obviously this is not a huge deal for a gameboy emulator. |
| 47 | +The screen is 160x144, even your vape pen could run it. |
| 48 | + |
| 49 | +But it does start to matter for anybody running expensive transcoding and AI models. |
| 50 | +If nobody wants captions, then don't run Whisper lul. |
| 51 | +And it's all built into MoQ baybee. |
| 52 | + |
| 53 | + |
| 54 | +## Discovery |
| 55 | +A boring person would have hard-coded the list of available games. |
| 56 | +But I'm HYPER-C00l, so MoqBoy instead uses MoQ's ability to discover available "broadcasts". |
| 57 | + |
| 58 | +The viewer asks the CDN for every broadcast with the prefix `demo/boy/**`. |
| 59 | +It will get a live notification when a matching broadcast comes online or goes offline. |
| 60 | + |
| 61 | +- One worker publishes `demo/boy/big2small`. |
| 62 | +- Another worker publishes `demo/boy/opossum`. |
| 63 | +- The viewer discovers both and inserts them into the grid. |
| 64 | + |
| 65 | +Also I can't let this slide. |
| 66 | +"opossum" is a made up word. |
| 67 | +It can't be spelled like that. |
| 68 | +It can't be real. |
| 69 | + |
| 70 | +Anyway, this is also how [hang.live](https://hang.live) discovers users in each conference room. |
| 71 | +It's as easy as "tell me when somebody publishes `room123/**`". |
| 72 | +You don't need a separate "room" service that manages membership, just use MoQ lul. |
| 73 | + |
| 74 | + |
| 75 | +## Controls |
| 76 | +MoQ is a one-directional protocol. |
| 77 | +Broadcasters broadcast, viewers view. |
| 78 | +But how do players play? |
| 79 | + |
| 80 | +Psst, I'll tell you a secret. |
| 81 | +**Each viewer is a broadcaster too!** |
| 82 | + |
| 83 | +Each player publishes a broadcast called `demo/viewer/big2small/<id>`, with a random ID. |
| 84 | +They produce a single `controls` track, and when a button is pressed, writes a JSON blob to it: |
| 85 | +```json |
| 86 | +{ |
| 87 | + a: true, |
| 88 | + up: true |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +The MoqBoy publisher uses the same DISCOVERY mechanism listed above to find all players. |
| 93 | +It subscribes to the `controls` track for any broadcasts with the prefix `demo/viewer/big2small/`. |
| 94 | + |
| 95 | +Bada bing, bada boom. |
| 96 | +We reinvented bidirectional streams using multiple unidirectional streams. |
| 97 | + |
| 98 | +But why not build bidirectional streams into MoQ proper? |
| 99 | +Well it's because of business logic you nerd. |
| 100 | + |
| 101 | +This demo uses anarchy, where the broadcaster chooses to SUBSCRIBE to **ALL** players. |
| 102 | +Your flesh mangling robot might want lockout, where the broadcaster chooses to SUBSCRIBE to **ONE** player. |
| 103 | +Or maybe it gains sentience and doesn't want to SUBSCRIBE to **ANY** pathetic humans any longer. |
| 104 | + |
| 105 | +IDK it's just easier to design/scale a protocol that fans out. |
| 106 | +We're not in the business of adding business logic to the relay to merge JSON blobs or some other nonsense. |
| 107 | + |
| 108 | +## Open Source |
| 109 | +Oh right and you can run it yourself. |
| 110 | +[Setup the mono repo], then run `just boy`. |
| 111 | + |
| 112 | +It's fun to type. |
| 113 | +Just boy. |
| 114 | +Just boy. |
| 115 | + |
| 116 | +If you're too lazy to ask Claude, here's the [Rust publisher](https://github.com/moq-dev/moq/tree/main/rs/moq-boy) and [JS player](https://github.com/moq-dev/moq/tree/main/js/moq-boy). |
| 117 | + |
| 118 | +## A Real Demo |
| 119 | +So I know this looks like a fun emulator side project, but I swear it's not. |
| 120 | +This is meant to be a DEMO of how you should use MoQ for robots, drones, and other murder machines. |
| 121 | + |
| 122 | +If you work in one of those lucrative industries and want some help, hit me up. |
| 123 | +I've started contracting as a way of getting MoQ pilots off the ground (literally and figuratively). |
| 124 | + |
| 125 | +Email me at: `me@kixel.me` |
| 126 | + |
| 127 | +Or DM me on [Discord](https://discord.gg/FCYF3p99mr), that's way more fun. |
| 128 | + |
| 129 | +Written by [@kixelated](https://github.com/kixelated). |
| 130 | + |
0 commit comments