SendUpstreamMessage 추가
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -168,6 +169,23 @@ func (ws *WebsocketHandler) SetState(region string, accid primitive.ObjectID, st
|
||||
ws.RedisSync.SetArgs(context.Background(), accid.Hex(), state, redis.SetArgs{Mode: "XX"}).Result()
|
||||
}
|
||||
|
||||
var errNoRegion = errors.New("region is not valid")
|
||||
|
||||
func (ws *WebsocketHandler) SendUpstreamMessage(region string, msg *UpstreamMessage) error {
|
||||
sh := ws.authCaches[region]
|
||||
if sh == nil {
|
||||
return errNoRegion
|
||||
}
|
||||
|
||||
bt, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = sh.redisSync.Publish(context.Background(), sh.redisMsgChanName, bt).Result()
|
||||
return err
|
||||
}
|
||||
|
||||
func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
@ -240,6 +258,10 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
}
|
||||
} else if target[0] == '@' {
|
||||
// TODO : 특정 유저에게만
|
||||
conn := entireConns[target[1:]]
|
||||
if conn != nil {
|
||||
conn.WriteMessage(websocket.TextMessage, usermsg.Body)
|
||||
}
|
||||
}
|
||||
|
||||
case *CommandMessage:
|
||||
|
||||
Reference in New Issue
Block a user