ws

package
v0.0.146 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MSG_CLIENT_CONNECT      = "Client connected %s to Hub:%s"
	MSG_CLIENT_DISCONNECT   = "Client disconnected %s to Hub:%s"
	ERR_NOT_WS_SERVICE      = "not websocket service"
	ERR_NOT_DEFINE_CLIENTID = "not define clientId"
	ERR_NOT_DEFINE_USERNAME = "not define username"
)

Variables

This section is empty.

Functions

func Broadcast

func Broadcast(message interface{}, ignoreId string) error

func Close

func Close() error

func Publish

func Publish(channel string, message interface{}, ignoreId string) error

func SendMessage

func SendMessage(clientId, channel string, message interface{}) (bool, error)

func Subscribe added in v0.0.44

func Subscribe(clientId string, channel string) bool

func Unsubscribe added in v0.0.44

func Unsubscribe(clientId string, channel string) bool

Types

type Channel

type Channel struct {
	Name        string
	Subscribers []*Client
	// contains filtered or unexported fields
}

func GetChannels

func GetChannels() []*Channel

func NewChanel

func NewChanel(hub *Hub, name string) *Channel

func (*Channel) Unsubcribe

func (ch *Channel) Unsubcribe(clientId string)

type Client

type Client struct {
	Id   string
	Name string
	Addr string
	// contains filtered or unexported fields
}

func Connect

func Connect(w http.ResponseWriter, r *http.Request) (*Client, error)

func GetClients

func GetClients() []*Client

func GetSubscribers

func GetSubscribers(channel string) []*Client

func NewClient

func NewClient(hub *Hub, socket *websocket.Conn, id, name string) (*Client, bool)

func (*Client) Channels

func (c *Client) Channels() []*Channel

func (*Client) Clear

func (c *Client) Clear()

func (*Client) Close

func (c *Client) Close()

func (*Client) Read

func (c *Client) Read()

func (*Client) SendMessage

func (c *Client) SendMessage(message []byte)

func (*Client) Subscribe

func (c *Client) Subscribe(channel string)

func (*Client) Subscribers

func (c *Client) Subscribers(channels []string)

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(channel string)

func (*Client) Unsubscribers

func (c *Client) Unsubscribers(channels []string)

func (*Client) Write

func (c *Client) Write()

type ClientWS added in v0.0.138

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

func Cliente added in v0.0.138

func Cliente(host string, reciveFn func(message []byte)) *ClientWS

Create a new client websocket connection

func (*ClientWS) Close added in v0.0.138

func (s *ClientWS) Close()

Close the client websocket connection

func (*ClientWS) Write added in v0.0.138

func (s *ClientWS) Write(message string) error

type Conn

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

func Load

func Load() (*Conn, error)

type Hub

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

func NewHub

func NewHub() *Hub

Create a new hub

func (*Hub) Broadcast

func (hub *Hub) Broadcast(message interface{}, ignoreId string)

Broadcast a message to all clients less the ignore client

func (*Hub) GetSubscribers

func (hub *Hub) GetSubscribers(channel string) []*Client

func (*Hub) Publish

func (hub *Hub) Publish(channel string, message interface{}, ignoreId string)

Publish a message to a channel less the ignore client

func (*Hub) Run

func (hub *Hub) Run()

Run the hub

func (*Hub) SendMessage

func (hub *Hub) SendMessage(clientId, channel string, message interface{}) bool

Send a message to a client in a channel

func (*Hub) Subscribe added in v0.0.44

func (hub *Hub) Subscribe(clientId string, channel string) bool

Subscribe a client to hub channels

func (*Hub) Unsubscribe added in v0.0.44

func (hub *Hub) Unsubscribe(clientId string, channel string) bool

type WsMessage

type WsMessage struct {
	Type    string      `json:"type"`
	Payload interface{} `json:"payload"`
}

Jump to

Keyboard shortcuts

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