-
Notifications
You must be signed in to change notification settings - Fork 0
/
publisher.js
executable file
·49 lines (36 loc) · 1002 Bytes
/
publisher.js
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
import { WHIPClient } from "whip"
import sdpParser from '@millicast/sdk/src/utils/SdpParser'
class PeerConnection extends RTCPeerConnection {
constructor({simulcast}) {
super();
this.simulcast = simulcast
}
async createOffer() {
let offer = await super.createOffer();
if (this.simulcast){
offer.sdp = sdpParser.setSimulcast(offer.sdp, 'h264')
}
return offer
}
}
const publisher = async ({url, token, simulcast}) => {
//Get mic+cam
const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
const video = document.getElementById("whip")
video.srcObject = stream
video.muted = true
video.play()
//Create peerconnection
const pc = new PeerConnection({simulcast});
//Send all tracks
for (const track of stream.getTracks()) {
//You could add simulcast too here
pc.addTrack(track);
}
//Create whip client
const whip = new WHIPClient();
//Start publishing
await whip.publish(pc, url, token);
return
}
export default publisher;