diff --git a/src/app/spreed-speakfreely-server/config.go b/src/app/spreed-speakfreely-server/config.go index 5d358d14..b480cd1b 100644 --- a/src/app/spreed-speakfreely-server/config.go +++ b/src/app/spreed-speakfreely-server/config.go @@ -25,19 +25,20 @@ import ( ) type Config struct { - Title string // Title - ver string // Version (not exported to Javascript) - S string // Static URL prefix with version - B string // Base URL - StunURIs []string // STUN server URIs - TurnURIs []string // TURN server URIs - 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) - Plugin string // Plugin to load + Title string // Title + ver string // Version (not exported to Javascript) + S string // Static URL prefix with version + B string // Base URL + StunURIs []string // STUN server URIs + TurnURIs []string // TURN server URIs + 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} } diff --git a/src/app/spreed-speakfreely-server/hub.go b/src/app/spreed-speakfreely-server/hub.go index c72c2759..04274b92 100644 --- a/src/app/spreed-speakfreely-server/hub.go +++ b/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) { h.mutex.Lock() diff --git a/src/app/spreed-speakfreely-server/main.go b/src/app/spreed-speakfreely-server/main.go index 5d572523..0ec20a11 100644 --- a/src/app/spreed-speakfreely-server/main.go +++ b/src/app/spreed-speakfreely-server/main.go @@ -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("") diff --git a/src/app/spreed-speakfreely-server/server.go b/src/app/spreed-speakfreely-server/server.go index b5aeae26..491e586b 100644 --- a/src/app/spreed-speakfreely-server/server.go +++ b/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"}) } c.Roomid = msg.Hello.Id - c.Hello = true - s.Broadcast(c, &DataUser{Type: "Joined", Id: c.Id, Ua: msg.Hello.Ua}) + 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) { // TODO(longsleep): Validate Answer s.Unicast(c, msg.Answer.To, msg.Answer) case "Users": - s.Users(c) + 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}) - 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": // 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) { msg.Chat.Chat.Time = time.Now().Format(time.RFC3339) if msg.Chat.To == "" { // 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 { s.Unicast(c, msg.Chat.To, msg.Chat) if msg.Chat.Chat.Mid != "" {