✨ Websocket stream control count connection for specific user
This commit is contained in:
@ -7,6 +7,13 @@ import (
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
)
|
||||
|
||||
func (v *Server) CountStreamConnection(ctx context.Context, request *proto.CountConnectionRequest) (*proto.CountConnectionResponse, error) {
|
||||
out := services.ClientCount(uint(request.GetUserId()))
|
||||
return &proto.CountConnectionResponse{
|
||||
Count: int64(out),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) PushStream(ctx context.Context, request *proto.PushStreamRequest) (*proto.PushStreamResponse, error) {
|
||||
cnt, success, errs := services.WebsocketPush(uint(request.GetUserId()), request.GetBody())
|
||||
if len(errs) > 0 {
|
||||
|
@ -29,6 +29,10 @@ func ClientUnregister(user models.Account, conn *websocket.Conn) {
|
||||
wsMutex.Unlock()
|
||||
}
|
||||
|
||||
func ClientCount(uid uint) int {
|
||||
return len(wsConn[uid])
|
||||
}
|
||||
|
||||
func WebsocketPush(uid uint, body []byte) (count int, success int, errs []error) {
|
||||
for conn := range wsConn[uid] {
|
||||
if err := conn.WriteMessage(1, body); err != nil {
|
||||
|
Reference in New Issue
Block a user