ws

package
v0.0.0-...-0895a87 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	RoomID      int    `json:"room_id"`
	Username    string `json:"username"`
	Alternative int8   `json:"alternative"`
	QuestionID  int    `json:"question_id"`
}

type ChatMessage

type ChatMessage struct {
	RoomID   int    `json:"room_id"`
	Username string `json:"username"`
	Message  string `json:"message"`
}

type Client

type Client struct {
	Conn          *websocket.Conn
	Answers       chan *Answer
	Question      chan *Question
	Notifications chan *Notification
	Messages      chan *ChatMessage
	ID            int    `json:"id"`
	RoomID        int    `json:"room_id"`
	UserID        int    `json:"user_id"`
	Username      string `json:"username"`
}

func (*Client) ReadAnswer

func (c *Client) ReadAnswer(h *Hub)

func (*Client) ReadChatMessage

func (c *Client) ReadChatMessage(h *Hub)

func (*Client) WriteChatMessage

func (c *Client) WriteChatMessage()

func (*Client) WriteNotification

func (c *Client) WriteNotification(h *Hub)

func (*Client) WriteQuestion

func (c *Client) WriteQuestion(h *Hub)

type ClientResponse

type ClientResponse struct {
	ID       int    `json:"id"`
	Username string `json:"username"`
}

type CreateRoomRequest

type CreateRoomRequest struct {
	ID                int    `json:"id"`
	Name              string `json:"name"`
	NumberOfQuestions int    `json:"number_of_questions"`
	Timeout           int    `json:"timeout"`
	Subject           string `json:"subject"`
	Capacity          int    `json:"capacity"`
}

type Handler

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

func NewHandler

func NewHandler(hub *Hub) *Handler

func (*Handler) CreateRoom

func (h *Handler) CreateRoom(c *gin.Context)

func (*Handler) JoinRoom

func (h *Handler) JoinRoom(c *gin.Context)

func (*Handler) ListClients

func (h *Handler) ListClients(c *gin.Context)

func (*Handler) ListRooms

func (h *Handler) ListRooms(c *gin.Context)

type Hub

type Hub struct {
	Rooms      map[int]*Room
	Register   chan *Client
	Unregister chan *Client
	Notify     chan *Notification
	Messages   chan *ChatMessage
	Answers    chan *Answer
}

func NewHub

func NewHub() *Hub

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) StartGame

func (h *Hub) StartGame(r *Room, questionNumber *int) map[string]bool

type Notification

type Notification struct {
	RoomID   int    `json:"room_id"`
	Username string `json:"username"`
	Type     string `json:"type"`
	Content  string `json:"content"`
}

type Question

type Question struct {
	ID            int      `json:"id"`
	Text          string   `json:"text"`
	Answers       []string `json:"answers"`
	Subject       string   `json:"subject"`
	CorrectAnswer int8     `json:"correct_answer"`
}

func (*Question) GetRandomQuestion

func (q *Question) GetRandomQuestion(subject string) *Question

type Room

type Room struct {
	ID                int             `json:"id"`
	Name              string          `json:"name"`
	Answers           chan *Answer    `json:"answers"`
	Question          *Question       `json:"question"`
	NumberOfQuestions int             `json:"number_of_questions"`
	Timeout           time.Duration   `json:"timeout"`
	Subject           string          `json:"subject"`
	Clients           map[int]*Client `json:"clients"`
	Players           int             `json:"players"`
	Capacity          int             `json:"capacity"`
}

type RoomResponse

type RoomResponse struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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