Can specify a time before auto-restart

This commit is contained in:
Pierre HUBERT 2020-04-12 17:24:49 +02:00
parent 98875aa47d
commit a98a65936f
5 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -6,4 +6,9 @@ secure: false
hostname: 127.0.0.1
port: 3000
path: /rtc_proxy/ws
token: SecretToken
token: SecretToken
# Number of seconds to wait before automatically
# closing the proxy (if WebSocket connection was
# interrupted)
restart: 0

10
main.go
View File

@ -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))
}

View File

@ -388,6 +388,7 @@ func newCall(mainOffer receivedSignal, r *activeRelay) {
}
}()
// Enter messags loop
for {
// Receive new channels

3
ws.go
View File

@ -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()