Documentation ¶
Index ¶
- Constants
- Variables
- type ElectionResult
- type Lobby
- type LobbyOptions
- type PostgresStore
- func (s *PostgresStore) ClaimNextTimedOutPeer(ctx context.Context, threshold time.Duration, ...) (more bool, err error)
- func (s *PostgresStore) CleanEmptyLobbies(ctx context.Context, olderThan time.Time) error
- func (s *PostgresStore) CreateLobby(ctx context.Context, game, lobbyCode, peerID string, options LobbyOptions) error
- func (s *PostgresStore) DoLeaderElection(ctx context.Context, gameID, lobbyCode string) (*ElectionResult, error)
- func (s *PostgresStore) GetLobby(ctx context.Context, game, lobbyCode string) (Lobby, error)
- func (s *PostgresStore) JoinLobby(ctx context.Context, game, lobbyCode, peerID, password string) error
- func (s *PostgresStore) LeaveLobby(ctx context.Context, game, lobbyCode, peerID string) error
- func (s *PostgresStore) ListLobbies(ctx context.Context, game, filter string) ([]Lobby, error)
- func (s *PostgresStore) Publish(ctx context.Context, topic string, data []byte) error
- func (s *PostgresStore) ReconnectPeer(ctx context.Context, peerID, secret, gameID string) (bool, []string, error)
- func (s *PostgresStore) Subscribe(ctx context.Context, callback SubscriptionCallback, game, lobby, peerID string)
- func (s *PostgresStore) TimeoutPeer(ctx context.Context, peerID, secret, gameID string, lobbies []string) error
- func (s *PostgresStore) UpdateLobby(ctx context.Context, game, lobbyCode, peerID string, options LobbyOptions) error
- type Store
- type SubscriptionCallback
Constants ¶
View Source
const ( CanUpdateByCreator = "creator" CanUpdateByLeader = "leader" CanUpdateByAnyone = "anyone" CanUpdateByNone = "none" )
Variables ¶
View Source
var ErrAlreadyInLobby = errors.New("peer already in lobby")
View Source
var ErrInvalidLobbyCode = errors.New("invalid lobby code")
View Source
var ErrInvalidPassword = errors.New("invalid password")
View Source
var ErrInvalidPeerID = errors.New("invalid peer id")
View Source
var ErrLobbyExists = errors.New("lobby already exists")
View Source
var ErrLobbyIsFull = errors.New("lobby is full")
View Source
var ErrNoSuchTopic = errors.New("no such topic")
View Source
var ErrNotFound = errors.New("lobby not found")
Functions ¶
This section is empty.
Types ¶
type ElectionResult ¶
type Lobby ¶
type Lobby struct { Code string `json:"code"` Peers []string `json:"peers"` PlayerCount int `json:"playerCount"` Creator string `json:"creator"` Public bool `json:"public"` MaxPlayers int `json:"maxPlayers"` HasPassword bool `json:"hasPassword"` CustomData map[string]any `json:"customData"` CanUpdateBy string `json:"canUpdateBy"` Leader string `json:"leader,omitempty"` Term int `json:"term"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
type LobbyOptions ¶
type PostgresStore ¶
func NewPostgresStore ¶
func (*PostgresStore) ClaimNextTimedOutPeer ¶
func (*PostgresStore) CleanEmptyLobbies ¶
func (*PostgresStore) CreateLobby ¶
func (s *PostgresStore) CreateLobby(ctx context.Context, game, lobbyCode, peerID string, options LobbyOptions) error
func (*PostgresStore) DoLeaderElection ¶
func (s *PostgresStore) DoLeaderElection(ctx context.Context, gameID, lobbyCode string) (*ElectionResult, error)
DoLeaderElection attempts to elect a leader for the given lobby. If a correct leader already exists it will return nil. If no leader can be elected, it will return an ElectionResult with a nil leader.
func (*PostgresStore) JoinLobby ¶
func (s *PostgresStore) JoinLobby(ctx context.Context, game, lobbyCode, peerID, password string) error
func (*PostgresStore) LeaveLobby ¶
func (s *PostgresStore) LeaveLobby(ctx context.Context, game, lobbyCode, peerID string) error
func (*PostgresStore) ListLobbies ¶
func (*PostgresStore) ReconnectPeer ¶
func (*PostgresStore) Subscribe ¶
func (s *PostgresStore) Subscribe(ctx context.Context, callback SubscriptionCallback, game, lobby, peerID string)
func (*PostgresStore) TimeoutPeer ¶
func (*PostgresStore) UpdateLobby ¶
func (s *PostgresStore) UpdateLobby(ctx context.Context, game, lobbyCode, peerID string, options LobbyOptions) error
type Store ¶
type Store interface { CreateLobby(ctx context.Context, Game, LobbyCode, PeerID string, options LobbyOptions) error JoinLobby(ctx context.Context, game, lobby, id, password string) error LeaveLobby(ctx context.Context, game, lobby, id string) error GetLobby(ctx context.Context, game, lobby string) (Lobby, error) ListLobbies(ctx context.Context, game, filter string) ([]Lobby, error) Subscribe(ctx context.Context, callback SubscriptionCallback, game, lobby, peerID string) Publish(ctx context.Context, topic string, data []byte) error TimeoutPeer(ctx context.Context, peerID, secret, gameID string, lobbies []string) error ReconnectPeer(ctx context.Context, peerID, secret, gameID string) (bool, []string, error) ClaimNextTimedOutPeer(ctx context.Context, threshold time.Duration, callback func(peerID, gameID string, lobbies []string) error) (bool, error) CleanEmptyLobbies(ctx context.Context, olderThan time.Time) error // DoLeaderElection attempts to elect a leader for the given lobby. If a correct leader already exists it will return nil. // If no leader can be elected, it will return an ElectionResult with a nil leader. DoLeaderElection(ctx context.Context, gameID, lobbyCode string) (*ElectionResult, error) UpdateLobby(ctx context.Context, Game, LobbyCode, PeerID string, options LobbyOptions) error }
type SubscriptionCallback ¶
Click to show internal directories.
Click to hide internal directories.