diff --git a/doc/CHANNELING-API.txt b/doc/CHANNELING-API.txt index 1d4e03be..3dc19aa4 100644 --- a/doc/CHANNELING-API.txt +++ b/doc/CHANNELING-API.txt @@ -248,6 +248,20 @@ Special purpose documents for channling themselves. Note that acceptable characters for this field may be constrained by the server based upon its configuration. + Leave + + { + Type: "Leave", + Leave: {...} + } + + A Leave document is to be sent by the client if a previously room should be + left. Note that no confirmation will be returned by the server. + + Keys under Leave: + + Currently none. + Room { diff --git a/go/channelling/api/api.go b/go/channelling/api/api.go index ed020385..854dcb90 100644 --- a/go/channelling/api/api.go +++ b/go/channelling/api/api.go @@ -188,6 +188,11 @@ func (api *channellingAPI) OnIncoming(sender channelling.Sender, session *channe } return api.HandleRoom(session, msg.Room) + case "Leave": + if err := api.HandleLeave(session); err != nil { + return nil, err + } + return nil, nil default: log.Println("OnText unhandled message type", msg.Type) } diff --git a/go/channelling/api/handle_leave.go b/go/channelling/api/handle_leave.go new file mode 100644 index 00000000..efef8899 --- /dev/null +++ b/go/channelling/api/handle_leave.go @@ -0,0 +1,32 @@ +/* + * Spreed WebRTC. + * Copyright (C) 2013-2016 struktur AG + * + * This file is part of Spreed WebRTC. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +package api + +import ( + "github.com/strukturag/spreed-webrtc/go/channelling" +) + +func (api *channellingAPI) HandleLeave(session *channelling.Session) error { + session.LeaveRoom() + + return nil +} diff --git a/go/channelling/session.go b/go/channelling/session.go index e7032290..7ac01164 100644 --- a/go/channelling/session.go +++ b/go/channelling/session.go @@ -129,16 +129,7 @@ func (s *Session) JoinRoom(roomName, roomType string, credentials *DataRoomCrede defer s.mutex.Unlock() if s.Hello && s.Roomid != roomID { - s.RoomStatusManager.LeaveRoom(s.Roomid, s.Id) - s.Broadcaster.Broadcast(s.Id, s.Roomid, &DataOutgoing{ - From: s.Id, - A: s.attestation.Token(), - Data: &DataSession{ - Type: "Left", - Id: s.Id, - Status: "soft", - }, - }) + s.doLeaveRoom("soft") } room, err := s.RoomStatusManager.JoinRoom(roomID, roomName, roomType, credentials, s, s.authenticated(), sender) @@ -164,6 +155,31 @@ func (s *Session) JoinRoom(roomName, roomType string, credentials *DataRoomCrede return room, err } +func (s *Session) doLeaveRoom(status string) { + s.RoomStatusManager.LeaveRoom(s.Roomid, s.Id) + s.Broadcaster.Broadcast(s.Id, s.Roomid, &DataOutgoing{ + From: s.Id, + A: s.attestation.Token(), + Data: &DataSession{ + Type: "Left", + Id: s.Id, + Status: status, + }, + }) + s.Hello = false +} + +func (s *Session) LeaveRoom() { + s.mutex.Lock() + defer s.mutex.Unlock() + + if !s.Hello { + return + } + + s.doLeaveRoom("soft") +} + func (s *Session) Broadcast(m interface{}) { s.mutex.RLock() if s.Hello {