WriteMessage를 WritePreparedMessage로 변경
This commit is contained in:
@ -7,6 +7,7 @@ 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"
|
||||
)
|
||||
|
||||
@ -89,7 +90,12 @@ func (cs *connections) writeMessage(acc primitive.ObjectID, src any) {
|
||||
}
|
||||
|
||||
if bt, err := json.Marshal(src); err == nil {
|
||||
conn.c.WriteMessage(websocket.TextMessage, bt)
|
||||
pmsg, err := websocket.NewPreparedMessage(websocket.TextMessage, bt)
|
||||
if err != nil {
|
||||
logger.Println("connections.writeMessage failed :", err)
|
||||
} else {
|
||||
conn.c.WritePreparedMessage(pmsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -144,7 +144,12 @@ func makeFriends(ctx context.Context, so *Social, conns *connections) (*friends,
|
||||
}
|
||||
|
||||
if exists && srcmap != nil && len(srcmap.lastState) > 0 {
|
||||
reg.l.c.WriteMessage(websocket.TextMessage, srcmap.lastState)
|
||||
pmsg, err := websocket.NewPreparedMessage(websocket.TextMessage, srcmap.lastState)
|
||||
if err != nil {
|
||||
logger.Println("makeFriends.NewPreparedMessage failed :", err)
|
||||
} else {
|
||||
reg.l.c.WritePreparedMessage(pmsg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(srcmap.listeners) == 0 && len(srcmap.lastState) == 0 {
|
||||
@ -167,13 +172,15 @@ func makeFriends(ctx context.Context, so *Social, conns *connections) (*friends,
|
||||
delete(listeners, target)
|
||||
}
|
||||
|
||||
pmsg, _ := websocket.NewPreparedMessage(websocket.TextMessage, srcmap.offline)
|
||||
for _, l := range srcmap.listeners {
|
||||
l.c.WriteMessage(websocket.TextMessage, srcmap.offline)
|
||||
l.c.WritePreparedMessage(pmsg)
|
||||
}
|
||||
} else {
|
||||
srcmap.lastState = []byte(state)
|
||||
pmsg, _ := websocket.NewPreparedMessage(websocket.TextMessage, srcmap.lastState)
|
||||
for _, l := range srcmap.listeners {
|
||||
l.c.WriteMessage(websocket.TextMessage, srcmap.lastState)
|
||||
l.c.WritePreparedMessage(pmsg)
|
||||
}
|
||||
}
|
||||
} else if len(state) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user