websocket

package
v0.0.0-...-3864442 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	WRITE_WAIT       = 10 * time.Second
	PONG_WAIT        = 60 * time.Second
	PING_PERIOD      = (PONG_WAIT * 9) / 10
	MAX_MESSAGE_SIZE = 1024 * 1024
)
View Source
const (
	ROOM_EXPIRY_TIME        = 3600 * 24
	TYPE_LEFT_ROOM          = "LEFT_ROOM" // Sent to user after successful room leaving
	TYPE_JOINED_ROOM        = "JOINED_ROOM"
	TYPE_MAX_PLAYERS        = 5
	TYPE_PLAYER_JOINED_ROOM = "PLAYER_JOINED_ROOM"
	TYPE_PLAYER_LEFT_ROOM   = "PLAYER_LEFT_ROOM"

	TYPE_PLAYER_COMPLETED_GAME = "PLAYER_COMPLETED_GAME"
	TYPE_START_COUNTDOWN       = "START_COUNTDOWN"
	TYPE_STOP_COUNTDOWN        = "STOP_COUNTDOWN"
	TYPE_TICK_COUNTDOWN        = "TICK_COUNTDOWN"

	TYPE_START_WAIT_COUNTDOWN = "START_WAIT_COUNTDOWN"
	TYPE_STOP_WAIT_COUNTDOWN  = "STOP_WAIT_COUNTDOWN"
	TYPE_TICK_WAIT_COUNTDOWN  = "TICK_WAIT_COUNTDOWN"

	TYPE_START_GAME          = "START_GAME"
	TYPE_FINISH_GAME         = "FINISH_GAME"
	TYPE_UPDATE_PLAYERS_DATA = "UPDATE_PLAYERS_DATA"

	TYPE_MIN_BOTS = 1
	TYPE_MAX_BOTS = 3

	WAIT_SECONDS        = 10     // How many seconds should the room count down for other players
	FINISH_GAME_SECONDS = 4 * 60 // How many seconds must pass before the game automatically closes
)
View Source
const (
	TYPE_CONNECTED = "CONNECTED" // Used after successful connection to the websocket server
	TYPE_ERROR     = "ERROR"     // Generic error type for any unsuccessful action

	TYPE_ONLINE_GAME_PLAYERS_SET       = "ONLINE_GAME_PLAYERS_SET"
	TYPE_ONLINE_GAME_COUNTDOWN_STARTED = "TYPE_ONLINE_GAME_COUNTDOWN_STARTED"
	TYPE_ONLINE_GAME_COUNTDOWN_STOPPED = "TYPE_ONLINE_GAME_COUNTDOWN_STOPPED"
	TYPE_ONLINE_GAME_COUNTDOWN_SET     = "TYPE_ONLINE_GAME_COUNTDOWN_SET"
	TYPE_ONLINE_GAME_RESET             = "TYPE_ONLINE_GAME_RESET"
)
View Source
const (
	CODE_RECONNECT  = 5001
	CODE_DISCONNECT = 5000
)
View Source
const TYPE_BOT_EASY = 1
View Source
const TYPE_BOT_HARD = 3
View Source
const TYPE_BOT_MEDIUM = 2
View Source
const TYPE_BOT_SUPER_HARD = 4
View Source
const TYPE_BOT_WPM_MULTIPLIER = 25

Variables

This section is empty.

Functions

func BroadcastMessage

func BroadcastMessage(messageType string, message interface{})

func DisconnectClient

func DisconnectClient(identifier string)

func ReconnectClient

func ReconnectClient(identifier string)

func ServeWs

func ServeWs(context echo.Context)

Types

type Bot

type Bot struct {
	Difficulty int
	Identifier string
	WPM        int
	Finished   bool
}

func NewBot

func NewBot(identifier string, difficulty int) Bot

type Client

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

func (*Client) SendMessage

func (c *Client) SendMessage(messageType string, message interface{})

type Engine

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

func GetEngine

func GetEngine() *Engine

func (*Engine) GetOnlineRoomData

func (e *Engine) GetOnlineRoomData() map[string]interface{}

GetOnlineRoomData returns details about an online room that hasn't started yet It'll be used to display player counts badge and room info in the online sidebar

func (*Engine) GetRoom

func (e *Engine) GetRoom(sessionId string) (*Room, bool)

func (*Engine) RemoveRoom

func (e *Engine) RemoveRoom(roomId string)

func (*Engine) Run

func (e *Engine) Run()

type Room

type Room struct {
	Id      string
	Players map[string]bool
	Bots    map[string]Bot
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(id string, text string, language string, product map[string]interface{}) *Room

func (*Room) AddBot

func (r *Room) AddBot(identifier string, difficulty int)

func (*Room) AddPlayer

func (r *Room) AddPlayer(identifier string)

Adds a new player to the room

func (*Room) GetPlayer

func (r *Room) GetPlayer(identifier string) map[string]string

Returns a slice with players in this room along with all the data

func (*Room) GetPlayers

func (r *Room) GetPlayers() map[string]interface{}

Returns a slice with players in this room along with all the data

func (*Room) RemoveAllBots

func (r *Room) RemoveAllBots()

func (*Room) RemoveBot

func (r *Room) RemoveBot(identifier string)

Removes player from the room

func (*Room) RemoveBots

func (r *Room) RemoveBots(count int)

Remove a given number of bots from the room (if exist)

func (*Room) RemovePlayer

func (r *Room) RemovePlayer(identifier string)

Removes player from the room

func (*Room) Run

func (r *Room) Run()

func (*Room) SendMessage

func (r *Room) SendMessage(messageType string, message interface{}) bool

Sends a message to the members of this room

func (*Room) StartBotCountdown

func (r *Room) StartBotCountdown()

func (*Room) StopBotCountdown

func (r *Room) StopBotCountdown()

type SocketHub

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

func GetHub

func GetHub() *SocketHub

Singleton pattern

func (*SocketHub) Run

func (h *SocketHub) Run()

func (*SocketHub) SendMessageToClient

func (h *SocketHub) SendMessageToClient(identifier string, messageType string, message interface{}) bool

Jump to

Keyboard shortcuts

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