Browse Source

Include number of chat message in hub statistics.

pull/10/head
Joachim Bauch 11 years ago
parent
commit
a0220f6eb1
  1. 45
      src/app/spreed-speakfreely-server/hub.go
  2. 3
      src/app/spreed-speakfreely-server/server.go

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

@ -30,6 +30,7 @@ import (
"github.com/gorilla/securecookie" "github.com/gorilla/securecookie"
"log" "log"
"sync" "sync"
"sync/atomic"
"time" "time"
) )
@ -47,28 +48,32 @@ type MessageRequest struct {
} }
type HubStat struct { type HubStat struct {
Rooms int `json:"rooms"` Rooms int `json:"rooms"`
Connections int `json:"connections"` Connections int `json:"connections"`
Users int `json:"users"` Users int `json:"users"`
Count uint64 `json:"count"` Count uint64 `json:"count"`
IdsInRoom map[string][]string `json:"idsinroom,omitempty"` BroadcastChatMessages uint64 `json:"broadcastchatmessages"`
UsersById map[string]*DataUser `json:"usersbyid,omitempty"` UnicastChatMessages uint64 `json:"unicastchatmessages"`
ConnectionsByIdx map[string]string `json:"connectionsbyidx,omitempty"` IdsInRoom map[string][]string `json:"idsinroom,omitempty"`
UsersById map[string]*DataUser `json:"usersbyid,omitempty"`
ConnectionsByIdx map[string]string `json:"connectionsbyidx,omitempty"`
} }
type Hub struct { type Hub struct {
server *Server server *Server
connectionTable map[string]*Connection connectionTable map[string]*Connection
userTable map[string]*User userTable map[string]*User
roomTable map[string]*RoomWorker roomTable map[string]*RoomWorker
version string version string
config *Config config *Config
sessionSecret []byte sessionSecret []byte
turnSecret []byte turnSecret []byte
tickets *securecookie.SecureCookie tickets *securecookie.SecureCookie
count uint64 count uint64
mutex sync.RWMutex mutex sync.RWMutex
buffers BufferCache buffers BufferCache
broadcastChatMessages uint64
unicastChatMessages uint64
} }
func NewHub(version string, config *Config, sessionSecret string, turnSecret string) *Hub { func NewHub(version string, config *Config, sessionSecret string, turnSecret string) *Hub {
@ -97,6 +102,8 @@ func (h *Hub) Stat(details bool) *HubStat {
Connections: len(h.connectionTable), Connections: len(h.connectionTable),
Users: len(h.userTable), Users: len(h.userTable),
Count: h.count, Count: h.count,
BroadcastChatMessages: atomic.LoadUint64(&h.broadcastChatMessages),
UnicastChatMessages: atomic.LoadUint64(&h.unicastChatMessages),
} }
if details { if details {
rooms := make(map[string][]string) rooms := make(map[string][]string)

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

@ -23,6 +23,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"log" "log"
"sync/atomic"
"time" "time"
) )
@ -114,9 +115,11 @@ func (s *Server) OnText(c *Connection, b Buffer) {
if msg.Chat.To == "" { if msg.Chat.To == "" {
// TODO(longsleep): Check if chat broadcast is allowed. // TODO(longsleep): Check if chat broadcast is allowed.
if c.h.config.defaultRoomEnabled || !c.h.isDefaultRoomid(c.Roomid) { if c.h.config.defaultRoomEnabled || !c.h.isDefaultRoomid(c.Roomid) {
atomic.AddUint64(&c.h.broadcastChatMessages, 1)
s.Broadcast(c, msg.Chat) s.Broadcast(c, msg.Chat)
} }
} else { } else {
atomic.AddUint64(&c.h.unicastChatMessages, 1)
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 != "" {
// Send out delivery confirmation status chat message. // Send out delivery confirmation status chat message.

Loading…
Cancel
Save