ws

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ws handles WebSocket connections and broadcasting messages to clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Client ID.
	ID int

	// Hub.
	Hub *Hub

	// WebSocket connection.
	Conn *websocket.Conn

	// To prevent pushes to the channel.
	Closed SafeBool

	// Buffered channel of outbound ws messages.
	Send chan models.WSMessage
}

Client is a single connected WS user.

func (*Client) Listen

func (c *Client) Listen()

Listen is a block method that listens for incoming messages from the client.

func (*Client) SendError

func (c *Client) SendError(msg string)

SendError sends an error message to client.

func (*Client) SendMessage

func (c *Client) SendMessage(b []byte, typ byte)

SendMessage sends a message to client.

func (*Client) Serve

func (c *Client) Serve()

Serve handles heartbeats and sending messages to the client.

type Hub

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

Hub maintains the set of registered websockets clients.

func NewHub

func NewHub(userStore userStore) *Hub

NewHub creates a new websocket hub.

func (*Hub) AddClient

func (h *Hub) AddClient(client *Client)

AddClient adds a new client to the hub.

func (*Hub) BroadcastMessage

func (h *Hub) BroadcastMessage(msg models.BroadcastMessage)

BroadcastMessage broadcasts a message to the specified users. If no users are specified, the message is broadcast to all users.

func (*Hub) RemoveClient

func (h *Hub) RemoveClient(client *Client)

RemoveClient removes a client from the hub.

type SafeBool

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

SafeBool is a thread-safe boolean.

func (*SafeBool) Get

func (b *SafeBool) Get() bool

Get returns the value of the SafeBool.

func (*SafeBool) Set

func (b *SafeBool) Set(value bool)

Set sets the value of the SafeBool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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