diff --git a/examples/singleon/chat/main.go b/examples/singleon/chat/main.go index a2d66d9..f874f34 100644 --- a/examples/singleon/chat/main.go +++ b/examples/singleon/chat/main.go @@ -115,7 +115,7 @@ func (mgr *RoomManager) Join(s *session.Session, msg []byte) error { fakeUID := s.ID() //just use s.ID as uid !!! s.Bind(fakeUID) // binding session uids.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 room.group.Broadcast("onNewUser", &NewUser{Content: fmt.Sprintf("New user: %d", s.ID())}) // new user join group diff --git a/group.go b/group.go index 23e1d21..2af8402 100644 --- a/group.go +++ b/group.go @@ -51,8 +51,16 @@ func (c *Group) Member(uid int64) (*session.Session, error) { return nil, ErrMemberNotFound } -// Members returns all member's UID in current group -func (c *Group) Members() []int64 { +// Members returns all members in current group +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() defer c.mu.RUnlock() diff --git a/version.go b/version.go index 692cd91..296b1ab 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,4 @@ package ngs // VERSION returns current ngs version -const VERSION = "0.1.2" +const VERSION = "0.1.3"