Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Dec 3, 2023
1 parent b62a261 commit 5318d69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,15 @@ import (

type Socket struct{ *gws.Conn }

// GetSubscriberID gets the subscription ID, which needs to be unique.
func (c *Socket) GetSubscriberID() int64 {
userId, _ := c.Session().Load("userId")
return userId.(int64)
}

func (c *Socket) GetMetadata() event_emitter.Metadata {
return c.Conn.Session()
}

func Sub(em *event_emitter.EventEmitter[*Socket], topic string, socket *Socket) {
em.Subscribe(socket, topic, func(subscriber *Socket, msg any) {
_ = msg.(*gws.Broadcaster).Broadcast(subscriber.Conn)
Expand Down
5 changes: 4 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,15 @@ import (

type Socket struct{ *gws.Conn }

// GetSubscriberID 获取订阅ID, 需要保证唯一
func (c *Socket) GetSubscriberID() int64 {
userId, _ := c.Session().Load("userId")
return userId.(int64)
}

func (c *Socket) GetMetadata() event_emitter.Metadata {
return c.Conn.Session()
}

func Sub(em *event_emitter.EventEmitter[*Socket], topic string, socket *Socket) {
em.Subscribe(socket, topic, func(subscriber *Socket, msg any) {
_ = msg.(*gws.Broadcaster).Broadcast(subscriber.Conn)
Expand Down

0 comments on commit 5318d69

Please sign in to comment.