From 58b49131b2e00cd2e0ec448361c35ecb9bd56e03 Mon Sep 17 00:00:00 2001 From: giongto35 Date: Sun, 12 May 2019 18:15:04 +0800 Subject: [PATCH 1/2] Remove unncessary --- emulator/nes/console.go | 6 +++--- handler/handlers.go | 2 +- handler/overlord.go | 3 +-- handler/room/room.go | 18 +++++++++--------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/emulator/nes/console.go b/emulator/nes/console.go index 08088e68..2dbd0d11 100644 --- a/emulator/nes/console.go +++ b/emulator/nes/console.go @@ -51,9 +51,9 @@ func (console *Console) Step() int { console.PPU.Step() console.Mapper.Step() } - //for i := 0; i < cpuCycles; i++ { - //console.APU.Step() - //} + for i := 0; i < cpuCycles; i++ { + console.APU.Step() + } return cpuCycles } diff --git a/handler/handlers.go b/handler/handlers.go index 00a942bf..c2a536f4 100644 --- a/handler/handlers.go +++ b/handler/handlers.go @@ -109,7 +109,7 @@ func (h *Handler) WS(w http.ResponseWriter, r *http.Request) { wssession.BrowserClient.Listen() // TODO: Use callback - // listen to socket done to close peerconnection + // If peerconnection is done (client.Done is signalled), we close peerconnection go func() { for { <-client.Done diff --git a/handler/overlord.go b/handler/overlord.go index 29a4b9dd..ee353120 100644 --- a/handler/overlord.go +++ b/handler/overlord.go @@ -75,9 +75,8 @@ func (s *Session) RouteOverlord() { "start", func(resp cws.WSPacket) (req cws.WSPacket) { log.Println("Received a start request from overlord") - log.Println("Add the connection to current room on the host") + log.Println("Add the connection to current room on the host ", resp.SessionID) - log.Println("SessionID : ", resp.SessionID) peerconnection := oclient.peerconnections[resp.SessionID] log.Println("start session") diff --git a/handler/room/room.go b/handler/room/room.go index 953bc743..deddca6f 100644 --- a/handler/room/room.go +++ b/handler/room/room.go @@ -148,9 +148,8 @@ func (r *Room) CleanSession(peerconnection *webrtc.WebRTC) { func (r *Room) removeSession(w *webrtc.WebRTC) { fmt.Println("Cleaning session: ", w) - //r.sessionsLock.Lock() - //defer r.sessionsLock.Unlock() fmt.Println("Sessions list", r.rtcSessions) + // TODO: get list of r.rtcSessions in lock for i, s := range r.rtcSessions { fmt.Println("found session: ", s, w) if s.ID == w.ID { @@ -171,14 +170,15 @@ func (r *Room) removeSession(w *webrtc.WebRTC) { } func (r *Room) Close() { - if r.Done == false { - log.Println("Closing room", r.ID) - log.Println("Closing director of room ", r.ID) - close(r.director.Done) - log.Println("Closing input of room ", r.ID) - close(r.inputChannel) - r.Done = true + if r.Done { + return } + + log.Println("Closing room", r.ID) + log.Println("Closing director of room ", r.ID) + close(r.director.Done) + log.Println("Closing input of room ", r.ID) + close(r.inputChannel) r.Done = true // Close here is a bit wrong because this read channel //close(r.imageChannel) From 6a05d4392849a8db76f112277ea9671b9a772d05 Mon Sep 17 00:00:00 2001 From: giongto35 Date: Sun, 12 May 2019 18:16:11 +0800 Subject: [PATCH 2/2] Add todo --- emulator/director.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emulator/director.go b/emulator/director.go index fda84e99..6eba51a5 100644 --- a/emulator/director.go +++ b/emulator/director.go @@ -24,7 +24,7 @@ type Director struct { const FPS = 60 func NewDirector(roomID string, imageChannel chan *image.RGBA, audioChannel chan float32, inputChannel chan int) *Director { - // return image channel from where it write + // TODO: return image channel from where it write director := Director{} director.Done = make(chan struct{}) director.audioChannel = audioChannel