Browse Source

Merge pull request #301 from fancycode/leave_api

Added API to leave a room.
pull/304/head
Simon Eisenmann 9 years ago committed by GitHub
parent
commit
2f21c984c4
  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
themselves. Note that acceptable characters for this field may be themselves. Note that acceptable characters for this field may be
constrained by the server based upon its configuration. 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 Room
{ {

5
go/channelling/api/api.go

@ -188,6 +188,11 @@ func (api *channellingAPI) OnIncoming(sender channelling.Sender, session *channe
} }
return api.HandleRoom(session, msg.Room) return api.HandleRoom(session, msg.Room)
case "Leave":
if err := api.HandleLeave(session); err != nil {
return nil, err
}
return nil, nil
default: default:
log.Println("OnText unhandled message type", msg.Type) log.Println("OnText unhandled message type", msg.Type)
} }

32
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 <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
defer s.mutex.Unlock() defer s.mutex.Unlock()
if s.Hello && s.Roomid != roomID { if s.Hello && s.Roomid != roomID {
s.RoomStatusManager.LeaveRoom(s.Roomid, s.Id) s.doLeaveRoom("soft")
s.Broadcaster.Broadcast(s.Id, s.Roomid, &DataOutgoing{
From: s.Id,
A: s.attestation.Token(),
Data: &DataSession{
Type: "Left",
Id: s.Id,
Status: "soft",
},
})
} }
room, err := s.RoomStatusManager.JoinRoom(roomID, roomName, roomType, credentials, s, s.authenticated(), sender) 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 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{}) { func (s *Session) Broadcast(m interface{}) {
s.mutex.RLock() s.mutex.RLock()
if s.Hello { if s.Hello {

Loading…
Cancel
Save