What's happening?
This was around a year back when I started the project, after a small speaker that I had broke out of nowhere. Won't connect.
, , and had just started on 100 Go Mistakes and How to Avoid Them.
And WebRTC? Also, WebRTC is mostly built around browser-to-browser, peer-to-peer stuff. My setup is a server broadcasting to multiple clients over LAN, which isn't really what WebRTC is designed for. So even if I knew about it from day one, I'm not sure it would've been the right fit anyway.
WebSocket was fine. It worked. And sometimes that's enough. I didn't want to overengineer.
👀 I learned about all these new terms like PCM, WebRTC, and all that stuff during the build. So, I might say something wrong. I'm not really that familiar with them. So, just hit me in the comments if so.
The Architecture
Okay, so the high level is pretty simple.
There's a server and there are clients. The server is where the music is stored, and the clients are the devices that play it (could be the same device).
Here's what actually happens when you press play:
The server takes the MP3 file, decodes it into raw PCM (basically just bytes of sound data), and starts broadcasting those bytes over WebSocket to every connected client. No client-side decoding. The server does all of that.
Here's a high level architecture:
There's also something in the code that keeps checking, roughly every second, whether the audio playing on your device is slightly ahead or behind.
If it is, it quietly adds or removes a tiny bit of audio to bring it back in line. So small you'd never hear it.
Both of these kind of work. I tested it. I just couldn't tell you exactly why the numbers are what they are.
How I usually run it
Since my plan is to use my whole laptop as a "speaker", I usually have the server and client on the same system (my personal laptop).
And I usually have it like this:
- Start the server:
gophercast serve # now follow the TUI setup....
- Connect clients (each in a tmux split). Usually, I have around 2 clients when running on the same machine. More than 2 kind of distorts the audio quality.
gophercast play --host <ip_from_serve> --port 8080 --name "client 1"
gophercast play --host <ip_from_serve> --port 8080 --name "client 2"
The steps are the same when connecting from multiple machines. Just make sure that all of them are connected to the same LAN.
Here's a quick demo on a single machine, working as the speaker.
(Ignore the audio quality)
My take
I'm pretty happy with how this worked out.
This was my very first time working with Charm's
(I haven't tested how well it works on Mac, so I can't tell there. Also, I'm not sure Windows will work either due to oto's limitation and our hardcoded 50ms delay.)
You can find the repo here:
SOCIAL SHARE CARD GENERATOR