YT Live Streamer — Player Website
About This Component
====================

WHAT IS THIS?
─────────────
The Player Website lets you stream to your own website at the same time as
YouTube. Viewers on your site get a full live player with a built-in chat
room — completely independent of YouTube's chat.

It runs on your own Linux machine (the same PC you stream from) or any Ubuntu
server. No subscription, no third-party service, no ongoing cost beyond your
existing internet connection or VPS.


WHAT VIEWERS SEE
────────────────
  • Full-screen capable dark-themed video player (Video.js)
  • Live chat with coloured usernames
  • Viewer count
  • Auto-reconnects if stream drops
  • "Stream is offline" placeholder when not live
  • Works on mobile and desktop browsers
  • No YouTube account needed to watch


HOW IT WORKS
────────────
  1. Your streamer (ffmpeg) sends your stream to two places at once:
       → YouTube RTMP   (rtmp://a.rtmp.youtube.com/live2/YOUR_KEY)
       → Your server    (rtmp://YOUR_MACHINE_IP/live/stream)

  2. nginx-rtmp receives your stream and converts it to HLS
     (a series of small .ts video chunks + an .m3u8 playlist file)

  3. Your website serves those HLS chunks to viewers via HTTP

  4. The Python chat server handles real-time WebSocket chat

  Everything runs locally — nginx, the chat server and the HLS files
  all live on your machine.


FILES IN THIS FOLDER
────────────────────
  stream_player.html        The web player page (copy to your webserver)
  chat_server.py            Python WebSocket chat server
  setup_stream_server.sh    Automated Ubuntu setup script
  ABOUT.txt                 This file
  INSTALL.txt               Step-by-step setup guide


REQUIREMENTS
────────────
  Ubuntu 20.04 or 22.04 (the machine you stream from, or a VPS)
  nginx with libnginx-mod-rtmp
  Python 3 with websockets package
  ffmpeg (already installed if you use the streamer)
  Port forwarding if you want public access (ports 80, 1935, 8765)
    OR Tailscale for private/secure access without port forwarding


MULTI-RTMP PLUGIN
─────────────────
  The multi_rtmp.py plugin (in streamer_plugins/) handles sending your
  stream to both YouTube and your server simultaneously. It uses ffmpeg's
  tee muxer — one encode, multiple destinations — so there is no extra
  CPU cost for the second stream.


CHAT FEATURES
─────────────
  Viewer commands:
    /name YourName       Set your display name
    /color #ff6b6b       Set your chat name colour (any hex colour)
    /help                Show available commands

  Moderator commands (after /mod PASSWORD):
    /ban username        Ban a user by IP address
    /clear               Clear chat for all viewers

  Change the mod password:
    Edit /etc/systemd/system/stream-chat.service
    Add:  Environment="CHAT_MOD_PASSWORD=yourpassword"
    Then: sudo systemctl daemon-reload
          sudo systemctl restart stream-chat


CUSTOMISING THE PLAYER
──────────────────────
  Open stream_player.html in a text editor. Near the top of the
  <script> section you will find the CONFIG block:

    const CONFIG = {
      hlsUrl:      "http://YOUR_SERVER_IP/hls/stream/index.m3u8",
      chatWsUrl:   "ws://YOUR_SERVER_IP:8765",
      streamTitle: "My Live Stream",
      pollInterval: 5,
    };

  Change streamTitle to your stream name.
  Change the IPs to match your server.
  If you add HTTPS/WSS, change http:// to https:// and ws:// to wss://


EMBEDDING ON AN EXISTING WEBSITE
──────────────────────────────────
  Option 1 — Embed the whole player page in an iframe:
    <iframe src="http://YOUR_SERVER/" width="100%" height="600"
            frameborder="0" allowfullscreen></iframe>

  Option 2 — Video only, no chat (add to any HTML page):
    <link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/8.6.1/video-js.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/8.6.1/video.min.js"></script>
    <video id="player" class="video-js" controls autoplay muted playsinline>
      <source src="http://YOUR_SERVER/hls/stream/index.m3u8"
              type="application/x-mpegURL">
    </video>
    <script>videojs('player');</script>


CHEAP VPS OPTIONS (if not running on your own machine)
──────────────────────────────────────────────────────
  Hetzner CX11    ~$4/mo   2GB RAM   Recommended — great value
  Vultr           ~$6/mo   1GB RAM   Good reliability
  DigitalOcean    ~$6/mo   1GB RAM   Easy to use
  Linode          ~$5/mo   1GB RAM   Solid performance

  All run Ubuntu 22.04. The setup script targets Ubuntu specifically.
  Hetzner is recommended — best specs per dollar, EU and US servers.
