- Reorder HandleGameEvents to create NATS subscriptions before SSE - Use chi's middleware.NewWrapResponseWriter for proper http.Flusher support - Add slog-zerolog adapter for unified logging - Add ErrorLog to HTTP server for better error visibility - Change session Cookie.Secure to false for HTTP support - Change heartbeat from 15s to 10s - Remove ConnectionIndicator patching (was causing PatchElementsNoTargetsFound) The key fix was using chi's response writer wrapper which properly implements http.Flusher, allowing SSE data to be flushed immediately instead of being buffered.
57 lines
1.6 KiB
Plaintext
57 lines
1.6 KiB
Plaintext
package pages
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/ryanhamamura/games/chat"
|
|
chatcomponents "github.com/ryanhamamura/games/chat/components"
|
|
"github.com/ryanhamamura/games/connect4"
|
|
"github.com/ryanhamamura/games/features/c4game/components"
|
|
sharedcomponents "github.com/ryanhamamura/games/features/common/components"
|
|
"github.com/ryanhamamura/games/features/common/layouts"
|
|
)
|
|
|
|
templ GamePage(g *connect4.Game, myColor int, messages []chat.Message, chatCfg chatcomponents.Config) {
|
|
@layouts.Base("Connect 4") {
|
|
<main
|
|
class="flex flex-col items-center gap-4 p-4"
|
|
data-signals="{chatMsg: ''}"
|
|
data-init={ fmt.Sprintf("@get('/games/%s/events',{requestCancellation:'disabled'})", g.ID) }
|
|
>
|
|
@GameContent(g, myColor, messages, chatCfg)
|
|
</main>
|
|
}
|
|
}
|
|
|
|
templ GameContent(g *connect4.Game, myColor int, messages []chat.Message, chatCfg chatcomponents.Config) {
|
|
<div id="game-content">
|
|
@sharedcomponents.BackToLobby()
|
|
@sharedcomponents.StealthTitle("text-3xl font-bold")
|
|
@components.PlayerInfo(g, myColor)
|
|
@components.StatusBanner(g, myColor)
|
|
<div class="c4-game-area">
|
|
@components.Board(g, myColor)
|
|
@chatcomponents.Chat(messages, chatCfg)
|
|
</div>
|
|
if g.Status == connect4.StatusWaitingForPlayer {
|
|
@components.InviteLink(g.ID)
|
|
}
|
|
</div>
|
|
}
|
|
|
|
templ JoinPage(gameID string) {
|
|
@layouts.Base("Connect 4 - Join") {
|
|
@sharedcomponents.GameJoinPrompt(
|
|
"/login?return_url=/games/"+gameID,
|
|
"/register?return_url=/games/"+gameID,
|
|
"/games/"+gameID,
|
|
)
|
|
}
|
|
}
|
|
|
|
templ NicknamePage(gameID string) {
|
|
@layouts.Base("Connect 4 - Join") {
|
|
@sharedcomponents.NicknamePrompt("/games/" + gameID + "/join")
|
|
}
|
|
}
|