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"
|
2022-11-07 09:55:04 +00:00
|
|
|
"github.com/kixelated/warp-demo/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
|
|
|
}
|
|
|
|
|
2022-06-29 16:17:02 +00:00
|
|
|
config := warp.ServerConfig{
|
2022-11-07 09:55:04 +00:00
|
|
|
Addr: *addr,
|
|
|
|
Cert: &tlsCert,
|
|
|
|
LogDir: *logDir,
|
2022-06-29 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ws, err := warp.NewServer(config, media)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create warp server: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("listening on %s", *addr)
|
|
|
|
|
|
|
|
return invoker.Run(ctx, invoker.Interrupt, ws.Run)
|
|
|
|
}
|