websocket

package
v0.0.0-...-dea11c1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: Unlicense Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpgradeConnection

func UpgradeConnection(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

Types

type Client

type Client struct {
	Uuid string
	Conn *websocket.Conn
	Pool *Pool
	User *users.User
}

func NewClient

func NewClient(conn *websocket.Conn, pool *Pool, user *users.User) *Client

func (*Client) IsAuthorized

func (c *Client) IsAuthorized() bool

IsAuthorized identify if the client provided its name before.

func (*Client) Read

func (c *Client) Read()

type MessageMetadata

type MessageMetadata struct {
	MessageType messages.MessageType `json:"type"`
}

type MessageTransport

type MessageTransport struct {
	MessageType messages.MessageType `json:"type"`
	Payload     interface{}          `json:"payload"`
}

func NewMessageTransport

func NewMessageTransport(messageType messages.MessageType, payloadObject interface{}) *MessageTransport

NewMessageTransport generates new transport for the message.

func (*MessageTransport) MarshalJSON

func (m *MessageTransport) MarshalJSON() ([]byte, error)

func (*MessageTransport) UnmarshalJSON

func (m *MessageTransport) UnmarshalJSON(bytes []byte) error

type Pool

type Pool struct {
	History    *history.History
	Clients    map[*Client]bool
	Register   chan *Client
	Unregister chan *Client
	LogIn      chan *Client
	LogOut     chan *Client
	Broadcast  chan *MessageTransport
}

func NewPool

func NewPool() *Pool

func (*Pool) AddClientToPool

func (pool *Pool) AddClientToPool(client *Client)

func (*Pool) BroadcastMessage

func (pool *Pool) BroadcastMessage(message *MessageTransport, sendToAllClients bool) error

func (*Pool) BroadcastServerMessage

func (pool *Pool) BroadcastServerMessage(message string) error

func (*Pool) BroadcastUsersQty

func (pool *Pool) BroadcastUsersQty() error

func (*Pool) DeleteClientFromPool

func (pool *Pool) DeleteClientFromPool(client *Client) error

func (*Pool) LogInClient

func (pool *Pool) LogInClient(client *Client) error

LogInClient sends JWT to the client

func (*Pool) LogOutClient

func (pool *Pool) LogOutClient(client *Client) error

func (*Pool) NewClient

func (pool *Pool) NewClient(user *users.User, conn *websocket.Conn) *Client

func (*Pool) SendHistoryToClient

func (pool *Pool) SendHistoryToClient(client *Client) error

func (*Pool) SendMessageToClient

func (pool *Pool) SendMessageToClient(message *MessageTransport, client *Client) error

func (*Pool) SendUsersQtyToClient

func (pool *Pool) SendUsersQtyToClient(client *Client) error

func (*Pool) ServeWs

func (pool *Pool) ServeWs(w http.ResponseWriter, r *http.Request)

ServeWs creates a new Client in the pool and starts reading of incoming history

func (*Pool) Start

func (pool *Pool) Start()

Jump to

Keyboard shortcuts

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