Browse Source

Added API to leave a room.

Previously it was only possible to leave a room by switching to another
room. This change allows explicitly leaving a room without re-joining.
pull/301/head
Joachim Bauch 9 years ago
parent
commit
983c9b991f
  1. 14
      doc/CHANNELING-API.txt
  2. 5
      go/channelling/api/api.go
  3. 32
      go/channelling/api/handle_leave.go
  4. 36
      go/channelling/session.go

14
doc/CHANNELING-API.txt

@ -248,6 +248,20 @@ Special purpose documents for channling @@ -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
{

5
go/channelling/api/api.go

@ -188,6 +188,11 @@ func (api *channellingAPI) OnIncoming(sender channelling.Sender, session *channe @@ -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)
}

32
go/channelling/api/handle_leave.go

@ -0,0 +1,32 @@ @@ -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 <http://www.gnu.org/licenses/>.
*
*/
package api
import (
"github.com/strukturag/spreed-webrtc/go/channelling"
)
func (api *channellingAPI) HandleLeave(session *channelling.Session) error {
session.LeaveRoom()
return nil
}

36
go/channelling/session.go

@ -129,16 +129,7 @@ func (s *Session) JoinRoom(roomName, roomType string, credentials *DataRoomCrede @@ -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 @@ -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("hard")
}
func (s *Session) Broadcast(m interface{}) {
s.mutex.RLock()
if s.Hello {

Loading…
Cancel
Save