Quit room

This commit is contained in:
giongto35 2019-05-18 02:50:25 +08:00
parent f743fc5520
commit fdc83e12fb
5 changed files with 31 additions and 5 deletions

View file

@ -85,6 +85,20 @@ func (s *Session) RouteBrowser() {
return req
})
browserClient.Receive("quit", func(resp cws.WSPacket) (req cws.WSPacket) {
log.Println("Received quit", req)
s.GameName = resp.Data
s.RoomID = resp.RoomID
s.PlayerIndex = resp.PlayerIndex
room := s.handler.getRoom(s.RoomID)
if room.IsPCInRoom(s.peerconnection) {
s.handler.detachPeerConn(s.peerconnection)
}
return cws.EmptyPacket
})
browserClient.Receive("start", func(resp cws.WSPacket) (req cws.WSPacket) {
s.GameName = resp.Data
s.RoomID = resp.RoomID

View file

@ -176,6 +176,9 @@ func (r *Room) removeSession(w *webrtc.WebRTC) {
// TODO: Reuse for remove Session
func (r *Room) IsPCInRoom(w *webrtc.WebRTC) bool {
if r == nil {
return false
}
for _, s := range r.rtcSessions {
if s.ID == w.ID {
return true