From a6b6bd2ccd1391ce3438331c306dbf71efd6a137 Mon Sep 17 00:00:00 2001 From: giongto35 Date: Wed, 10 Apr 2019 03:33:21 +0800 Subject: [PATCH] Clean room with no sessions --- main.go | 2 ++ ui/director.go | 1 - webrtc/webrtc.go | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 04782ce5..fb488b29 100644 --- a/main.go +++ b/main.go @@ -227,12 +227,14 @@ func fanoutScreen(imageChannel chan *image.RGBA, roomID string) { // encode frame // fanout imageChannel if webRTC.IsConnected() { + // NOTE: can block here webRTC.ImageChannel <- yuv } isRoomRunning = true } if isRoomRunning == false { + log.Println("Closed room", roomID) rooms[roomID].closedChannel <- true } } diff --git a/ui/director.go b/ui/director.go index ee6194e9..3a6f3e6e 100644 --- a/ui/director.go +++ b/ui/director.go @@ -69,7 +69,6 @@ L: select { // if there is event from close channel => the game is ended case <-d.closedChannel: - log.Println("Closed game") break L default: } diff --git a/webrtc/webrtc.go b/webrtc/webrtc.go index 44ecefd7..6641606f 100644 --- a/webrtc/webrtc.go +++ b/webrtc/webrtc.go @@ -185,6 +185,10 @@ func (w *WebRTC) StartClient(remoteSession string, width, height int) (string, e // Input is key state, represented as binary string, 1001011. We compress it to binary number w.InputChannel <- i }) + + d.OnClose(func() { + w.isClosed = true + }) }) offer := webrtc.SessionDescription{} @@ -224,7 +228,7 @@ func (w *WebRTC) StopClient() { w.connection.Close() } w.connection = nil - w.isClosed = true + //w.isClosed = true } // IsConnected comment