Real-Time Audio, Video, and Data on Flutter Web with flutter_webrtc
Build real-time calls in a Flutter web app with flutter_webrtc 1.6.x: peer connection setup, STUN versus TURN, signaling over WebSocket, data channels, and browser quirks.
Published on • November 11, 2026
AI Assistant

WebRTC is where Flutter web stops being a rendering target and becomes a network client: media and bytes travel peer-to-peer, outside your server’s request path. The flutter_webrtc package already speaks the browser’s WebRTC stack — this post covers what that gets you on web, how a call is actually set up, and the browser rules that decide whether it connects at all.
What flutter_webrtc gives you on web
Version 1.6.3 lists web as a first-class target, built on dart_webrtc and package:web rather than platform channels, and its feature matrix reads well for browsers: audio/video, data channels, screen capture, unified-plan, simulcast, MediaRecorder, and end-to-end encryption are all marked supported on web. Everything still runs in a secure context — HTTPS or localhost — because the underlying getUserMedia does.
dependencies:
flutter:
sdk: flutter
flutter_webrtc: ^1.6.3
The mobile side of the story (permissions, lifecycle, native renderers) is covered in the existing WebRTC post; on web the interesting parts are the negotiation flow and the network path.
Offer, answer, and ICE
A call starts by building a peer connection with ICE servers, handing it your local media, and watching for remote tracks:
import 'package:flutter_webrtc/flutter_webrtc.dart';
RTCPeerConnection? _pc;
Future<void> connect() async {
_pc = await createPeerConnection({
'iceServers': [
{'urls': 'stun:stun.l.google.com:19302'},
{'urls': 'turn:turn.example.com:3478', 'username': 'u', 'credential': 'p'},
],
});
final local = await getUserMedia(MediaStreamConstraints(audio: true, video: true));
for (final track in local.getTracks()) {
await _pc!.addTrack(track, local);
}
_pc!.onTrack = (RTCTrackEvent event) {
final remote = event.streams.first; // attach this to your renderer
};
}
Then comes the offer/answer dance, with ICE candidates trickling alongside it. The SDP blobs must cross a signaling channel you provide — a WebSocket is the usual choice, and our Flutter WebSockets post covers that side:
Future<void> negotiate(RTCPeerConnection pc) async {
final offer = await pc.createOffer();
await pc.setLocalDescription(offer);
await signaling.send({'type': 'offer', 'sdp': offer.sdp});
pc.onIceCandidate = (c) {
signaling.send({
'type': 'ice',
'candidate': c.candidate,
'sdpMid': c.sdpMid,
'sdpMLineIndex': c.sdpMLineIndex,
});
};
signaling.onMessage((msg) async {
if (msg['type'] == 'answer') {
await pc.setRemoteDescription(RTCSessionDescription(msg['sdp'], 'answer'));
} else if (msg['type'] == 'ice') {
await pc.addIceCandidate(
RTCIceCandidate(msg['candidate'], msg['sdpMid'], msg['sdpMLineIndex']));
}
});
}
STUN discovers, TURN relays
STUN servers do one job: report your public IP:port back so both peers can attempt a direct path. That works until it does not — symmetric NATs, CGNAT carriers, and strict corporate firewalls block the direct route. For those pairs only TURN helps, because it relays the traffic through your server.
Production calls therefore need both: public STUN for the easy cases, your own TURN with credentials — typically short-lived, minted per room by your signaling server — for the hard ones. A cheap diagnostic is to build the connection with iceTransportPolicy: 'relay': if calls only connect with TURN forced, you know how much of your real traffic is relaying and should budget TURN bandwidth accordingly. Expect TURN’s cost to track relayed bytes, so compress video before you compress the bill.
Data channels and screen share
Audio and video are optional; RTCDataChannel gives you a bidirectional lane for chat, state, or control messages over the same negotiated connection:
final dc = await _pc!.createDataChannel('chat');
dc.onMessage = (RTCDataChannelMessage message) {
print('peer says: ${message.text}');
};
await dc.send(RTCDataChannelMessage('ping'));
Screen sharing rides getDisplayMedia() — exposed by the package on web — and is governed by its own Permissions-Policy directive, display-capture, so an iframe needs allow="display-capture" just as it needs allow="camera; microphone". Recording the result is handled by MediaRecorder, which the package’s matrix marks as web-supported.
Rendering, quirks, and cleanup
Remote video is still an HTML <video> under the hood, so the standard widget route works:
final _remote = RTCVideoRenderer();
Future<void> initRenderers() async {
await _remote.initialize();
_remote.srcObject = remoteStream; // from onTrack
}
// in build():
RTCVideoView(_remote, objectFit: RTCVideoViewFit.cover);
Three quirks decide whether users actually hear anything. Browsers autoplay-block remote audio until a recent user gesture, so chain the first play into your join button. Safari insists on unified-plan — flutter_webrtc’s web implementation supports it, but avoid legacy plan-B assumptions in custom code. And on HtmlElementView-based routes, Flutter can lose pointer events that land on the embedded element, so keep controls outside the video box or use pointer_interceptor.
Cleanup is not optional: await _pc.close(), stop and dispose the local MediaStream, dispose the renderer, and unregister signaling handlers — otherwise the browser’s recording indicator stays on and the WebSocket keeps running.
Takeaway: flutter_webrtc brings the full WebRTC stack to Flutter web — negotiate offer/answer over your signaling channel, ship both STUN and TURN if you need production reliability, gate the first play on a user gesture, and close every connection so the camera light and the socket both go dark.