examples

command
v3.0.0-eslami Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 9 Imported by: 0

README

Examples

We've built an extensive collection of examples covering common use-cases. You can modify and extend these examples to get started quickly.

For more full featured examples that use 3rd party libraries see our example-webrtc-applications repo.

Overview

Media API

  • Reflect: The reflect example demonstrates how to have Pion send back to the user exactly what it receives using the same PeerConnection.
  • Play from Disk: The play-from-disk example demonstrates how to send video to your browser from a file saved to disk.
  • Play from Disk Renegotiation: The play-from-disk-renegotiation example is an extension of the play-from-disk example, but demonstrates how you can add/remove video tracks from an already negotiated PeerConnection.
  • Insertable Streams: The insertable-streams example demonstrates how Pion can be used to send E2E encrypted video and decrypt via insertable streams in the browser.
  • Save to Disk: The save-to-disk example shows how to record your webcam and save the footage to disk on the server side.
  • Broadcast: The broadcast example demonstrates how to broadcast a video to multiple peers. A broadcaster uploads the video once and the server forwards it to all other peers.
  • RTP Forwarder: The rtp-forwarder example demonstrates how to forward your audio/video streams using RTP.
  • RTP to WebRTC: The rtp-to-webrtc example demonstrates how to take RTP packets sent to a Pion process into your browser.
  • Simulcast: The simulcast example demonstrates how to accept and demux 1 Track that contains 3 Simulcast streams. It then returns the media as 3 independent Tracks back to the sender.
  • Swap Tracks: The swap-tracks example demonstrates deeper usage of the Pion Media API. The server accepts 3 media streams, and then dynamically routes them back as a single stream to the user.
  • RTCP Processing The rtcp-processing example demonstrates Pion's RTCP APIs. This allow access to media statistics and control information.

Data Channel API

  • Data Channels: The data-channels example shows how you can send/recv DataChannel messages from a web browser.
  • Data Channels Detach: The data-channels-detach example shows how you can send/recv DataChannel messages using the underlying DataChannel implementation directly. This provides a more idiomatic way of interacting with Data Channels.
  • Data Channels Flow Control: Example data-channels-flow-control shows how to use the DataChannel API efficiently. You can measure the amount the rate at which the remote peer is receiving data, and structure your application accordingly.
  • ORTC: Example ortc shows how you an use the ORTC API for DataChannel communication.
  • Pion to Pion: Example pion-to-pion is an example of two pion instances communicating directly! It therefore has no corresponding web page.

Miscellaneous

  • Custom Logger The custom-logger demonstrates how the user can override the logging and process messages instead of printing to stdout. It has no corresponding web page.
  • ICE Restart Example ice-restart demonstrates how a WebRTC connection can roam between networks. This example restarts ICE in a loop and prints the new addresses it uses each time.
  • ICE Single Port Example ice-single-port demonstrates how multiple WebRTC connections can be served from a single port. By default Pion listens on a new port for every PeerConnection. Pion can be configured to use a single port for multiple connections.
  • ICE TCP Example ice-tcp demonstrates how a WebRTC connection can be made over TCP instead of UDP. By default Pion only does UDP. Pion can be configured to use a TCP port, and this TCP port can be used for many connections.
  • Trickle ICE Example trickle-ice example demonstrates Pion WebRTC's Trickle ICE APIs. This is important to use since it allows ICE Gathering and Connecting to happen concurrently.
  • VNet Example vnet demonstrates Pion's network virtualisation library. This example connects two PeerConnections over a virtual network and prints statistics about the data traveling over it.

Usage

We've made it easy to run the browser based examples on your local machine.

  1. Build and run the example server:

    GO111MODULE=on go get github.com/sepehrEslami81/webrtc/v3
    git clone https://github.com/pion/webrtc.git $GOPATH/src/github.com/pion/webrtc
    cd $GOPATH/src/github.com/pion/webrtc/examples
    go run examples.go
    
  2. Browse to localhost to browse through the examples. Note that you can change the port of the server using the --address flag:

    go run examples.go --address localhost:8080
    go run examples.go --address :8080            # listen on all available interfaces
    

WebAssembly

Pion WebRTC can be used when compiled to WebAssembly, also known as WASM. In this case the library will act as a wrapper around the JavaScript WebRTC API. This allows you to use WebRTC from Go in both server and browser side code with little to no changes

Some of our examples have support for WebAssembly. The same examples server documented above can be used to run the WebAssembly examples. However, you have to compile them first. This is done as follows:

  1. If the example supports WebAssembly it will contain a main.go file under the jsfiddle folder.
  2. Build this main.go file as follows:
    GOOS=js GOARCH=wasm go build -o demo.wasm
    
  3. Start the example server. Refer to the usage section for how you can build the example server.
  4. Browse to localhost. The page should now give you the option to run the example using the WebAssembly binary.

Documentation

Overview

HTTP server that demonstrates Pion WebRTC examples

Directories

Path Synopsis
bandwidth-estimation-from-disk demonstrates how to use Pion's Bandwidth Estimation APIs.
bandwidth-estimation-from-disk demonstrates how to use Pion's Bandwidth Estimation APIs.
broadcast demonstrates how to broadcast a video to many peers, while only requiring the broadcaster to upload once.
broadcast demonstrates how to broadcast a video to many peers, while only requiring the broadcaster to upload once.
custom-logger is an example of how the Pion API provides an customizable logging API
custom-logger is an example of how the Pion API provides an customizable logging API
data-channels is a Pion WebRTC application that shows how you can send/recv DataChannel messages from a web browser
data-channels is a Pion WebRTC application that shows how you can send/recv DataChannel messages from a web browser
data-channels-detach is an example that shows how you can detach a data channel.
data-channels-detach is an example that shows how you can detach a data channel.
data-channels-flow-control demonstrates how to use the DataChannel congestion control APIs
data-channels-flow-control demonstrates how to use the DataChannel congestion control APIs
ice-restart demonstrates Pion WebRTC's ICE Restart abilities.
ice-restart demonstrates Pion WebRTC's ICE Restart abilities.
ice-single-port demonstrates Pion WebRTC's ability to serve many PeerConnections on a single port.
ice-single-port demonstrates Pion WebRTC's ability to serve many PeerConnections on a single port.
ice-tcp demonstrates Pion WebRTC's ICE TCP abilities.
ice-tcp demonstrates Pion WebRTC's ICE TCP abilities.
insertable-streams demonstrates how to use insertable streams with Pion
insertable-streams demonstrates how to use insertable streams with Pion
internal
signal
Package signal contains helpers to exchange the SDP session description between examples.
Package signal contains helpers to exchange the SDP session description between examples.
ortc demonstrates Pion WebRTC's ORTC capabilities.
ortc demonstrates Pion WebRTC's ORTC capabilities.
pion-to-pion
answer
pion-to-pion is an example of two pion instances communicating directly!
pion-to-pion is an example of two pion instances communicating directly!
offer
pion-to-pion is an example of two pion instances communicating directly!
pion-to-pion is an example of two pion instances communicating directly!
play-from-disk demonstrates how to send video and/or audio to your browser from files saved to disk.
play-from-disk demonstrates how to send video and/or audio to your browser from files saved to disk.
play-from-disk-renegotiation demonstrates Pion WebRTC's renegotiation abilities.
play-from-disk-renegotiation demonstrates Pion WebRTC's renegotiation abilities.
reflect demonstrates how with one PeerConnection you can send video to Pion and have the packets sent back
reflect demonstrates how with one PeerConnection you can send video to Pion and have the packets sent back
rtcp-processing demonstrates the Public API for processing RTCP packets in Pion WebRTC.
rtcp-processing demonstrates the Public API for processing RTCP packets in Pion WebRTC.
rtp-forwarder shows how to forward your webcam/microphone via RTP using Pion WebRTC.
rtp-forwarder shows how to forward your webcam/microphone via RTP using Pion WebRTC.
rtp-to-webrtc demonstrates how to consume a RTP stream video UDP, and then send to a WebRTC client.
rtp-to-webrtc demonstrates how to consume a RTP stream video UDP, and then send to a WebRTC client.
save-to-disk is a simple application that shows how to record your webcam/microphone using Pion WebRTC and save VP8/Opus to disk.
save-to-disk is a simple application that shows how to record your webcam/microphone using Pion WebRTC and save VP8/Opus to disk.
save-to-disk-av1 is a simple application that shows how to save a video to disk using AV1.
save-to-disk-av1 is a simple application that shows how to save a video to disk using AV1.
simulcast demonstrates of how to handle incoming track with multiple simulcast rtp streams and show all them back.
simulcast demonstrates of how to handle incoming track with multiple simulcast rtp streams and show all them back.
stats demonstrates how to use the webrtc-stats implementation provided by Pion WebRTC.
stats demonstrates how to use the webrtc-stats implementation provided by Pion WebRTC.
swap-tracks demonstrates how to swap multiple incoming tracks on a single outgoing track.
swap-tracks demonstrates how to swap multiple incoming tracks on a single outgoing track.
trickle-ice demonstrates Pion WebRTC's Trickle ICE APIs.
trickle-ice demonstrates Pion WebRTC's Trickle ICE APIs.
vnet
show-network-usage
show-network-usage shows the amount of packets flowing through the vnet
show-network-usage shows the amount of packets flowing through the vnet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL