websocket

package
v1.9.8 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EchoHandler added in v1.3.1

func EchoHandler(_ context.Context, s *Service, conn *Connection, svc string, cmd string, param []byte, logger util.Logger) error

func LogHandler added in v1.3.1

func LogHandler(_ context.Context, _ *Service, conn *Connection, svc string, cmd string, param []byte, logger util.Logger) error

func OnMessage

func OnMessage(ctx context.Context, s *Service, connID uuid.UUID, message *Message, logger util.Logger) error

func ReadSocketLoop added in v0.7.0

func ReadSocketLoop(
	connID uuid.UUID, sock *websocket.Conn, onMessage func(m *Message) error, onDisconnect func() error, logger util.Logger, stats ...*Stats,
) error

Types

type Channel

type Channel struct {
	Key        string      `json:"key"`
	ConnIDs    []uuid.UUID `json:"connIDs"`
	LastUpdate time.Time   `json:"lastUpdate"`
	Stats      *Stats      `json:"stats,omitempty"`
}

type ConnectEvent

type ConnectEvent func(s *Service, conn *Connection, logger util.Logger) error

type Connection

type Connection struct {
	ID       uuid.UUID     `json:"id"`
	Profile  *user.Profile `json:"profile,omitzero"`
	Svc      string        `json:"svc,omitzero"`
	ModelID  *uuid.UUID    `json:"modelID,omitzero"`
	Channels []string      `json:"channels,omitempty"`
	Started  time.Time     `json:"started,omitzero"`
	Stats    *Stats        `json:"stats,omitempty"`
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(svc string, profile *user.Profile, socket *websocket.Conn, handler Handler) *Connection

func (*Connection) Close

func (c *Connection) Close(logger util.Logger) error

func (*Connection) Read

func (c *Connection) Read() ([]byte, error)

func (*Connection) String added in v0.7.0

func (c *Connection) String() string

func (*Connection) ToStatus

func (c *Connection) ToStatus() *Status

func (*Connection) Username added in v0.8.17

func (c *Connection) Username() string

func (*Connection) Write

func (c *Connection) Write(b []byte) error

type Handler

type Handler func(ctx context.Context, s *Service, conn *Connection, svc string, cmd string, param []byte, logger util.Logger) error

type Message

type Message struct {
	From    *uuid.UUID     `json:"from,omitzero"`
	Channel string         `json:"channel,omitzero"`
	Cmd     string         `json:"cmd"`
	Param   jsontext.Value `json:"param"`
}

func NewMessage

func NewMessage(userID *uuid.UUID, ch string, cmd string, param any) *Message

func (*Message) String

func (m *Message) String() string

type OnlineUpdate

type OnlineUpdate struct {
	UserID    uuid.UUID `json:"userID"`
	Connected bool      `json:"connected"`
}

type Service

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

func NewService

func NewService(onOpen ConnectEvent, onClose ConnectEvent) *Service

func (*Service) Broadcast added in v0.11.15

func (s *Service) Broadcast(message *Message, logger util.Logger, except ...uuid.UUID) error

func (*Service) ChannelList

func (s *Service) ChannelList(params *filter.Params) []string

func (*Service) Close

func (s *Service) Close(logger util.Logger)

func (*Service) Count

func (s *Service) Count() int

func (*Service) Disconnect

func (s *Service) Disconnect(connID uuid.UUID, logger util.Logger) (bool, error)

func (*Service) GetAllMembers added in v0.6.22

func (s *Service) GetAllMembers(key string) []*Connection

func (*Service) GetByID

func (s *Service) GetByID(id uuid.UUID, logger util.Logger) *Status

func (*Service) GetChannel added in v0.6.22

func (s *Service) GetChannel(ch string) *Channel

func (*Service) GetConnection added in v0.6.22

func (s *Service) GetConnection(id uuid.UUID) *Connection

func (*Service) GetOnline

func (s *Service) GetOnline(key string) []uuid.UUID

func (*Service) Join

func (s *Service) Join(connID uuid.UUID, ch string, logger util.Logger) (bool, error)

func (*Service) Leave

func (s *Service) Leave(connID uuid.UUID, ch string, logger util.Logger) (bool, error)

func (*Service) ReadLoop

func (s *Service) ReadLoop(ctx context.Context, connID uuid.UUID, logger util.Logger) error

func (*Service) Register

func (s *Service) Register(profile *user.Profile, c *websocket.Conn, h Handler, logger util.Logger) (*Connection, error)

func (*Service) RegisterTap added in v0.7.0

func (s *Service) RegisterTap(w http.ResponseWriter, r *http.Request, logger util.Logger) (uuid.UUID, error)

func (*Service) RemoveTap added in v0.7.0

func (s *Service) RemoveTap(connID uuid.UUID, logger util.Logger)

func (*Service) ReplaceHandlers added in v1.2.10

func (s *Service) ReplaceHandlers(onOpen ConnectEvent, onClose ConnectEvent)

func (*Service) Stats added in v1.8.2

func (s *Service) Stats(connID *uuid.UUID) (*Stats, error)

func (*Service) Status

func (s *Service) Status() ([]string, []*Connection, []uuid.UUID)

func (*Service) Terminal added in v1.3.4

func (s *Service) Terminal(ch string, logger util.Logger) func(_ string, b []byte) error

func (*Service) Upgrade added in v0.7.0

func (s *Service) Upgrade(
	_ context.Context, w http.ResponseWriter, r *http.Request, channel string,
	profile *user.Profile, handler Handler, logger util.Logger,
) (uuid.UUID, error)

func (*Service) UserList

func (s *Service) UserList(params *filter.Params) Statuses

func (*Service) WriteChannel

func (s *Service) WriteChannel(message *Message, logger util.Logger, except ...uuid.UUID) error

func (*Service) WriteCloseRequest added in v1.5.18

func (s *Service) WriteCloseRequest(connID uuid.UUID, logger util.Logger) error

func (*Service) WriteMessage

func (s *Service) WriteMessage(connID uuid.UUID, message *Message, logger util.Logger) error

func (*Service) WriteTap added in v0.7.0

func (s *Service) WriteTap(message *Message, logger util.Logger)

type Stats added in v1.8.2

type Stats struct {
	MessagesSent     int       `json:"messagesSent"`
	MessagesReceived int       `json:"messagesReceived"`
	BytesSent        int       `json:"bytesSent"`
	BytesReceived    int       `json:"bytesReceived"`
	Started          time.Time `json:"started,omitempty"`
}

func NewStats added in v1.8.2

func NewStats() *Stats

func (*Stats) Clone added in v1.8.2

func (s *Stats) Clone() *Stats

func (*Stats) Received added in v1.8.2

func (s *Stats) Received(b int)

func (*Stats) Sent added in v1.8.2

func (s *Stats) Sent(b int)

func (*Stats) String added in v1.8.2

func (s *Stats) String() string

type Status

type Status struct {
	ID       uuid.UUID `json:"id"`
	Username string    `json:"username"`
	Channels []string  `json:"channels"`
}

type Statuses

type Statuses = []*Status

type UpdateMemberParams

type UpdateMemberParams struct {
	ID   uuid.UUID `json:"id"`
	Role string    `json:"role"`
}

Jump to

Keyboard shortcuts

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