Skip to content

Commit b352467

Browse files
committed
Update http example to use dynamic ip and port
1 parent 0c61817 commit b352467

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

examples/http/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go get github.com/pion/mediadevices/examples/http
88

99
### Run HTTP server
1010

11-
Run `http`
11+
Run `http :1313`
1212

1313

1414
### Access the camera stream from the browser

examples/http/main.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"mime/multipart"
1212
"net/http"
1313
"net/textproto"
14+
"os"
1415

1516
"github.com/pion/mediadevices"
1617
"github.com/pion/mediadevices/pkg/prop"
@@ -28,16 +29,23 @@ func must(err error) {
2829
}
2930

3031
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{
3239
Video: func(constraint *mediadevices.MediaTrackConstraints) {
3340
constraint.Width = prop.Int(600)
3441
constraint.Height = prop.Int(400)
3542
},
3643
})
3744
must(err)
3845

39-
t := s.GetVideoTracks()[0]
40-
videoTrack := t.(*mediadevices.VideoTrack)
46+
track := mediaStream.GetVideoTracks()[0]
47+
videoTrack := track.(*mediadevices.VideoTrack)
48+
defer videoTrack.Close()
4149

4250
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
4351
var buf bytes.Buffer
@@ -72,6 +80,6 @@ func main() {
7280
}
7381
})
7482

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))
7785
}

0 commit comments

Comments
 (0)