commandtype 이름 변경

This commit is contained in:
2023-07-19 16:38:44 +09:00
parent e0e911f9e7
commit 112e037f4d

View File

@ -61,7 +61,7 @@ type DownstreamMessage struct {
type commandType string type commandType string
const ( const (
commandType_JoinRoom = commandType("join_room") commandType_EnterRoom = commandType("enter_room")
commandType_LeaveRoom = commandType("leave_room") commandType_LeaveRoom = commandType("leave_room")
) )
@ -293,7 +293,7 @@ func (ws *WebsocketHandler) EnterRoom(region string, room string, accid primitiv
sh := ws.subhandlers[region] sh := ws.subhandlers[region]
if sh != nil { if sh != nil {
sh.localDeliveryChan <- &commandMessage{ sh.localDeliveryChan <- &commandMessage{
Cmd: commandType_JoinRoom, Cmd: commandType_EnterRoom,
Args: []any{room, accid}, Args: []any{room, accid},
} }
} }
@ -417,7 +417,7 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
} }
case *commandMessage: case *commandMessage:
if usermsg.Cmd == commandType_JoinRoom && len(usermsg.Args) == 2 { if usermsg.Cmd == commandType_EnterRoom && len(usermsg.Args) == 2 {
roomName := usermsg.Args[0].(string) roomName := usermsg.Args[0].(string)
accid := usermsg.Args[1].(primitive.ObjectID) accid := usermsg.Args[1].(primitive.ObjectID)
conn := entireConns[accid.Hex()] conn := entireConns[accid.Hex()]
@ -479,7 +479,7 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
} }
case *commandMessage: case *commandMessage:
if usermsg.Cmd == commandType_JoinRoom && len(usermsg.Args) == 2 { if usermsg.Cmd == commandType_EnterRoom && len(usermsg.Args) == 2 {
roomName := usermsg.Args[0].(string) roomName := usermsg.Args[0].(string)
accid := usermsg.Args[1].(primitive.ObjectID) accid := usermsg.Args[1].(primitive.ObjectID)
conn := entireConns[accid.Hex()] conn := entireConns[accid.Hex()]
@ -507,11 +507,15 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
case c := <-sh.connInOutChan: case c := <-sh.connInOutChan:
if c.Conn == nil { if c.Conn == nil {
delete(entireConns, c.sender.Accid.Hex()) delete(entireConns, c.sender.Accid.Hex())
var roomnames []string
for _, room := range c.joinedRooms { for _, room := range c.joinedRooms {
roomnames = append(roomnames, room.name)
room.out(c) room.out(c)
} }
c.joinedRooms = nil c.joinedRooms = nil
go sh.callReceiver.OnClientMessageReceived(c.sender, Disconnected, nil)
bt, _ := json.Marshal(roomnames)
go sh.callReceiver.OnClientMessageReceived(c.sender, Disconnected, bytes.NewBuffer(bt))
} else { } else {
entireConns[c.sender.Accid.Hex()] = c entireConns[c.sender.Accid.Hex()] = c
go sh.callReceiver.OnClientMessageReceived(c.sender, Connected, nil) go sh.callReceiver.OnClientMessageReceived(c.sender, Connected, nil)
@ -542,7 +546,6 @@ func upgrade_core(sh *subhandler, conn *websocket.Conn, accid primitive.ObjectID
} }
if messageType == websocket.CloseMessage { if messageType == websocket.CloseMessage {
sh.callReceiver.OnClientMessageReceived(c.sender, CloseMessage, r)
break break
} }