SendUpstreamMessage 추가
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"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()
|
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) {
|
func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||||
defer func() {
|
defer func() {
|
||||||
s := recover()
|
s := recover()
|
||||||
@ -240,6 +258,10 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
} else if target[0] == '@' {
|
} else if target[0] == '@' {
|
||||||
// TODO : 특정 유저에게만
|
// TODO : 특정 유저에게만
|
||||||
|
conn := entireConns[target[1:]]
|
||||||
|
if conn != nil {
|
||||||
|
conn.WriteMessage(websocket.TextMessage, usermsg.Body)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case *CommandMessage:
|
case *CommandMessage:
|
||||||
|
|||||||
Reference in New Issue
Block a user