tvplay

How does your phone change my TV?

You paste a link on a website. A few seconds later, a TV in my living room plays it. Here's every piece in between, explained like you're five.

swipe to see it all →
The path a video takes Your phone sends a link to Cloudflare. Cloudflare checks it with YouTube, runs the vote, then tells a helper program inside my house. The helper tells YouTube on the TV to play it. The TV reports back what second it's at, and that comes back to your phone so you watch along. THE INTERNET (Cloudflare) MY HOUSE (locked front door) Send Your phone the web page The Referee checks links · runs the vote keeps the queue · counts who's here top 3 → 20-second vote YouTube "is this video OK?" The Helper a tiny program on my Mac, always on My TV 1 link 2 check 3 "play this" 4 cast 5 "I'm at 0:42" 6 watch along
your video going to the TVthe TV reporting back

One video's trip, step by step

From your thumb to my couch, in under half a minute (plus the vote).

  1. 1
    You paste a link.

    The web page sends it over the internet to the Referee. Not a YouTube link? It reads the page's title and searches YouTube for you.

    your phone
  2. 2
    The Referee checks it with YouTube.

    Is it real? Public? Not age-restricted? Not a live stream? Playable in the US? Long videos aren't turned away: they play just the first 3 minutes.

    the internet
  3. 3
    I approve it (from my phone).

    A grown-up looks before it hits the living room. If I turn approvals off, it skips straight to the vote.

    my phone
  4. 4
    Everyone votes for 20 seconds.

    The 3 most-wanted videos go on the ballot. One vote each. The winner plays.

    the internet
  5. 5
    The Referee tells the Helper in my house.

    The Helper is already on the line (it called out first, so nothing can call in). It opens YouTube on the TV if it's closed.

    my house
  6. 6
    The Helper "casts" it, like the Cast button on your phone.

    It uses the same language your YouTube app uses to send a video to a TV. The TV doesn't know it's a crowd.

    my TV
  7. 7
    The TV reports back, and you watch along.

    YouTube on the TV says "playing, at 0:42" or "paused." That goes back up to every phone, so your page plays the same video at the same second, and shows ⏸ when the TV pauses.

    everyone's phone

Why is there a Helper in my house?

Because nobody on the internet can knock on my TV's door. That's a good thing.

Calling in: blocked

My home router is a locked front door. The internet can't reach in and press buttons on the TV.

Calling out: allowed

The Helper inside calls the Referee and keeps the line open, like a walkie-talkie. Orders come down that line. No door is ever opened.

The parts list

The real names, if you want to look them up.

One web page

A single HTML file, no app to install. It holds a live connection (a WebSocket) so votes and the clock update instantly.

Cloudflare Worker + Durable Object

A tiny program that runs on Cloudflare's servers worldwide. The "Durable Object" is one room with a memory: the queue, the ballot, who's here, and a log of every submission.

YouTube Data API

Asks YouTube about each video: length, age rating, region, channel. Answers are saved for 6 hours so we don't ask twice.

A Node.js relay

Runs on a Mac in my house and starts by itself when the Mac turns on. It only knows two commands: play this YouTube video, and play/pause. Everything else is refused.

YouTube "Lounge" protocol

How phones talk to YouTube on TVs. The Helper pairs with the TV once, then sends "play this list." It also turns off autoplay so random videos don't sneak in.

A normal Samsung smart TV

Nothing installed, nothing hacked. It just runs the regular YouTube app, which is told what to play.

The synced mirror

Your page embeds the same video and jumps to the TV's real position whenever it drifts more than 2 seconds.

tvplay.lol

A domain pointed at Cloudflare. Same code also answers the admin page I use to approve videos from my phone.

Rules that keep it fun (and my house safe)

Things that didn't work

Most of building this was finding out what the TV won't let you do.

By the numbers

1real TV
20sto vote
3 minmax for long videos
10–25sfrom the vote ending to the TV playing
~1,900lines of code
0doors opened on my home network
Send a video to my TV →