Skip to main content

General Questions

Pion WebRTC is a pure Go implementation of the WebRTC API. It allows you to build real-time communication applications in Go without requiring Cgo or external C libraries.Key features:
  • Pure Go: No Cgo dependencies, easy cross-compilation
  • Portable: Works on Windows, macOS, Linux, FreeBSD, iOS, Android, and WebAssembly
  • Standards Compliant: Implements W3C WebRTC specifications
  • Production Ready: Used by many projects in production
Pion offers several advantages:
  • Easy to Build: Simple go build command, no complex build systems
  • Cross-Platform: Compile once, run anywhere Go runs
  • No Dependencies: Pure Go means no external library dependencies
  • Flexible: Direct access to RTP/RTCP for custom media processing
  • Well Documented: Extensive examples and API documentation
  • Active Community: Regular updates and helpful community support
Yes! Pion WebRTC is used in production by many companies and projects. It’s actively maintained, has comprehensive test coverage, and follows WebRTC standards closely.See awesome-pion for real-world usage examples.
Version 4 includes dependency updates, performance improvements, and bug fixes. The core API remains similar, but import paths change from /v3 to /v4.See the Migration Guide for detailed upgrade instructions.

Getting Started

Using Go modules (required):
export GO111MODULE=on
go get github.com/pion/webrtc/v4
Then import in your code:
import "github.com/pion/webrtc/v4"
Pion provides extensive examples:To run examples locally:
git clone https://github.com/pion/webrtc.git
cd webrtc/examples
go run examples.go
Then browse to http://localhost
Basic understanding helps, but Pion provides:
  • WebRTC for the Curious - Free book about WebRTC
  • Extensive code examples with comments
  • Active community for questions
  • API that matches browser WebRTC (if you know browser WebRTC, you know Pion)
Pion WebRTC v4 requires Go 1.24.0 or later. Check your version:
go version
Update Go if needed from golang.org/dl

Media Handling

Pion WebRTC supports:Video:
  • H.264
  • VP8
  • VP9
  • AV1
Audio:
  • Opus
  • PCM
Pion provides packetizers for these codecs. You can also implement custom packetizers for other formats.
Use the play-from-disk example as a starting point:
  1. Read video file (IVF, H264, etc.)
  2. Create a track
  3. Add track to PeerConnection
  4. Read and send packets
Example: play-from-disk
Yes! You can pipe FFmpeg output to Pion or process FFmpeg output in Go.Common approaches:
  • Use FFmpeg to decode/encode media
  • Pipe RTP output from FFmpeg to Pion
  • Use Go FFmpeg bindings for processing
See rtp-to-webrtc example
Use the save-to-disk example:
track, err := peerConnection.AddTrack(videoTrack)
// Handle incoming track
peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
    // Save to IVF, Ogg, or other format
})
Example: save-to-disk
Yes! Pion gives you direct RTP/RTCP access:
peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
    for {
        rtp, _, err := track.ReadRTP()
        // Process raw RTP packet
    }
})

Connectivity & NAT Traversal

It depends on your network setup:
  • Local Network: No TURN needed
  • Same Network/No Firewall: STUN may be sufficient
  • Behind NAT/Firewall: TURN server recommended
  • Production: Always include TURN servers
Configure TURN:
config := webrtc.Configuration{
    ICEServers: []webrtc.ICEServer{
        {
            URLs: []string{"stun:stun.l.google.com:19302"},
        },
        {
            URLs:       []string{"turn:turn.example.com:3478"},
            Username:   "user",
            Credential: "pass",
        },
    },
}
Use the SettingEngine to configure a single UDP port:
s := webrtc.SettingEngine{}
s.SetEphemeralUDPPortRange(8000, 8000)
api := webrtc.NewAPI(webrtc.WithSettingEngine(s))
See ice-single-port example
Yes! Configure ICE to use TCP:
s := webrtc.SettingEngine{}
s.SetNetworkTypes([]webrtc.NetworkType{
    webrtc.NetworkTypeTCP4,
    webrtc.NetworkTypeTCP6,
})
See ice-tcp example
Trickle ICE allows ICE candidates to be sent incrementally instead of waiting for all candidates before starting negotiation.Benefits:
  • Faster connection establishment
  • Better user experience
  • Recommended for production
See trickle-ice example

Data Channels

Use DataChannels for bidirectional data transfer:
dataChannel, err := peerConnection.CreateDataChannel("data", nil)
dataChannel.OnMessage(func(msg webrtc.DataChannelMessage) {
    fmt.Printf("Message: %s\n", string(msg.Data))
})
dataChannel.OnOpen(func() {
    dataChannel.SendText("Hello!")
})
See data-channels example
Configure these settings when creating a DataChannel:
  • Ordered: Messages arrive in the order sent (default: true)
  • Unordered: Messages may arrive out of order (lower latency)
  • Reliable: Messages guaranteed to arrive (uses retransmission)
  • Unreliable: Messages may be lost (lower latency)
ordered := false
maxRetransmits := uint16(0)
dataChannel, err := peerConnection.CreateDataChannel("data", &webrtc.DataChannelInit{
    Ordered:        &ordered,
    MaxRetransmits: &maxRetransmits,
})
Monitor buffered amount to implement flow control:
if dataChannel.BufferedAmount() > 1024*1024 {
    // Wait before sending more
}
See data-channels-flow-control example

Deployment & Performance

Best practices:
  • Use interceptors for custom processing
  • Pool buffers to reduce GC pressure
  • Use Pion’s media libraries (IVF, Ogg readers/writers)
  • Monitor memory usage and optimize hot paths
  • Use single port configuration in production
  • Enable hardware acceleration for supported ciphers
Yes! Pion works well in containers:
  • Expose necessary UDP/TCP ports
  • Configure ICE servers properly
  • Use host networking or proper port mapping
  • Consider TURN for NAT traversal
Pion itself is a library, but you can build clustered systems:
  • Use TURN servers for media relay
  • Implement signaling server with load balancing
  • Use service mesh for connection distribution
  • See community projects for SFU implementations
This depends on:
  • Server resources (CPU, memory, bandwidth)
  • Media bitrate and complexity
  • Whether you’re using SFU/MCU architecture
Pion has been tested with thousands of concurrent connections. Use benchmarking tools like rtsp-bench to test your specific use case.

Debugging & Development

Pion uses the pion/logging interface:
import "github.com/pion/logging"

s := webrtc.SettingEngine{}
s.LoggerFactory = logging.NewDefaultLoggerFactory()
api := webrtc.NewAPI(
    webrtc.WithSettingEngine(s),
)
See custom-logger example
Useful debugging tools:
  • chrome://webrtc-internals: Chrome’s built-in WebRTC debugging
  • Wireshark: Packet capture and analysis
  • Pion’s logging: Enable debug logs
  • Stats API: Monitor connection statistics
stats := peerConnection.GetStats()
Testing strategies:
  • Unit tests for business logic
  • Integration tests with virtual networks (vnet)
  • Browser automation with tools like Selenium
  • Load testing with benchmarking tools
See vnet example for network simulation

Platform-Specific

Yes! Pion supports iOS and Android:
  • Compile using gomobile
  • Pure Go means no platform-specific build issues
  • Used in production mobile apps
Yes! Pion can be compiled to WebAssembly:
GOOS=js GOARCH=wasm go build -o demo.wasm
In WASM mode, Pion acts as a wrapper around the browser’s WebRTC API, allowing you to use the same Go code in browser and server.See examples with WASM support
Absolutely! Pion is a standard Go library:
  • Use with any Go web framework (Gin, Echo, Fiber, etc.)
  • Integrate with gRPC for signaling
  • Combine with other Go libraries
  • No special requirements or conflicts

Still Have Questions?

Community

Ask questions in Discord or GitHub Discussions

Troubleshooting

Common issues and solutions

Examples

Browse code examples

API Reference

Complete API documentation

Build docs developers (and LLMs) love