websocket

package
v0.0.0-...-ecfdd64 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CREATE_GAME = "CREATE_GAME"
	FLAG        = "FLAG"
	UNFLAG      = "UNFLAG"
	DIG         = "DIG"
	USER_MOUSE  = "USER_MOUSE"
)
View Source
const (
	GAME_LOST       = "GAME_LOST"
	GAME_WON        = "GAME_WON"
	UPDATE_BOARD    = "UPDATE_BOARD"
	HISTORY         = "HISTORY"
	CONNECTED_USERS = "CONNECTED_USERS"
)

Variables

View Source
var NilEvent = Event{}

Functions

func ServeWs

func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request, name string)

serveWs handles websocket requests from the peer.

Types

type Action

type Action struct {
	Action string `json:"action"`
}

type ActionMouse

type ActionMouse struct {
	Action string `json:"action"`
	MouseX int    `json:"mouseX"`
	MouseY int    `json:"mouseY"`
}

type ActionSquare

type ActionSquare struct {
	Action string `json:"action"`
	Row    int    `json:"row"`
	Column int    `json:"column"`
}

type Client

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

Client is a middleman between the websocket connection and the hub.

type Event

type Event struct {
	Action     string `json:"action"`
	AuthorID   string `json:"authorID"`
	AuthorName string `json:"authorName"`
	Date       string `json:"date"`
	Row        int    `json:"row"`
	Column     int    `json:"column"`
}

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

func (*Hub) Run

func (h *Hub) Run()

type Response

type Response struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

type User

type User struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	MouseX int    `json:"mouseX"`
	MouseY int    `json:"mouseY"`
}

func GetAllUsers

func GetAllUsers(hub *Hub) []*User

func GetUser

func GetUser(client *Client) *User

Jump to

Keyboard shortcuts

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