comms

package
v0.0.0-...-abd2ee0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FilePath  = "G:\\binge\\binge-questions\\%s.json"
	IndexFile = "index"
)
View Source
var (
	Db         db.DB
	CommsHub   *Hub
	Controller services.Service
)

Functions

func DecodeJsonBody

func DecodeJsonBody(r *http.Request, v interface{}) error

func DecodeRequestJsonString

func DecodeRequestJsonString(content string) (request models.Request, err error)

func HandlerAddQuestion

func HandlerAddQuestion(w http.ResponseWriter, r *http.Request)

func HandlerSeedQuestions

func HandlerSeedQuestions(w http.ResponseWriter, r *http.Request)

func Routes

func Routes(mongoClientId string, database string) *http.ServeMux

Add handlers and interceptors to the endpoints.

func SerializeMessage

func SerializeMessage(response interface{}) []byte

func ServeBinquiz

func ServeBinquiz(hub *Hub, client *Client)

func ServeWebsocket

func ServeWebsocket(hub *Hub, w http.ResponseWriter, r *http.Request)

serveWs handles websocket requests from the peer.

Types

type Client

type Client struct {
	Hub *Hub

	// Buffered channel of outbound messages.
	Send chan []byte

	PlayerId string
	// contains filtered or unexported fields
}

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

func NewClient

func NewClient(hub *Hub, conn *websocket.Conn) *Client

func (*Client) ReadPump

func (c *Client) ReadPump()

readPump pumps messages from the websocket connection to the hub.

The application runs readPump in a per-connection goroutine. The application ensures that there is at most one reader on a connection by executing all reads from this goroutine.

func (*Client) SetPlayerId

func (client *Client) SetPlayerId(playerId string)

func (*Client) WritePump

func (c *Client) WritePump()

writePump pumps messages from the hub to the websocket connection.

A goroutine running writePump is started for each connection. The application ensures that there is at most one writer to a connection by executing all writes from this goroutine.

type CreatePermissionRequest

type CreatePermissionRequest struct {
	PlayerId string `json:"player_id"`
}

type Enter

type Enter func(request models.Request) (res models.GameResponse, err error)

type Hub

type Hub struct {
	// Registered Clients.
	Clients map[*Client]bool

	// Register requests from the clients.
	Register chan *Client

	// Unregister requests from clients.
	Unregister chan *Client

	Controller services.Service
	// contains filtered or unexported fields
}

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

func NewHub

func NewHub(controller services.Service) *Hub

func (*Hub) Broadcast

func (hub *Hub) Broadcast(response models.WebsocketMessage, targets map[string]bool)

func (*Hub) Handle

func (hub *Hub) Handle(msg models.WebsocketMessage, client *Client) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) HandleMessages

func (hub *Hub) HandleMessages(input []byte, fromClient *Client) (err error)

func (*Hub) OnBegin

func (hub *Hub) OnBegin(request models.Request, client *Client) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnCreate

func (hub *Hub) OnCreate(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnFinish

func (hub *Hub) OnFinish(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnHint

func (hub *Hub) OnHint(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnJoin

func (hub *Hub) OnJoin(content models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnNext

func (hub *Hub) OnNext(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnPass

func (hub *Hub) OnPass(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnRefresh

func (hub *Hub) OnRefresh(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnRight

func (hub *Hub) OnRight(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnScore

func (hub *Hub) OnScore(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnStart

func (hub *Hub) OnStart(request models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) OnWatch

func (hub *Hub) OnWatch(content models.Request) (res models.WebsocketMessage, targets map[string]bool, err error)

func (*Hub) Run

func (h *Hub) Run()

type MatchHandler

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

func (MatchHandler) HandlerActiveQuizzes

func (handler MatchHandler) HandlerActiveQuizzes(w http.ResponseWriter, r *http.Request)

type Message

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

type PermissionHandler

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

func (PermissionHandler) HandlerCreatePermission

func (handler PermissionHandler) HandlerCreatePermission(w http.ResponseWriter, r *http.Request)

func (PermissionHandler) HandlerFindPermissions

func (handler PermissionHandler) HandlerFindPermissions(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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