Browse Source

Added server side code to disable default room.

Signed-off-by: Simon Eisenmann <simon@struktur.de>
pull/3/head
Simon Eisenmann 12 years ago committed by Simon Eisenmann
parent
commit
ba14e3fa4b
  1. 25
      src/app/spreed-speakfreely-server/config.go
  2. 5
      src/app/spreed-speakfreely-server/hub.go
  3. 4
      src/app/spreed-speakfreely-server/main.go
  4. 20
      src/app/spreed-speakfreely-server/server.go

25
src/app/spreed-speakfreely-server/config.go

@ -25,19 +25,20 @@ import (
) )
type Config struct { type Config struct {
Title string // Title Title string // Title
ver string // Version (not exported to Javascript) ver string // Version (not exported to Javascript)
S string // Static URL prefix with version S string // Static URL prefix with version
B string // Base URL B string // Base URL
StunURIs []string // STUN server URIs StunURIs []string // STUN server URIs
TurnURIs []string // TURN server URIs TurnURIs []string // TURN server URIs
Tokens bool // True when we got a tokens file Tokens bool // True when we got a tokens file
Version string // Server version number Version string // Server version number
globalRoomid string // Id of the global room (not exported to Javascript) globalRoomid string // Id of the global room (not exported to Javascript)
Plugin string // Plugin to load defaultRoomEnabled bool // Flag to enable default room ("")
Plugin string // Plugin to load
} }
func NewConfig(title, ver, runtimeVersion, basePath string, stunURIs, turnURIs []string, tokens bool, globalRoomid, plugin string) *Config { func NewConfig(title, ver, runtimeVersion, basePath string, stunURIs, turnURIs []string, tokens bool, globalRoomid, string, defaultRoomEnabled bool, plugin string) *Config {
sv := fmt.Sprintf("static/ver=%s", ver) sv := fmt.Sprintf("static/ver=%s", ver)
return &Config{Title: title, ver: ver, S: sv, B: basePath, StunURIs: stunURIs, TurnURIs: turnURIs, Tokens: tokens, Version: runtimeVersion, globalRoomid: globalRoomid, Plugin: plugin} return &Config{Title: title, ver: ver, S: sv, B: basePath, StunURIs: stunURIs, TurnURIs: turnURIs, Tokens: tokens, Version: runtimeVersion, globalRoomid: globalRoomid, defaultRoomEnabled: defaultRoomEnabled, Plugin: plugin}
} }

5
src/app/spreed-speakfreely-server/hub.go

@ -144,6 +144,11 @@ func (h *Hub) isGlobalRoomid(id string) bool {
} }
func (h *Hub) isDefaultRoomid(id string) bool {
return id == ""
}
func (h *Hub) registerHandler(c *Connection) { func (h *Hub) registerHandler(c *Connection) {
h.mutex.Lock() h.mutex.Lock()

4
src/app/spreed-speakfreely-server/main.go

@ -221,8 +221,10 @@ func runner(runtime phoenix.Runtime) error {
tokenProvider = TokenFileProvider(tokenFile) tokenProvider = TokenFileProvider(tokenFile)
} }
defaultRoomEnabled := false
// Create configuration data structure. // Create configuration data structure.
config = NewConfig(title, ver, runtimeVersion, basePath, stunURIs, turnURIs, tokenProvider != nil, globalRoomid, plugin) config = NewConfig(title, ver, runtimeVersion, basePath, stunURIs, turnURIs, tokenProvider != nil, globalRoomid, defaultRoomEnabled, plugin)
// Load templates. // Load templates.
tt := template.New("") tt := template.New("")

20
src/app/spreed-speakfreely-server/server.go

@ -75,8 +75,12 @@ func (s *Server) OnText(c *Connection, b []byte) {
s.Broadcast(c, &DataUser{Type: "Left", Id: c.Id, Status: "soft"}) s.Broadcast(c, &DataUser{Type: "Left", Id: c.Id, Status: "soft"})
} }
c.Roomid = msg.Hello.Id c.Roomid = msg.Hello.Id
c.Hello = true if c.h.config.defaultRoomEnabled || !c.h.isDefaultRoomid(c.Roomid) {
s.Broadcast(c, &DataUser{Type: "Joined", Id: c.Id, Ua: msg.Hello.Ua}) c.Hello = true
s.Broadcast(c, &DataUser{Type: "Joined", Id: c.Id, Ua: msg.Hello.Ua})
} else {
c.Hello = false
}
case "Offer": case "Offer":
// TODO(longsleep): Validate offer // TODO(longsleep): Validate offer
s.Unicast(c, msg.Offer.To, msg.Offer) s.Unicast(c, msg.Offer.To, msg.Offer)
@ -87,13 +91,17 @@ func (s *Server) OnText(c *Connection, b []byte) {
// TODO(longsleep): Validate Answer // TODO(longsleep): Validate Answer
s.Unicast(c, msg.Answer.To, msg.Answer) s.Unicast(c, msg.Answer.To, msg.Answer)
case "Users": case "Users":
s.Users(c) if c.h.config.defaultRoomEnabled || !c.h.isDefaultRoomid(c.Roomid) {
s.Users(c)
}
case "Bye": case "Bye":
s.Unicast(c, msg.Bye.To, msg.Bye) s.Unicast(c, msg.Bye.To, msg.Bye)
case "Status": case "Status":
//log.Println("Status", msg.Status) //log.Println("Status", msg.Status)
rev := s.UpdateUser(c, &UserUpdate{Types: []string{"Status"}, Status: msg.Status.Status}) rev := s.UpdateUser(c, &UserUpdate{Types: []string{"Status"}, Status: msg.Status.Status})
s.Broadcast(c, &DataUser{Type: "Status", Id: c.Id, Status: msg.Status.Status, Rev: rev}) if c.h.config.defaultRoomEnabled || !c.h.isDefaultRoomid(c.Roomid) {
s.Broadcast(c, &DataUser{Type: "Status", Id: c.Id, Status: msg.Status.Status, Rev: rev})
}
case "Chat": case "Chat":
// TODO(longsleep): Limit sent chat messages per incoming connection. // TODO(longsleep): Limit sent chat messages per incoming connection.
if !msg.Chat.Chat.NoEcho { if !msg.Chat.Chat.NoEcho {
@ -102,7 +110,9 @@ func (s *Server) OnText(c *Connection, b []byte) {
msg.Chat.Chat.Time = time.Now().Format(time.RFC3339) msg.Chat.Chat.Time = time.Now().Format(time.RFC3339)
if msg.Chat.To == "" { if msg.Chat.To == "" {
// TODO(longsleep): Check if chat broadcast is allowed. // TODO(longsleep): Check if chat broadcast is allowed.
s.Broadcast(c, msg.Chat) if c.h.config.defaultRoomEnabled || !c.h.isDefaultRoomid(c.Roomid) {
s.Broadcast(c, msg.Chat)
}
} else { } else {
s.Unicast(c, msg.Chat.To, msg.Chat) s.Unicast(c, msg.Chat.To, msg.Chat)
if msg.Chat.Chat.Mid != "" { if msg.Chat.Chat.Mid != "" {

Loading…
Cancel
Save