feat: group添加获取所有members方法

main
NorthLan 3 years ago
parent c08fa7243c
commit d0e21cf470

@ -115,7 +115,7 @@ func (mgr *RoomManager) Join(s *session.Session, msg []byte) error {
fakeUID := s.ID() //just use s.ID as uid !!! fakeUID := s.ID() //just use s.ID as uid !!!
s.Bind(fakeUID) // binding session uids.Set(roomIDKey, room) s.Bind(fakeUID) // binding session uids.Set(roomIDKey, room)
s.Set(roomIDKey, room) s.Set(roomIDKey, room)
s.Push("onMembers", &AllMembers{Members: room.group.Members()}) s.Push("onMembers", &AllMembers{Members: room.group.MemberIDs()})
// notify others // notify others
room.group.Broadcast("onNewUser", &NewUser{Content: fmt.Sprintf("New user: %d", s.ID())}) room.group.Broadcast("onNewUser", &NewUser{Content: fmt.Sprintf("New user: %d", s.ID())})
// new user join group // new user join group

@ -51,8 +51,16 @@ func (c *Group) Member(uid int64) (*session.Session, error) {
return nil, ErrMemberNotFound return nil, ErrMemberNotFound
} }
// Members returns all member's UID in current group // Members returns all members in current group
func (c *Group) Members() []int64 { func (c *Group) Members() map[int64]*session.Session {
c.mu.RLock()
defer c.mu.RUnlock()
return c.sessions
}
// MemberIDs returns all member's UID in current group
func (c *Group) MemberIDs() []int64 {
c.mu.RLock() c.mu.RLock()
defer c.mu.RUnlock() defer c.mu.RUnlock()

@ -1,4 +1,4 @@
package ngs package ngs
// VERSION returns current ngs version // VERSION returns current ngs version
const VERSION = "0.1.2" const VERSION = "0.1.3"

Loading…
Cancel
Save