mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-21 17:18:47 +00:00
client closes peerconnection
This commit is contained in:
parent
8c4f6f624e
commit
2a782100a0
4 changed files with 25 additions and 5 deletions
|
|
@ -24,6 +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
|
||||
director := Director{}
|
||||
director.Done = make(chan struct{})
|
||||
director.audioChannel = audioChannel
|
||||
|
|
|
|||
|
|
@ -130,6 +130,10 @@ func (view *GameView) Exit() {
|
|||
if cartridge.Battery != 0 {
|
||||
writeSRAM(sramPath(view.saveFile), cartridge.SRAM)
|
||||
}
|
||||
|
||||
// close producer
|
||||
close(view.imageChannel)
|
||||
close(view.audioChannel)
|
||||
}
|
||||
|
||||
// Update is called for every period of time, dt is the elapsed time from the last frame
|
||||
|
|
|
|||
|
|
@ -107,10 +107,22 @@ func (h *Handler) WS(w http.ResponseWriter, r *http.Request) {
|
|||
}, nil)
|
||||
|
||||
wssession.BrowserClient.Listen()
|
||||
|
||||
// TODO: Use callback
|
||||
// listen to socket done to close peerconnection
|
||||
go func() {
|
||||
for {
|
||||
<-client.Done
|
||||
h.detachPeerConn(wssession.peerconnection)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
// Detach peerconnection detach/remove a peerconnection from current room
|
||||
func (h *Handler) detachPeerConn(pc *webrtc.WebRTC) {
|
||||
log.Println("Detach peerconnection")
|
||||
roomID := pc.RoomID
|
||||
room := h.getRoom(roomID)
|
||||
if room == nil {
|
||||
|
|
|
|||
|
|
@ -171,12 +171,15 @@ func (r *Room) removeSession(w *webrtc.WebRTC) {
|
|||
}
|
||||
|
||||
func (r *Room) Close() {
|
||||
log.Println("Closing room", r.ID)
|
||||
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
|
||||
}
|
||||
r.Done = true
|
||||
log.Println("Closing director of room ", r.ID)
|
||||
close(r.director.Done)
|
||||
log.Println("Closing input of room ", r.ID)
|
||||
close(r.inputChannel)
|
||||
// Close here is a bit wrong because this read channel
|
||||
//close(r.imageChannel)
|
||||
//close(r.audioChannel)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue