feat: publish matchmaking state events

This commit is contained in:
Josh Creek
2026-08-31 23:12:20 +01:00
parent 161d2cdceb
commit 60fe2caf8f
4 changed files with 76 additions and 3 deletions
+18
View File
@@ -14,6 +14,8 @@ import (
"strings"
"sync"
"time"
"github.com/cosmic-clash/cosmic-clash/server/domain"
)
const (
@@ -205,6 +207,22 @@ func (s *Service) PublishControlPlaneEvent(event ControlPlaneEvent) error {
return s.getEventHub().publish(event)
}
func (s *Service) publishTicketEvent(ticket domain.QueueTicket, now time.Time) {
_ = s.PublishControlPlaneEvent(ControlPlaneEvent{
Event: "state_changed", Revision: ticket.Revision, ResourceID: ticket.TicketID,
OccurredAt: now, State: string(ticket.State), PlayerID: ticket.PlayerID,
})
}
func (s *Service) publishProposalEvent(proposal domain.Proposal, now time.Time) {
for _, participant := range proposal.Participants {
_ = s.PublishControlPlaneEvent(ControlPlaneEvent{
Event: "proposal_changed", Revision: proposal.Revision, ResourceID: proposal.ProposalID,
OccurredAt: now, State: string(proposal.State), PlayerID: participant.PlayerID,
})
}
}
func isWebSocketUpgrade(r *http.Request) bool {
return strings.EqualFold(r.Header.Get("Upgrade"), "websocket") && headerContainsToken(r.Header.Values("Connection"), "upgrade")
}