chat

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: Apache-2.0 Imports: 12 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.

Functions

This section is empty.

Types

type Client

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

Client represents the relationship between a user and websocket connections.

type Error added in v0.2.0

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

Error represents a chat error.

func NewError added in v0.2.0

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

NewError creates a new Error.

func (Error) Error added in v0.2.0

func (e Error) Error() string

Error implements the Error interface.

func (Error) IsError added in v0.2.0

func (e Error) IsError() bool

IsError checks if the error of severity error.

func (Error) IsGlobal added in v0.2.0

func (e Error) IsGlobal() bool

IsGlobal returns true if the error is a global error.

func (Error) IsWarning added in v0.2.0

func (e Error) IsWarning() bool

IsWarning checks if the error of severity warning.

type ErrorSeverity added in v0.2.0

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 added in v0.2.0

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

GetClient gets a client.

func (*Room) IsAtCapacity added in v0.2.0

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