Skip to main content
Pion WebRTC provides an extensive collection of examples covering common use-cases. You can modify and extend these examples to get started quickly with real-time communication in Go.

Getting Started

All examples can be run locally using the examples server:
1

Clone the repository

git clone https://github.com/pion/webrtc.git webrtc
cd webrtc/examples
2

Run the examples server

go run examples.go
You can change the port using the --address flag:
go run examples.go --address localhost:8080
go run examples.go --address :8080  # listen on all interfaces
3

Access the examples

Browse to localhost to explore all available examples

Media API Examples

Examples demonstrating audio and video streaming capabilities:

Media Streaming

Send video and audio from disk to your browser with frame-by-frame control

Save to Disk

Record webcam and microphone streams and save them as VP8/Opus files

Broadcast

Broadcast video to multiple peers with single upload using SFU pattern

RTP Forwarder

Forward audio/video streams via RTP to external applications

Simulcast

Accept and demux single track with 3 simulcast streams into separate tracks

Data Channel API Examples

Examples showing how to use WebRTC data channels for real-time data transfer:

Data Channels

Send and receive DataChannel messages between browser and server

ORTC

Use the ORTC API for low-level DataChannel communication control

Key Features

Many Pion WebRTC examples support WebAssembly compilation, allowing you to use WebRTC from Go in both server and browser code with minimal changes.To compile an example for WebAssembly:
cd examples/data-channels/jsfiddle
GOOS=js GOARCH=wasm go build -o demo.wasm
The examples server will automatically detect and offer the WebAssembly option.
Most examples use a simple copy-paste signaling mechanism for demonstration purposes:
  1. Run the example application
  2. Paste the browser’s offer into the terminal
  3. Copy the answer from terminal to browser
Production applications should implement proper signaling using WebSockets, HTTP polling, or other real-time communication methods.
All examples use Google’s public STUN server by default:
config := webrtc.Configuration{
    ICEServers: []webrtc.ICEServer{
        {
            URLs: []string{"stun:stun.l.google.com:19302"},
        },
    },
}
For production deployments, consider using your own STUN/TURN servers.

Advanced Examples

For more full-featured examples using third-party libraries, check out the example-webrtc-applications repository.
Each example is self-contained and demonstrates a specific use case. Start with the data channels or media streaming examples to understand the basics, then explore more advanced patterns like simulcast and broadcasting.

Build docs developers (and LLMs) love