|
| 1 | +node-webrtc-examples |
| 2 | +==================== |
| 3 | + |
| 4 | +This project presents a few example applications using node-webrtc. |
| 5 | + |
| 6 | +- [audio-video-loopback](examples/audio-video-loopback): relays incoming audio |
| 7 | + and video using RTCRtpTransceivers. |
| 8 | +- [ping-pong](examples/ping-pong): simple RTCDataChannel ping/pong example. |
| 9 | +- [pitch-detector](examples/pitch-detector): pitch detector implemented using |
| 10 | + RTCAudioSink and RTCDataChannel. |
| 11 | +- [sine-wave](examples/sine-wave): generates a sine wave using RTCAudioSource; |
| 12 | + frequency control implemented using RTCDataChannel. |
| 13 | +- [sine-wave-stereo](examples/sine-wave-stereo): generates a stereo sine wave |
| 14 | + using RTCAudioSource; panning control implemented using RTCDataChannel. |
| 15 | +- [video-compositing](examples/video-compositing): uses RTCVideoSink, |
| 16 | + [node-canvas](https://github.com/Automattic/node-canvas), and RTCVideoSource |
| 17 | + to draw spinning text on top of an incoming video. |
| 18 | + |
| 19 | +Usage |
| 20 | +----- |
| 21 | + |
| 22 | +Install the project's dependencies and run the tests before starting the |
| 23 | +application server: |
| 24 | + |
| 25 | +``` |
| 26 | +npm install |
| 27 | +npm test |
| 28 | +npm start |
| 29 | +``` |
| 30 | + |
| 31 | +Then, navigate to [http://localhost:3000](http://localhost:3000). |
| 32 | + |
| 33 | +Architecture |
| 34 | +------------ |
| 35 | + |
| 36 | +Each example application under [examples/](examples) has a Client and Server |
| 37 | +component. RTCPeerConnection negotiation is supported via a REST API (described |
| 38 | +below), and is abstracted away from each example application. Code for |
| 39 | +RTCPeerConnection negotiation lives under [lib/](lib). |
| 40 | + |
| 41 | +### RTCPeerConnection Negotiation |
| 42 | + |
| 43 | +RTCPeerConnections are negotiated via REST API. The Server always offers (with |
| 44 | +host candidates) and the Client always answers. In order to negotiate a new |
| 45 | +RTCPeerConnection, the Client first POSTs to `/connections`. The Server responds |
| 46 | +with an RTCPeerConnection ID and SDP offer. Finally, the Client POSTs an SDP |
| 47 | +answer to the RTCPeerConnection's URL. |
| 48 | + |
| 49 | +``` |
| 50 | +Client Server |
| 51 | + | | |
| 52 | + | POST /connections | |
| 53 | + | | |
| 54 | + |---------------------------------------------------->| |
| 55 | + | | |
| 56 | + | 200 OK | |
| 57 | + | { "id": "$ID", "localDescription": "$SDP_OFFER" } | |
| 58 | + | | |
| 59 | + |<----------------------------------------------------| |
| 60 | + | | |
| 61 | + | POST /connections/$ID/remote-description | |
| 62 | + | $SDP_ANSWER | |
| 63 | + | | |
| 64 | + |---------------------------------------------------->| |
| 65 | + | | |
| 66 | + | 200 OK | |
| 67 | + | | |
| 68 | + |<----------------------------------------------------| |
| 69 | +``` |
| 70 | + |
| 71 | +### RTCPeerConnection Teardown |
| 72 | + |
| 73 | +RTCPeerConnections can be proactively torn down by sending a DELETE to the |
| 74 | +RTCPeerConnection's URL; otherwise, ICE disconnection or failure, if unresolved |
| 75 | +within the `timeToReconnect` window, will also trigger teardown. The default |
| 76 | +`timeToReconnect` value is 10 s. |
| 77 | + |
| 78 | +``` |
| 79 | +Client Server |
| 80 | + | | |
| 81 | + | DELETE /connections/$ID | |
| 82 | + | | |
| 83 | + |---------------------------------------------------->| |
| 84 | + | | |
| 85 | + | 200 OK | |
| 86 | + | | |
| 87 | + |<----------------------------------------------------| |
| 88 | +``` |
0 commit comments