ws

package module
v0.0.0-...-ef5cc6b Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: MIT Imports: 11 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient() *Client

func (*Client) Close

func (self *Client) Close() error

func (*Client) Connect

func (self *Client) Connect(url string, headers http.Header) error

func (*Client) OnConnect

func (self *Client) OnConnect(handler func())

func (*Client) Read

func (self *Client) Read() (Message, error)

func (*Client) Send

func (self *Client) Send(msg Message) error

type ConnectedMessageBody

type ConnectedMessageBody map[string]any

func (ConnectedMessageBody) Address

func (self ConnectedMessageBody) Address() string

func (ConnectedMessageBody) ID

func (self ConnectedMessageBody) ID() string

type Message

type Message struct {
	ID     string      `json:"id"`
	ToID   string      `json:"to_id"`
	Type   MessageType `json:"type"`
	Body   any         `json:"body,omitempty"`
	SentAt time.Time   `json:"sent_at"`
}

func NewConnectedMessage

func NewConnectedMessage(body ConnectedMessageBody) Message

func NewDisconnectedMessage

func NewDisconnectedMessage(id string) Message

func NewMessage

func NewMessage(t MessageType, body any) Message

func NewTextMessage

func NewTextMessage(text string) Message

func (Message) String

func (self Message) String() string

func (Message) WithToID

func (self Message) WithToID(toId string) Message

type MessageType

type MessageType string
const (
	TEXT_MESSAGE_TYPE         MessageType = "text"
	CONNECTED_MESSAGE_TYPE    MessageType = "connected"
	DISCONNECTED_MESSAGE_TYPE MessageType = "disconnected"
)

func (MessageType) Valid

func (self MessageType) Valid() bool

type Socket

type Socket struct {
	ID        string
	CreatedAt time.Time
	// contains filtered or unexported fields
}

func (*Socket) Close

func (self *Socket) Close() error

func (*Socket) Read

func (self *Socket) Read() (Message, error)

func (*Socket) Send

func (self *Socket) Send(msg Message) error

type Sockets

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

func NewSockets

func NewSockets() *Sockets

func (*Sockets) Add

func (self *Sockets) Add(conn *websocket.Conn) *Socket

func (*Sockets) Del

func (self *Sockets) Del(id string)

func (*Sockets) Get

func (self *Sockets) Get() *Socket

func (*Sockets) GetByID

func (self *Sockets) GetByID(id string) *Socket

func (*Sockets) Send

func (self *Sockets) Send(msg Message) error

Jump to

Keyboard shortcuts

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