mirror of
https://gitlab.com/comunic/ComunicRTCProxy
synced 2025-02-23 09:31:16 +00:00
Automatically close websocket
This commit is contained in:
parent
c30af1b6d7
commit
a0f41fe2e1
12
ws.go
12
ws.go
@ -6,6 +6,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
@ -13,6 +15,10 @@ import (
|
|||||||
// Open websocket connection
|
// Open websocket connection
|
||||||
func openWs(conf *Config) {
|
func openWs(conf *Config) {
|
||||||
|
|
||||||
|
// Auto-close connection when the system request it
|
||||||
|
interrupt := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
|
|
||||||
u := conf.getURL()
|
u := conf.getURL()
|
||||||
log.Printf("Connecting to %s", u.String())
|
log.Printf("Connecting to %s", u.String())
|
||||||
|
|
||||||
@ -23,6 +29,12 @@ func openWs(conf *Config) {
|
|||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
|
// Wait for interrupt signal
|
||||||
|
go func() {
|
||||||
|
<-interrupt
|
||||||
|
c.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
// Read remote messages
|
// Read remote messages
|
||||||
for {
|
for {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user