-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
47 lines (39 loc) · 1.01 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
package main
import (
"log"
"net/http"
"strconv"
"github.com/bezineb5/go-h264-streamer/stream"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
const (
staticDir = "static"
staticURL = "/static"
videoWebsocketURL = "/stream"
port = 8080
width = 960
height = 540
fps = 30
)
func main() {
options := stream.CameraOptions{
Width: width,
Height: height,
Fps: fps,
HorizontalFlip: true,
VerticalFlip: true,
Rotation: 0,
UseLibcamera: false,
}
router := mux.NewRouter()
// Websocket
connectionNumber := make(chan int, 2)
wsh := NewWebSocketHandler(connectionNumber)
router.HandleFunc(videoWebsocketURL, wsh.Handler)
go stream.Video(options, wsh, connectionNumber)
// Static
fs := http.FileServer(http.Dir(staticDir))
router.PathPrefix(staticURL).Handler(handlers.CompressHandler(http.StripPrefix(staticURL, fs)))
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), router))
}