|
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 |
4 | 2 |
|
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. |
6 | 14 |
|
7 | 15 | ## Instructions |
8 | 16 |
|
9 | | -### Download whip-whep |
| 17 | +### Download the example |
10 | 18 |
|
11 | 19 | This example requires you to clone the repo since it is serving static HTML. |
12 | 20 |
|
13 | 21 | ``` |
14 | 22 | git clone https://github.com/pion/webrtc.git |
15 | | -cd webrtc/examples/whip-whep |
| 23 | +cd webrtc/examples/data-channels-whip-whep-like |
16 | 24 | ``` |
17 | 25 |
|
18 | | -### Run whip-whep |
| 26 | +### Run the server |
19 | 27 | Execute `go run *.go` |
20 | 28 |
|
21 | | -### Publish |
| 29 | +### Connect and chat |
22 | 30 |
|
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 |
24 | 36 |
|
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 |
26 | 38 |
|
| 39 | +## Why WHIP/WHEP for signaling? |
27 | 40 |
|
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. |
29 | 42 |
|
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. |
32 | 44 |
|
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". |
34 | 54 |
|
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 |
36 | 61 |
|
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. |
38 | 64 |
|
39 | 65 | For more info on WHIP/WHEP specification, feel free to read some of these great resources: |
40 | 66 | - https://webrtchacks.com/webrtc-cracks-the-whip-on-obs/ |
|
0 commit comments