-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (36 loc) · 1.03 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
package main
import (
"fmt"
"github.com/connerdouglass/livestream-rtmp/api"
"github.com/connerdouglass/livestream-rtmp/hlsserver"
"github.com/connerdouglass/livestream-rtmp/rtmp"
"github.com/joho/godotenv"
)
func main() {
// Load the .env file
if err := godotenv.Load(); err != nil {
fmt.Println("Error loading .env file: ", err)
}
// Create the livestream-api client
apiClient := &api.Client{
Hostname: EnvOrDefault("API_HOSTNAME", "http://localhost:8080"),
RtmpPasscode: RequireEnv("API_PASSCODE"),
}
// Create the handler factory
handlerFactory := &rtmp.HlsStreamHandlerFactory{
WorkDir: "./hlsdata",
}
// Create the RTMP server
rtmpServer := rtmp.Server{
Address: EnvOrDefault("RTMP_ADDR", ":1935"),
Api: apiClient,
NewStreamHandler: handlerFactory.NewHandler,
}
hlsServer := &hlsserver.Server{
HlsFactory: handlerFactory,
EnablePlayer: true,
}
go hlsServer.Run(EnvOrDefault("HLS_ADDR", ":8081"))
// Run the RTMP server. This blocks the main goroutine
rtmpServer.Run()
}