diff --git a/config.go b/config.go index 530c98f..32602f0 100644 --- a/config.go +++ b/config.go @@ -16,6 +16,11 @@ type Config struct { Port int Path string Token string + + // Amount of time to wait before automatically + //quitting the application when the websocket + // connection was interrupted + Restart int } // Get the URL associated with the configuration diff --git a/config.yaml b/config.yaml index 03ff419..fab1894 100644 --- a/config.yaml +++ b/config.yaml @@ -6,4 +6,9 @@ secure: false hostname: 127.0.0.1 port: 3000 path: /rtc_proxy/ws -token: SecretToken \ No newline at end of file +token: SecretToken + +# Number of seconds to wait before automatically +# closing the proxy (if WebSocket connection was +# interrupted) +restart: 0 \ No newline at end of file diff --git a/main.go b/main.go index 31ae8f8..b0faf52 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,9 @@ package main import ( "fmt" + "log" "os" + "time" ) func main() { @@ -17,6 +19,14 @@ func main() { // First, load the config conf := loadConfig(os.Args[1]) + /// Avoid to quick restart loop + defer timeBeforeQuit(&conf) + // Then connect to websocket openWs(&conf) } + +func timeBeforeQuit(c *Config) { + log.Printf("Waiting %d seconds before quitting...", c.Restart) + time.Sleep(time.Second * time.Duration(c.Restart)) +} diff --git a/relay.go b/relay.go index a29d44f..7822a04 100644 --- a/relay.go +++ b/relay.go @@ -388,6 +388,7 @@ func newCall(mainOffer receivedSignal, r *activeRelay) { } }() + // Enter messags loop for { // Receive new channels diff --git a/ws.go b/ws.go index b955d15..ba5929f 100644 --- a/ws.go +++ b/ws.go @@ -36,7 +36,8 @@ func openWs(conf *Config) { // Connect to Websocket c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) if err != nil { - log.Fatal("dial:", err) + log.Println("dial:", err) + return } defer c.Close()