-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: synchronization of chat info when the server is down
- Loading branch information
1 parent
282b0b3
commit 2b9e8d8
Showing
12 changed files
with
286 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package chat | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/pet-sitter/pets-next-door-api/internal/service" | ||
) | ||
|
||
func InitializeWebSocketServer(ctx context.Context, wsServer *WsServer, chatService *service.ChatService) { | ||
rows, err := chatService.FindUserChatRoom(ctx) | ||
if err != nil { | ||
log.Println("Error finding user chat rooms:", err) | ||
return | ||
} | ||
|
||
// 클라이언트를 중복 생성하지 않도록 관리하는 맵 | ||
clientMap := make(map[string]*Client) | ||
|
||
for _, row := range rows { | ||
// 클라이언트를 생성하거나 기존 클라이언트를 재사용 | ||
client, exists := clientMap[row.UserInfo.FirebaseUID] | ||
if !exists { | ||
client = NewClient(nil, wsServer, row.UserInfo.Nickname, row.UserInfo.FirebaseUID) | ||
wsServer.RegisterClient(client) | ||
clientMap[row.UserInfo.FirebaseUID] = client | ||
} | ||
|
||
// 방을 생성하거나 기존 방을 불러옴 | ||
room := wsServer.findRoomByID(row.RoomInfo.ID) | ||
if room == nil { | ||
room = room.InitRoom(row.RoomInfo.ID, row.RoomInfo.Name, row.RoomInfo.RoomType) | ||
wsServer.rooms[room] = true | ||
go room.RunRoom(chatService) | ||
} | ||
|
||
// 클라이언트를 방에 등록 | ||
if !client.isInRoom(room) { | ||
client.rooms[room] = true | ||
room.register <- client | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.