-
Notifications
You must be signed in to change notification settings - Fork 2
/
readme.hbs
65 lines (48 loc) · 2.36 KB
/
readme.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[1]: https://blog.mozilla.org/webrtc/perfect-negotiation-in-webrtc/
# WHIP-WHAP-JS: WebRTC WHIP and WHAP using [Perfect Negotiation][1]
## Features
- Does *NOT* encapsulate RTCPeerConnection
- Small, simple code base
- Auto-retries WHIP/WHAP on WebRTC failure, or when iceConnectionState is "disconnected"
- Uses *Perfect Negotiation* for WHIP and WHAP as from the _Jan-Ivar Bruaroey_ article [here][1]
## WHIP
WHIP stands for WebRTC-HTTP ingestion protocol
It's an IETF draft, and you can learn more here:
https://github.com/wish-wg/webrtc-http-ingest-protocol
## WHAP
WHIP stands for WebRTC-HTTP access protocol
And this is the only place to learn about it for now.
It's similar to WHIP, but intended for receiving audio/video from WebRTC servers.
See the example below.
## WHIP Example
WHIP example: send camera to WHIP server.
```js
let url = '/pub'
let whipwhap = await import('https://cdn.jsdelivr.net/npm/whip-whap-js')
document.write('<video id="video1" autoplay controls muted width="1024" allowfullscreen/>')
let pc = new RTCPeerConnection({ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] })
pc.addEventListener('iceconnectionstatechange', whipwhap.handleIceStateChange)
pc.addEventListener('negotiationneeded', ev => whipwhap.handleNegotiationNeeded(ev, url))
let gum = await navigator.mediaDevices.getUserMedia({ audio: true, video: true })
pc.addTransceiver(gum.getVideoTracks()[0], { 'direction': 'sendonly' })
pc.addTransceiver(gum.getAudioTracks()[0], { 'direction': 'sendonly' })
let video1 = document.getElementById('video1')
video1.srcObject = gum
video1.play()
```
## WHAP Example
WHAP example: receive video/audio from WebRTC server to HTML video element.
```js
let url = '/sub'
let whipwhap = await import('https://cdn.jsdelivr.net/npm/whip-whap-js')
document.write('<video id="video1" autoplay controls muted width="1024" allowfullscreen/>')
let pc = new RTCPeerConnection({ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] })
pc.addTransceiver('video', { 'direction': 'recvonly' }) // build sdp
pc.addTransceiver('audio', { 'direction': 'recvonly' }) // build sdp
pc.addEventListener('iceconnectionstatechange', whipwhap.handleIceStateChange)
pc.addEventListener('negotiationneeded', ev => whipwhap.handleNegotiationNeeded(ev, url))
let video1 = document.getElementById('video1')
pc.ontrack = ev => video1.srcObject = ev.streams[0]
```
## Functions
{{>main}}