增加建立以及断开连接时,移除连接
This commit is contained in:
@ -10,6 +10,8 @@ package message
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/go-developer/websocket/context"
|
||||
)
|
||||
|
||||
@ -22,3 +24,20 @@ func Response(wsCtx *context.WSContext, data map[string]interface{}) error {
|
||||
byteData, _ := json.Marshal(data)
|
||||
return wsCtx.Session.Write(byteData)
|
||||
}
|
||||
|
||||
// Broadcast 消息广播
|
||||
//
|
||||
// Author : go_developer@163.com<张德满>
|
||||
//
|
||||
// Date : 5:43 下午 2021/4/8
|
||||
func Broadcast(message string, ctxList ...context.WSContext) map[string]error {
|
||||
result := make(map[string]error)
|
||||
for _, ctx := range ctxList {
|
||||
if nil == ctx.Session {
|
||||
result[ctx.ConnectionID] = errors.New("session is nil")
|
||||
continue
|
||||
}
|
||||
result[ctx.ConnectionID] = ctx.Session.Write([]byte(message))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Reference in New Issue
Block a user