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. 5
      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. 10
      src/app/spreed-speakfreely-server/server.go

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

@ -34,10 +34,11 @@ type Config struct { @@ -34,10 +34,11 @@ type Config struct {
Tokens bool // True when we got a tokens file
Version string // Server version number
globalRoomid string // Id of the global room (not exported to Javascript)
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)
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 { @@ -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) {
h.mutex.Lock()

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

@ -221,8 +221,10 @@ func runner(runtime phoenix.Runtime) error { @@ -221,8 +221,10 @@ func runner(runtime phoenix.Runtime) error {
tokenProvider = TokenFileProvider(tokenFile)
}
defaultRoomEnabled := false
// 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.
tt := template.New("")

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

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

Loading…
Cancel
Save