Guide · Open source
How to use WebRTC in Go with pion/webrtc: setup and basics
Updated · written with AI from the project's own documentation and checked against our catalogue data
pion/webrtc is an MIT-licensed library written in Go that implements the WebRTC API, the standard browsers and apps use to exchange audio, video, and data in real time. This guide explains what it is, how to set it up for a Go project, what it can do, and when it is the wrong choice. It is written for developers who already write Go and want to add WebRTC connections to a server or application.
Quick start
- 1Set module mode. Run export GO111MODULE=on as the README shows, so Go Modules are active.
- 2Create a Go module. Make a project directory that is a Go module, since the README says Go Modules are mandatory.
- 3Import the v4 package. Import the library with an explicit /v4 path, as the README instructs.
- 4Open a PeerConnection. Use the PeerConnection API to create a connection object for your peer.
- 5Add a DataChannel or media track. Create a DataChannel for data or attach audio or video tracks for media.
- 6Test against a browser or example. Compare your code with a sample from examples/README.md and connect it to a browser to confirm the exchange works.
What pion/webrtc is and who it is for
pion/webrtc is a library, not a ready-made app. You write Go code that calls its API to create peer connections, data channels, and media tracks. The README describes it as a pure Go implementation of the WebRTC API and says it has no Cgo dependency.
It fits Go developers who need WebRTC on a server or in an application, teams building real-time video or data channels in Go, and engineers who want low-level access to RTP and RTCP packets.
- Good fit: adding WebRTC to a Go server, streaming a webcam or media file to a browser from Go, low-level RTP/RTCP work.
- Poor fit: you want a finished video chat app, your project is not written in Go, or you have no networking background.
Install pion/webrtc with Go Modules
The README says Go Modules are mandatory. Set module mode before you use the library. The README's usage section gives this command:
When you import the library, explicitly specify the major version, /v4 (or an earlier version). The README does not specify a minimum Go version, so check the project's documentation for that before you start.
- Install Go first; the README does not state which Go version is required.
- Work inside a Go module so the import path works.
- Import the v4 path explicitly, as the README instructs.
export GO111MODULE=onUnderstand the main building blocks
The README's feature list shows what you work with. The PeerConnection API covers DataChannels, sending and receiving audio and video, renegotiation, and both Plan-B and Unified Plan. Connectivity features include a full ICE agent, ICE restart, Trickle ICE, STUN, TURN over UDP, TCP, DTLS and TLS, and mDNS candidates.
For media, the library offers direct RTP/RTCP access, packetizers for Opus, PCM, H264, VP8 and VP9, and IVF, Ogg, H264 and Matroska for sending and saving. You can also pass your own packetizer.
- PeerConnection: the core connection object.
- DataChannels: ordered or unordered, lossy or lossless.
- Media tracks: send and receive audio and video, with direct RTP/RTCP access.
- SettingEngine: Pion-specific extensions.
Find working examples before you write your own
Reading the GoDoc API reference alone is slow for a first project. The README points to several resources: an examples directory with code samples, a separate example-webrtc-applications repository with fuller examples that use third-party libraries, and the awesome-pion list of projects that use Pion.
The README also lists ideas such as sending a video file to multiple browsers, streaming a camera on an embedded device to a browser, and securely sending data between two servers without pub/sub. Start with the example closest to your goal and change it.
- examples/README.md: code samples of common tasks.
- example-webrtc-applications: more complete examples using third-party libraries.
- GoDoc: auto-generated API reference.
- The project FAQ and Discord community for questions.
Know the platform and media limits
The library is pure Go, so it builds without Cgo. The README lists Windows, macOS, Linux, FreeBSD, iOS, Android, WebAssembly, and the 386, amd64, arm, mips and ppc64 architectures. The README also notes that getUserMedia support, which comes from a separate mediadevices project, requires Cgo.
Security features include DTLS v1.2 and SRTP cipher suites listed in the README, with hardware acceleration for GCM suites. Check the README's Security section for the exact list before relying on a specific suite.
- Pure Go: no Cgo for the core library.
- getUserMedia capture (via the mediadevices project) requires Cgo.
- Debugging WebRTC issues benefits from the separate book WebRTC for the Curious, which the README describes as vendor agnostic.
What people use it for
- Sending a webcam feed from an embedded device to a browser, as the README's ideas list suggests.
- Sending a video file to several browsers in sync for shared viewing.
- Exchanging data securely between two servers through DataChannels.
- Recording a stream on a server and processing the frames, using the RTP access the library provides.
Frequently asked questions
Is pion/webrtc free to use?
Yes. The README states the project is licensed under the MIT License, and the full text is in the LICENSE file in the repository. Check that file for the exact terms.
What do I need to install pion/webrtc?
You need Go and a Go module setup. The README says Go Modules are mandatory and gives export GO111MODULE=on, and it does not specify a minimum Go version.
Does pion/webrtc need Cgo?
No, the core library has no Cgo dependency according to the README. The getUserMedia implementation from the separate mediadevices project does require Cgo.
Can I use pion/webrtc with Python or JavaScript?
The README says it is a pure Go implementation and Go Modules are mandatory, so it is for Go projects. For Python, the comparable project aiortc is listed as an alternative in this directory.
Is pion/webrtc a ready-made video chat app?
No. It is a library with an API that requires coding. For a finished app, look for a tool built on top of WebRTC rather than the library itself.
What should I read if my WebRTC connection fails?
The README recommends WebRTC for the Curious, a book on ICE, SCTP, DTLS, SRTP and the WebRTC stack. It also points to the Discord community for help with questions.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Use pion/webrtc if you write Go and need WebRTC on a server, in an embedded device, or inside an application, with low-level control over media and data. Pick a different project if you want a finished video chat product, if your stack is not Go, or if you have no networking background; the comparable projects listed here (aiortc, libwebrtc, mediasoup, Janus) may suit those cases better.
Install options & downloads