signaling

package
v0.0.0-...-e9e885a Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: ISC Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxPlayers = 4
View Source
const LobbyCleanInterval = 30 * time.Minute
View Source
const LobbyCleanThreshold = 24 * time.Hour

Variables

View Source
var ErrUnknownPacketType = fmt.Errorf("unknown packet type")

Functions

func Handler

Types

type ClosePacket

type ClosePacket struct {
	Type string `json:"type"`

	ID     string `json:"id"`
	Reason string `json:"reason"`
}

type ConnectPacket

type ConnectPacket struct {
	Type string `json:"type"`

	ID     string `json:"id"`
	Polite bool   `json:"polite"`
}

type CreatePacket

type CreatePacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`

	CodeFormat  string         `json:"codeFormat"`
	Public      bool           `json:"public"`
	Password    string         `json:"password"`
	MaxPlayers  *int           `json:"maxPlayers"`
	CustomData  map[string]any `json:"customData"`
	CanUpdateBy string         `json:"canUpdateBy"`
}

type CredentialsPacket

type CredentialsPacket struct {
	cloudflare.Credentials
	Type      string `json:"type"`
	RequestID string `json:"rid,omitempty"`
}

type DisconnectPacket

type DisconnectPacket struct {
	Type string `json:"type"`

	ID     string `json:"id"`
	Reason string `json:"reason"`
}

type EventPacket

type EventPacket struct {
	metrics.EventParams
	Type string `json:"type"`
}

type ForwardablePacket

type ForwardablePacket struct {
	Type string `json:"type"`

	Source    string `json:"source"`
	Recipient string `json:"recipient"`
}

type HelloPacket

type HelloPacket struct {
	Type string `json:"type"`

	Game          string    `json:"game"`
	ID            string    `json:"id"`
	Secret        string    `json:"secret"`
	Version       string    `json:"version"`
	LatencyVector []float32 `json:"latencyVector"`
}

type JoinPacket

type JoinPacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`

	Lobby    string `json:"lobby"`
	Password string `json:"password"`
}

type JoinedPacket

type JoinedPacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`

	LobbyCode string       `json:"lobby"` // for backwards compatibility, can't rename
	LobbyInfo stores.Lobby `json:"lobbyInfo"`
}

type LeaderPacket

type LeaderPacket struct {
	Type string `json:"type"`

	Leader string `json:"leader,omitempty"`
	Term   int    `json:"term"`
}

type LeavePacket

type LeavePacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`
}

type LeftPacket

type LeftPacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`
}

type ListPacket

type ListPacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`

	Filter string `json:"filter"`
	Sort   string `json:"sort"`
	Limit  int    `json:"limit"`
}

type LobbiesPacket

type LobbiesPacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`

	Lobbies []stores.Lobby `json:"lobbies"`
}

type LobbyUpdatePacket

type LobbyUpdatePacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`

	Public      *bool           `json:"public"`
	CustomData  *map[string]any `json:"customData"`
	CanUpdateBy *string         `json:"canUpdateBy"`
	Password    *string         `json:"password"`
	MaxPlayers  *int            `json:"maxPlayers"`
}

type LobbyUpdatedPacket

type LobbyUpdatedPacket struct {
	RequestID string `json:"rid"`
	Type      string `json:"type"`

	LobbyInfo stores.Lobby `json:"lobbyInfo"`
}

type MissingRecipientError

type MissingRecipientError struct {
	Recipient string `json:"recipient"`
	Cause     error  `json:"cause"`
}

func (*MissingRecipientError) Error

func (e *MissingRecipientError) Error() string

func (*MissingRecipientError) ErrorCode

func (e *MissingRecipientError) ErrorCode() string

func (*MissingRecipientError) MarshalJSON

func (e *MissingRecipientError) MarshalJSON() ([]byte, error)

func (*MissingRecipientError) Unwrap

func (e *MissingRecipientError) Unwrap() error

type Peer

type Peer struct {
	ID            string
	Secret        string
	Game          string
	Lobby         string
	LatencyVector []float32
	// contains filtered or unexported fields
}

func (*Peer) ForwardMessage

func (p *Peer) ForwardMessage(ctx context.Context, raw []byte)

func (*Peer) HandleClosePacket

func (p *Peer) HandleClosePacket(ctx context.Context, packet ClosePacket) error

func (*Peer) HandleCreatePacket

func (p *Peer) HandleCreatePacket(ctx context.Context, packet CreatePacket) error

func (*Peer) HandleHelloPacket

func (p *Peer) HandleHelloPacket(ctx context.Context, packet HelloPacket) error

func (*Peer) HandleJoinPacket

func (p *Peer) HandleJoinPacket(ctx context.Context, packet JoinPacket) error

func (*Peer) HandleLeaveLobbyPacket

func (p *Peer) HandleLeaveLobbyPacket(ctx context.Context, packet LeavePacket) error

func (*Peer) HandleListPacket

func (p *Peer) HandleListPacket(ctx context.Context, packet ListPacket) error

func (*Peer) HandlePacket

func (p *Peer) HandlePacket(ctx context.Context, typ string, raw []byte) error

func (*Peer) HandleUpdatePacket

func (p *Peer) HandleUpdatePacket(ctx context.Context, packet LobbyUpdatePacket) error

func (*Peer) RequestConnection

func (p *Peer) RequestConnection(ctx context.Context, otherID string) error

func (*Peer) Send

func (p *Peer) Send(ctx context.Context, packet any) error

type PingPacket

type PingPacket struct {
	Type string `json:"type"`
}

type TimeoutManager

type TimeoutManager struct {
	DisconnectThreshold time.Duration

	Store stores.Store
}

func (*TimeoutManager) Disconnected

func (manager *TimeoutManager) Disconnected(ctx context.Context, p *Peer)

func (*TimeoutManager) MarkPeerAsActive

func (manager *TimeoutManager) MarkPeerAsActive(ctx context.Context, peerID string)

func (*TimeoutManager) Reconnected

func (manager *TimeoutManager) Reconnected(ctx context.Context, peerID, secret, gameID string) (bool, []string, error)

func (*TimeoutManager) Run

func (manager *TimeoutManager) Run(ctx context.Context)

func (*TimeoutManager) RunOnce

func (manager *TimeoutManager) RunOnce(ctx context.Context)

type WelcomePacket

type WelcomePacket struct {
	Type string `json:"type"`

	ID     string `json:"id"`
	Secret string `json:"secret"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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