forked from ggarber/whip-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (40 loc) · 1.24 KB
/
main.go
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
package main
import (
"bufio"
"fmt"
"log"
"os"
"github.com/pion/mediadevices"
"github.com/pion/mediadevices/pkg/codec/vpx"
_ "github.com/pion/mediadevices/pkg/driver/screen" // This is required to register screen adapter
"github.com/pion/webrtc/v3"
)
func main() {
if len(os.Args) < 3 {
log.Fatal("Invalid number of arguments, pass endpoint url (and optionally a token)")
}
//get the media here
// configure codec specific parameters
vpxParams, _ := vpx.NewVP8Params()
vpxParams.BitRate = 1_000_000 // 1mbps
codecSelector := mediadevices.NewCodecSelector(
mediadevices.WithVideoEncoders(&vpxParams),
)
stream, err := mediadevices.GetDisplayMedia(mediadevices.MediaStreamConstraints{
Video: func(constraint *mediadevices.MediaTrackConstraints) {},
Codec: codecSelector,
})
if err != nil {
log.Fatal("Unexpected error capturing screen. ", err)
}
mediaEngine := webrtc.MediaEngine{}
codecSelector.Populate(&mediaEngine)
// mediaEngine.RegisterDefaultCodecs()
//pass it into the whip client
iceServers := []webrtc.ICEServer{}
whip := NewWHIPClient(os.Args[1], os.Args[2])
whip.Publish(stream, mediaEngine, iceServers, false)
fmt.Print("Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
whip.Close()
}