Hackathon Project: Daily "cable access TV" with nginx

Options

Hackathon Recap

Repo here: https://github.com/vipyne/nginx-rtmp-docker


The Idea

A coworker and I were talking about how we enjoyed learning from our other colleagues, even if it was just watching them screenshare and squash a bug or delve through logs or push a small feature. And sometimes we missed just general office chatter. Wouldn't it be neat to have a constant live stream of content like this? I imagined a cable access channel TV-like experience. (Wayne's World was a big inspiration here.) I wanted to keep a small browser window always open in the corner of my screen, much like having a TV on in the background, that would show my coworkers doing a lunch-and-learn or hosting open office hours. There wouldn't be 24 hours everyday of content, so when nothing was streaming (or nothing was "on TV"), a static logo would appear. The nice thing here is that other than navigating to the site, I wouldn't have to do anything to passively access the content. Live streams would start and end and I could just sit back and watch. I imagined a blend of live and "syndicated", or pre-recorded, content and maybe some fun /daily logo bumpers, but in true Hack form, what was created is just a POC. Essentially I wanted to blend real time video with VOD (video on demand), and basically, that's what this does, albeit naively so.



The Approach

I knew I wanted to learn more about nginx configuration, especially with regard to RTMP streaming, so I started there. After I got the server config to handle RTMP, HLS, and VOD, I made a web 1.0 simple html page that loops an .mp4 file (the static /daily TV logo). Then I poll for RTMP stats (which we get for free from nginx, thanks nginx!). We parse the RTMP streaming stats XML for when a stream has started and when one has, we switch the video src and type on the player to HLS, and the live stream replaces the looping mp4 content. When the stream ends (again determined from polling the RTMP stats), we switch back to the mp4 video source and the player goes back to static.


Config files and DSLs can be difficult to work with and create a higher than usual barrier of entry. A pretty exhaustive list of `nginx-rtmp-module` directives was helpful here. I had hoped to accomplish the switching between live and VOD logic in the nginx config alone, but didn't quite get there. I'm pretty sure it is possible (if you know how, please comment!), at least with commercially available modules and/or the correct mix of nginx modules and more knowledge and experience than I have at the moment with more complex configurations. For now, Javascript’s `setTimeout` gets the job done.