Skip to content

Commit abef201

Browse files
committed
Update readme
1 parent a2522f7 commit abef201

File tree

1 file changed

+42
-16
lines changed
  • examples/data-channels-whip-whep-like

1 file changed

+42
-16
lines changed

examples/data-channels-whip-whep-like/README.md

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,66 @@
1-
# whip-whep
2-
whip-whep demonstrates using WHIP and WHEP with Pion. Since WHIP+WHEP is standardized signaling you can publish via tools like OBS and GStreamer.
3-
You can then watch it in sub-second time from your browser, or pull the video back into OBS and GStreamer via WHEP.
1+
# whip-whep-like
42

5-
Further details about the why and how of WHIP+WHEP are below the instructions.
3+
This example demonstrates a WHIP/WHEP-like implementation using Pion WebRTC with DataChannel support for real-time chat.
4+
5+
**Note:** This is similar to but not exactly WHIP/WHEP, as the official WHIP/WHEP specifications focus on media streaming only and do not include DataChannel support. This example extends the WHIP/WHEP pattern to demonstrate peer-to-peer chat functionality with automatic username assignment and message broadcasting.
6+
7+
Key features:
8+
- **Real-time chat** with WebRTC DataChannels
9+
- **Automatic username generation** - Each user gets a unique random username (e.g., SneakyBear46)
10+
- **Message broadcasting** - All connected users receive messages from everyone else
11+
- **WHIP/WHEP-like signaling** - Simple HTTP-based signaling for easy integration
12+
13+
Further details about WHIP+WHEP and the WebRTC DataChannel implementation are below the instructions.
614

715
## Instructions
816

9-
### Download whip-whep
17+
### Download the example
1018

1119
This example requires you to clone the repo since it is serving static HTML.
1220

1321
```
1422
git clone https://github.com/pion/webrtc.git
15-
cd webrtc/examples/whip-whep
23+
cd webrtc/examples/data-channels-whip-whep-like
1624
```
1725

18-
### Run whip-whep
26+
### Run the server
1927
Execute `go run *.go`
2028

21-
### Publish
29+
### Connect and chat
2230

23-
You can publish via an tool that supports WHIP or via your browser. To publish via your browser open [http://localhost:8080](http://localhost:8080), and press publish.
31+
1. Open [http://localhost:8080](http://localhost:8080) in your browser
32+
2. Click "Publish" or "Subscribe" to establish a DataChannel connection
33+
3. You'll be assigned a random username (e.g., "SneakyBear46")
34+
4. Type a message and click "Send Message" to broadcast to all connected users
35+
5. Open multiple tabs/windows to test multi-user chat
2436

25-
To publish via OBS set `Service` to `WHIP` and `Server` to `http://localhost:8080/whip`. The `Bearer Token` can be whatever value you like.
37+
Congrats, you have used Pion WebRTC! Now start building something cool
2638

39+
## Why WHIP/WHEP for signaling?
2740

28-
### Subscribe
41+
This example uses a WHIP/WHEP-like signaling approach where an Offer is uploaded via HTTP and the server responds with an Answer. This simple API contract makes it easy to integrate WebRTC into web applications.
2942

30-
Once you have started publishing open [http://localhost:8080](http://localhost:8080) and press the subscribe button. You can now view your video you published via
31-
OBS or your browser.
43+
**Difference from standard WHIP/WHEP:** The official WHIP/WHEP specifications are designed for media streaming (audio/video) only. This example extends that pattern to include DataChannel support for real-time chat functionality.
3244

33-
Congrats, you have used Pion WebRTC! Now start building something cool
45+
## Implementation details
46+
47+
### Username generation
48+
Each connected user is automatically assigned a unique username combining:
49+
- An adjective (e.g., Sneaky, Brave, Quick)
50+
- An animal noun (e.g., Bear, Fox, Eagle)
51+
- A random number (0-999)
52+
53+
This creates usernames like "SneakyBear46" or "BraveFox789".
3454

35-
## Why WHIP/WHEP?
55+
### Message broadcasting
56+
The server maintains a broadcast hub that:
57+
- Registers all connected DataChannels
58+
- Associates each channel with a unique username
59+
- Broadcasts every message to all connected users (including the sender)
60+
- Automatically cleans up when users disconnect
3661

37-
WHIP/WHEP mandates that a Offer is uploaded via HTTP. The server responds with a Answer. With this strong API contract WebRTC support can be added to tools like OBS.
62+
### Thread safety
63+
All hub operations use `sync.RWMutex` to ensure thread-safe access to the connection map and username mapping.
3864

3965
For more info on WHIP/WHEP specification, feel free to read some of these great resources:
4066
- https://webrtchacks.com/webrtc-cracks-the-whip-on-obs/

0 commit comments

Comments
 (0)