2022-06-29 16:17:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-11-07 09:55:04 +00:00
|
|
|
"crypto/tls"
|
2022-06-29 16:17:02 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/kixelated/invoker"
|
2023-03-26 19:35:33 +00:00
|
|
|
"github.com/kixelated/warp/server/internal/warp"
|
2022-06-29 16:17:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := run(context.Background())
|
2022-12-05 22:07:58 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2022-06-29 16:17:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(ctx context.Context) (err error) {
|
2022-11-18 23:13:35 +00:00
|
|
|
addr := flag.String("addr", ":4443", "HTTPS server address")
|
2022-11-09 23:03:44 +00:00
|
|
|
cert := flag.String("tls-cert", "../cert/localhost.crt", "TLS certificate file path")
|
|
|
|
key := flag.String("tls-key", "../cert/localhost.key", "TLS certificate file path")
|
2022-06-29 16:17:02 +00:00
|
|
|
logDir := flag.String("log-dir", "", "logs will be written to the provided directory")
|
|
|
|
|
2022-11-09 23:03:44 +00:00
|
|
|
dash := flag.String("dash", "../media/playlist.mpd", "DASH playlist path")
|
2022-06-29 16:17:02 +00:00
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
media, err := warp.NewMedia(*dash)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to open media: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-11-09 23:03:44 +00:00
|
|
|
tlsCert, err := tls.LoadX509KeyPair(*cert, *key)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to load TLS certificate: %w", err)
|
2022-11-07 09:55:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-26 19:35:33 +00:00
|
|
|
warpConfig := warp.Config{
|
2022-11-07 09:55:04 +00:00
|
|
|
Addr: *addr,
|
|
|
|
Cert: &tlsCert,
|
|
|
|
LogDir: *logDir,
|
2023-03-26 19:35:33 +00:00
|
|
|
Media: media,
|
2022-06-29 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2023-03-26 19:35:33 +00:00
|
|
|
warpServer, err := warp.New(warpConfig)
|
2022-06-29 16:17:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create warp server: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("listening on %s", *addr)
|
|
|
|
|
2023-04-13 20:34:34 +00:00
|
|
|
return invoker.Run(ctx, invoker.Interrupt, warpServer.Run)
|
2022-06-29 16:17:02 +00:00
|
|
|
}
|