|
|
@ -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) |
|
|
|