models

package
v0.0.0-...-8db6ce2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID string

	// socket is the web socket for this client.
	Socket *websocket.Conn

	// send is a channel on which messages are sent.
	Send chan []byte

	// room is the room this client is chatting in.
	Room *Room
}

Client represents a single chatting user.

func (*Client) Read

func (c *Client) Read()

func (*Client) Write

func (c *Client) Write()

type Message

type Message struct {
	ID        string `json:"ID"`
	Sender    string
	Timestamp int64
	Content   string `json:"content"`
}

Message describe a message sent and receive between clients

type RawClientMessage

type RawClientMessage struct {
	Sender  string `json:"sender"`
	Content string `json:"content"`
}

RawClientMessage describe a message sent from a client

type Room

type Room struct {
	ID string
	// Forward is a channel that holds incoming messages
	// that should be forwarded to the other clients.
	Forward chan *RawClientMessage

	// join is a channel for clients wishing to join the room.
	Join chan *Client

	// Leave is a channel for clients wishing to Leave the room.
	Leave chan *Client
	// contains filtered or unexported fields
}

Room define model for a room

func NewRoom

func NewRoom(ID string) *Room

NewRoom will create a new room

func (*Room) GetMessages

func (room *Room) GetMessages() []*Message

GetMessages returns room's valid messages

func (*Room) Run

func (room *Room) Run()

Run will start listen to room event

func (*Room) ServeHTTP

func (room *Room) ServeHTTP(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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