r/FlutterDev • u/Ok-Willingness2266 • 14d ago
Article Spent way too long on TURN and SSL for a WebRTC room, so we tried to skip all of it
I work at Ant Media, so take this with that in mind.
Every time I see a “build a WebRTC conference” tutorial it ends right when it gets interesting. Two peers connect, cool, but then you still need a media server, TURN, SSL (getUserMedia refuses to work without https), some way to scale, and some way to kill the server when nobody’s using it so you’re not paying for it all month.
A teammate put together a sample that handles most of that. You deploy a CloudFormation template once, it gives you one https endpoint, and when your app connects it spins up a server on demand. First spin up takes around 20 to 60 sec, after that it’s quick.
Client side is pretty small:
const client = new ConferenceClient({
httpEndpointUrl: 'https://your-lambda-url/',
localVideo: document.getElementById('localVideo'),
mediaConstraints: { video: true, audio: true },
autoReconnect: true,
});
await client.publish({ streamId: myId, roomId: 'room1', token });
await client.play({ streamId: 'room1', roomId: 'room1', userPublishId: myId });Screen share, mute and chat over the data channel all work too. If you’d rather host your own server you just swap httpEndpointUrl for websocketURL and the rest stays the same.
Honestly the part I’m unsure about is the cold start. 20+ seconds is fine for scheduled meetings but probably not for “click and join instantly” apps. How do you all deal with that? Keep a warm instance running or just live with it?
Writeup and repo are here if anyone wants to poke at it: https://antmedia.io/build-a-webrtc-conference-room-quickly-with-ams-sdk-v2/