SendCloseMessage 추가
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
@ -42,13 +43,14 @@ type DownstreamMessage struct {
|
||||
type CommandType string
|
||||
|
||||
const (
|
||||
CommandType_JoinRoom = CommandType("join_room")
|
||||
CommandType_LeaveRoom = CommandType("leave_room")
|
||||
CommandType_JoinRoom = CommandType("join_room")
|
||||
CommandType_LeaveRoom = CommandType("leave_room")
|
||||
CommandType_WriteControl = CommandType("write_control")
|
||||
)
|
||||
|
||||
type CommandMessage struct {
|
||||
Cmd CommandType
|
||||
Args []string
|
||||
Args []any
|
||||
}
|
||||
|
||||
type WebSocketMessageType int
|
||||
@ -177,6 +179,20 @@ func (ws *WebsocketHandler) SendUpstreamMessage(region string, msg *UpstreamMess
|
||||
}
|
||||
}
|
||||
|
||||
func (ws *WebsocketHandler) SendCloseMessage(region string, target string, text string) {
|
||||
sh := ws.authCaches[region]
|
||||
if sh != nil {
|
||||
sh.localDeliveryChan <- &CommandMessage{
|
||||
Cmd: CommandType_WriteControl,
|
||||
Args: []any{
|
||||
target,
|
||||
int(websocket.CloseMessage),
|
||||
websocket.FormatCloseMessage(websocket.CloseNormalClosure, text),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
@ -257,8 +273,8 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
|
||||
case *CommandMessage:
|
||||
if usermsg.Cmd == CommandType_JoinRoom && len(usermsg.Args) == 2 {
|
||||
alias := usermsg.Args[0]
|
||||
roomName := usermsg.Args[1]
|
||||
alias := usermsg.Args[0].(string)
|
||||
roomName := usermsg.Args[1].(string)
|
||||
|
||||
conn := entireConns[alias]
|
||||
if conn != nil {
|
||||
@ -266,8 +282,8 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
break
|
||||
}
|
||||
} else if usermsg.Cmd == CommandType_LeaveRoom && len(usermsg.Args) == 2 {
|
||||
alias := usermsg.Args[0]
|
||||
roomName := usermsg.Args[1]
|
||||
alias := usermsg.Args[0].(string)
|
||||
roomName := usermsg.Args[1].(string)
|
||||
|
||||
conn := entireConns[alias]
|
||||
if conn != nil {
|
||||
@ -276,6 +292,12 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if usermsg.Cmd == CommandType_WriteControl && len(usermsg.Args) == 2 {
|
||||
alias := usermsg.Args[0].(string)
|
||||
conn := entireConns[alias]
|
||||
if conn != nil {
|
||||
conn.WriteControl(usermsg.Args[1].(int), usermsg.Args[2].([]byte), time.Time{})
|
||||
}
|
||||
}
|
||||
|
||||
// 위에서 break 안걸리면 나한테 없으므로 publish를 해야 함. 그러면 다른 호스트가 deliveryChan으로 받는다
|
||||
@ -303,16 +325,16 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
|
||||
case *CommandMessage:
|
||||
if usermsg.Cmd == CommandType_JoinRoom && len(usermsg.Args) == 2 {
|
||||
alias := usermsg.Args[0]
|
||||
roomName := usermsg.Args[1]
|
||||
alias := usermsg.Args[0].(string)
|
||||
roomName := usermsg.Args[1].(string)
|
||||
|
||||
conn := entireConns[alias]
|
||||
if conn != nil {
|
||||
findRoom(roomName, true).in(conn)
|
||||
}
|
||||
} else if usermsg.Cmd == CommandType_LeaveRoom && len(usermsg.Args) == 2 {
|
||||
alias := usermsg.Args[0]
|
||||
roomName := usermsg.Args[1]
|
||||
alias := usermsg.Args[0].(string)
|
||||
roomName := usermsg.Args[1].(string)
|
||||
|
||||
conn := entireConns[alias]
|
||||
if conn != nil {
|
||||
|
||||
Reference in New Issue
Block a user