@@ -11,6 +11,7 @@ import (
11
11
"mime/multipart"
12
12
"net/http"
13
13
"net/textproto"
14
+ "os"
14
15
15
16
"github.com/pion/mediadevices"
16
17
"github.com/pion/mediadevices/pkg/prop"
@@ -28,16 +29,23 @@ func must(err error) {
28
29
}
29
30
30
31
func main () {
31
- s , err := mediadevices .GetUserMedia (mediadevices.MediaStreamConstraints {
32
+ if len (os .Args ) != 2 {
33
+ fmt .Printf ("usage: %s host:port\n " , os .Args [0 ])
34
+ return
35
+ }
36
+ dest := os .Args [1 ]
37
+
38
+ mediaStream , err := mediadevices .GetUserMedia (mediadevices.MediaStreamConstraints {
32
39
Video : func (constraint * mediadevices.MediaTrackConstraints ) {
33
40
constraint .Width = prop .Int (600 )
34
41
constraint .Height = prop .Int (400 )
35
42
},
36
43
})
37
44
must (err )
38
45
39
- t := s .GetVideoTracks ()[0 ]
40
- videoTrack := t .(* mediadevices.VideoTrack )
46
+ track := mediaStream .GetVideoTracks ()[0 ]
47
+ videoTrack := track .(* mediadevices.VideoTrack )
48
+ defer videoTrack .Close ()
41
49
42
50
http .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
43
51
var buf bytes.Buffer
@@ -72,6 +80,6 @@ func main() {
72
80
}
73
81
})
74
82
75
- fmt .Println ("listening on http://localhost:1313" )
76
- log .Println (http .ListenAndServe ("localhost:1313" , nil ))
83
+ fmt .Printf ("listening on %s \n " , dest )
84
+ log .Println (http .ListenAndServe (dest , nil ))
77
85
}
0 commit comments