ws

package
v0.0.0-...-8fa2ce1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeWs

func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request, config util.Config, store db.Store, gameService *gameservice.GameService, mq *MessageQueue, tokenMaker token.Maker)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a single chatting user.

func NewClient

func NewClient(ctx context.Context, hub *Hub, conn *websocket.Conn, userID int64, store db.Store, gameService *gameservice.GameService, mq *MessageQueue, broadcastChan chan<- []byte, gameID int64, playerGameID int64) *Client

NewClient initializes a new client and sets up message handlers

type DrawCardPayload

type DrawCardPayload struct {
	GameID       int64 `json:"game_id"`
	PlayerGameID int64 `json:"player_game_id"`
	PlayerNumber int32 `json:"player_number"`
}

DrawCardPayload matches the structure expected in the DrawCardRequest message

type EndTurnPayload

type EndTurnPayload struct {
	GameID       int64 `json:"game_id"`
	PlayerGameID int64 `json:"player_game_id"`
}

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub() *Hub

NewHub creates a new Hub.

func (*Hub) HandleGameEvents

func (h *Hub) HandleGameEvents()

func (*Hub) Run

func (h *Hub) Run()

Run starts the hub to process incoming register, unregister and broadcast channels.

type MessageQueue

type MessageQueue struct {
	// contains filtered or unexported fields
}

func NewMessageQueue

func NewMessageQueue(size int) *MessageQueue

func (*MessageQueue) Enqueue

func (mq *MessageQueue) Enqueue(message []byte)

func (*MessageQueue) StartProcessing

func (mq *MessageQueue) StartProcessing(hub *Hub)

type PlayDessertPayload

type PlayDessertPayload struct {
	GameID       int64   `json:"game_id"`
	PlayerGameID int64   `json:"player_game_id"`
	DessertName  string  `json:"dessert_name"`
	CardIDs      []int64 `json:"card_ids"`
}

PlayDessertPayload mirrors the PlayDessertRequest from gRPC

type PlayDessertResponseJSON

type PlayDessertResponseJSON struct {
	DessertPlayedId int64           `json:"dessert_played_id"`
	PlayerGame      *PlayerGameJSON `json:"player_game"`
	GameOver        bool            `json:"game_over"`
}

Custom struct that mirrors pb.PlayDessertResponse but is safe for marshaling

type PlayerGameJSON

type PlayerGameJSON struct {
	PlayerGame   int64  `json:"player_game_id"`
	PlayerId     int64  `json:"player_id"`
	GameId       int64  `json:"game_id"`
	PlayerNumber int32  `json:"player_number"`
	PlayerScore  int32  `json:"player_score"`
	PlayerStatus string `json:"player_status"`
}

type SpecialCardPayload

type SpecialCardPayload struct {
	PlayerGameID int64  `json:"player_game_id"`
	CardType     string `json:"card_type"` // Type of special card
	CardID       int64  `json:"card_id"`
}

type WebSocketMessage

type WebSocketMessage struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL