mirror of
https://gitlab.com/comunic/ComunicRTCProxy
synced 2024-12-25 21:18:53 +00:00
Can specify a time before auto-restart
This commit is contained in:
parent
98875aa47d
commit
a98a65936f
@ -16,6 +16,11 @@ type Config struct {
|
|||||||
Port int
|
Port int
|
||||||
Path string
|
Path string
|
||||||
Token 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
|
// Get the URL associated with the configuration
|
||||||
|
@ -6,4 +6,9 @@ secure: false
|
|||||||
hostname: 127.0.0.1
|
hostname: 127.0.0.1
|
||||||
port: 3000
|
port: 3000
|
||||||
path: /rtc_proxy/ws
|
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
10
main.go
@ -2,7 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -17,6 +19,14 @@ func main() {
|
|||||||
// First, load the config
|
// First, load the config
|
||||||
conf := loadConfig(os.Args[1])
|
conf := loadConfig(os.Args[1])
|
||||||
|
|
||||||
|
/// Avoid to quick restart loop
|
||||||
|
defer timeBeforeQuit(&conf)
|
||||||
|
|
||||||
// Then connect to websocket
|
// Then connect to websocket
|
||||||
openWs(&conf)
|
openWs(&conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func timeBeforeQuit(c *Config) {
|
||||||
|
log.Printf("Waiting %d seconds before quitting...", c.Restart)
|
||||||
|
time.Sleep(time.Second * time.Duration(c.Restart))
|
||||||
|
}
|
||||||
|
1
relay.go
1
relay.go
@ -388,6 +388,7 @@ func newCall(mainOffer receivedSignal, r *activeRelay) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Enter messags loop
|
||||||
for {
|
for {
|
||||||
|
|
||||||
// Receive new channels
|
// Receive new channels
|
||||||
|
3
ws.go
3
ws.go
@ -36,7 +36,8 @@ func openWs(conf *Config) {
|
|||||||
// Connect to Websocket
|
// Connect to Websocket
|
||||||
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("dial:", err)
|
log.Println("dial:", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user