mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 09:12:19 +00:00
Load SRT host and port from configuration
This commit is contained in:
parent
c905eadc78
commit
29eeb2c0fd
@ -30,4 +30,7 @@ web:
|
||||
widgetURL: https://example.com/
|
||||
|
||||
srt:
|
||||
listenAddress: 127.0.0.1:9710
|
||||
listenAddress: 127.0.0.1:9710
|
||||
|
||||
# Max number of active SRT connections
|
||||
maxClients: 64
|
||||
|
1
main.go
1
main.go
@ -49,6 +49,7 @@ func loadConfiguration() {
|
||||
viper.SetDefault("Auth.LDAP.UserDn", "cn=users,dc=example,dc=com")
|
||||
viper.SetDefault("Monitoring.ListenAddress", ":2112")
|
||||
viper.SetDefault("Srt.ListenAddress", ":9710")
|
||||
viper.SetDefault("Srt.MaxClients", "64")
|
||||
viper.SetDefault("Web.ListenAddress", ":8080")
|
||||
viper.SetDefault("Web.Name", "Ghostream")
|
||||
viper.SetDefault("Web.Hostname", "localhost")
|
||||
|
@ -2,6 +2,8 @@ package srt
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/haivision/srtgo"
|
||||
"github.com/pion/rtp"
|
||||
@ -10,18 +12,34 @@ import (
|
||||
// Options holds web package configuration
|
||||
type Options struct {
|
||||
ListenAddress string
|
||||
MaxClients int
|
||||
}
|
||||
|
||||
// Split host and port from listen address
|
||||
func splitHostPort(hostport string) (string, uint16) {
|
||||
host, portS, err := net.SplitHostPort(hostport)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to split host and port from %s", hostport)
|
||||
}
|
||||
if host == "" {
|
||||
host = "0.0.0.0"
|
||||
}
|
||||
port64, err := strconv.ParseUint(portS, 10, 16)
|
||||
if err != nil {
|
||||
log.Fatalf("Port is not a integer: %s", err)
|
||||
}
|
||||
return host, uint16(port64)
|
||||
}
|
||||
|
||||
// Serve SRT server
|
||||
func Serve(cfg *Options) {
|
||||
log.Printf("SRT server listening on %s", cfg.ListenAddress)
|
||||
|
||||
options := make(map[string]string)
|
||||
options["transtype"] = "live"
|
||||
|
||||
// FIXME: cfg.ListenAddress -> host and port
|
||||
sck := srtgo.NewSrtSocket("0.0.0.0", 9710, options)
|
||||
sck.Listen(1)
|
||||
log.Printf("SRT server listening on %s", cfg.ListenAddress)
|
||||
host, port := splitHostPort(cfg.ListenAddress)
|
||||
sck := srtgo.NewSrtSocket(host, uint16(port), options)
|
||||
sck.Listen(cfg.MaxClients)
|
||||
|
||||
for {
|
||||
s, err := sck.Accept()
|
||||
|
Loading…
Reference in New Issue
Block a user