웹소켓 메시지 전송 채널 단일화
This commit is contained in:
@ -7,7 +7,6 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/wshandler"
|
||||
)
|
||||
|
||||
@ -20,6 +19,7 @@ type connWithFriends struct {
|
||||
type connections struct {
|
||||
connLock sync.Mutex
|
||||
conns map[primitive.ObjectID]*connWithFriends
|
||||
wsh *wshandler.WebsocketHandler
|
||||
redison *gocommon.RedisonHandler
|
||||
}
|
||||
|
||||
@ -90,12 +90,7 @@ func (cs *connections) writeMessage(acc primitive.ObjectID, src any) {
|
||||
}
|
||||
|
||||
if bt, err := json.Marshal(src); err == nil {
|
||||
pmsg, err := websocket.NewPreparedMessage(websocket.TextMessage, bt)
|
||||
if err != nil {
|
||||
logger.Println("connections.writeMessage failed :", err)
|
||||
} else {
|
||||
conn.c.WritePreparedMessage(pmsg)
|
||||
}
|
||||
cs.wsh.WriteDirectMessage(conn.c, websocket.TextMessage, bt)
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,9 +104,10 @@ func (cs *connections) ClientDisconnected(msg string, callby *wshandler.Sender)
|
||||
cs.delete(callby.Accid)
|
||||
}
|
||||
|
||||
func makeConnections(redison *gocommon.RedisonHandler) *connections {
|
||||
func makeConnections(redison *gocommon.RedisonHandler, wsh *wshandler.WebsocketHandler) *connections {
|
||||
return &connections{
|
||||
conns: make(map[primitive.ObjectID]*connWithFriends),
|
||||
wsh: wsh,
|
||||
redison: redison,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user