From d0e21cf470a1274b6227e1222575a312965ce1f9 Mon Sep 17 00:00:00 2001 From: NorthLan <6995syu@163.com> Date: Thu, 26 May 2022 23:53:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20group=E6=B7=BB=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=89=80=E6=9C=89members=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/singleon/chat/main.go | 2 +- group.go | 12 ++++++++++-- version.go | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) 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"