ws

package
v1.1.31 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MSG_CLIENT_CONNECT          = "Client connected id:%s name:%s to Hub:%s"
	MSG_CLIENT_DISCONNECT       = "Client disconnected %s name:%s to Hub:%s"
	MSG_CONNECT_SUCCESSFULLY    = "Connected successfully"
	MSG_DISCONNECT_SUCCESSFULLY = "Disconnected successfully"
	ERR_SERVER_NOT_FOUND        = "Server not found"
	ERR_CLIENT_NOT_FOUND        = "Client not found"
	ERR_CLIENT_IS_CLOSED        = "Client is closed"
	ERR_NOT_WS_SERVICE          = "Not websocket service"
	ERR_NOT_DEFINE_CLIENTID     = "Not define clientId"
	ERR_NOT_DEFINE_USERNAME     = "Not define username"
	ERR_NOT_CONNECT_WS          = "Not connect socket"
	ERR_CLIENT_DISCONNECTED     = "Client disconnected"
	ERR_CHANNEL_NOT_FOUND       = "Channel not found"
	ERR_CHANNEL_NOT_SUBSCRIBERS = "Channel not subscribers - %s"
	ERR_CHANNEL_EMPTY           = "Channel is empty"
	ERR_QUEUE_EMPTY             = "Queue is empty"
	ERR_PARAM_NOT_FOUND         = "Param not found"
	ERR_CLIENT_ID_EMPTY         = "Client id is empty"
	ERR_MESSAGE_UNFORMATTED     = "Message unformatted"
	ERR_REDISADAPTER_NOT_FOUND  = "Redis adapter not found"
	ERR_INVALID_ID              = "Invalid id"
	ERR_INVALID_NAME            = "Invalid name"
	ERR_ADAPTER_NOT_FOUND       = "Adapter not found"
	ERR_NOT_SIGNATURE           = "Not signature"
	PARAMS_UPDATED              = "Params updated"
)
View Source
const ServiceName = "Websocket"

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter added in v1.1.0

type Adapter interface {
	ConnectTo(params et.Json) error
	Close()
	Subscribed(channel string)
	UnSubscribed(channel string)
	Publish(channel string, msg Message)
}

func NewRedisAdapter

func NewRedisAdapter() Adapter

func NewWSAdapter added in v1.1.30

func NewWSAdapter() Adapter

type AdapterRedis added in v1.1.30

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

func (*AdapterRedis) Close added in v1.1.30

func (s *AdapterRedis) Close()

* * Close *

func (*AdapterRedis) ConnectTo added in v1.1.30

func (s *AdapterRedis) ConnectTo(params et.Json) error

* * ConnectTo * @param params et.Json * @return error *

func (*AdapterRedis) Publish added in v1.1.30

func (s *AdapterRedis) Publish(channel string, msg Message)

* * Publish * @param sub channel string *

func (*AdapterRedis) Subscribed added in v1.1.30

func (s *AdapterRedis) Subscribed(channel string)

* * Subscribed * @param channel string *

func (*AdapterRedis) UnSubscribed added in v1.1.30

func (s *AdapterRedis) UnSubscribed(channel string)

* * UnSubscribed * @param sub channel string *

type AdapterWS added in v1.1.30

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

func (*AdapterWS) Close added in v1.1.30

func (s *AdapterWS) Close()

* * Close *

func (*AdapterWS) ConnectTo added in v1.1.30

func (s *AdapterWS) ConnectTo(params et.Json) error

* * ConnectTo * @param params et.Json * @return error *

func (*AdapterWS) Publish added in v1.1.30

func (s *AdapterWS) Publish(channel string, msg Message)

* * Publish * @param sub channel string *

func (*AdapterWS) Subscribed added in v1.1.30

func (s *AdapterWS) Subscribed(channel string)

* * Subscribed * @param channel string *

func (*AdapterWS) UnSubscribed added in v1.1.30

func (s *AdapterWS) UnSubscribed(channel string)

* * UnSubscribed * @param sub channel string *

type Channel

type Channel struct {
	Name        string        `json:"name"`
	Subscribers []*Subscriber `json:"subscribers"`
	// contains filtered or unexported fields
}

* * Channel *

func (*Channel) Count

func (c *Channel) Count() int

* * Count return the number of subscribers * @return int *

type Client

type Client struct {
	Channels  map[string]func(Message)
	Attempts  *race.Value
	Connected *race.Value
	// contains filtered or unexported fields
}

func NewClient added in v1.1.0

func NewClient(config *ClientConfig) (*Client, error)

* * NewClient * @config config ConectPatams * @return erro *

func NewNode added in v1.1.30

func NewNode(config *ClientConfig) (*Client, error)

* * NewClient * @config config ConectPatams * @return erro *

func (*Client) Close added in v1.1.0

func (c *Client) Close()

* * Close *

func (*Client) Connect added in v1.1.0

func (c *Client) Connect() error

* * Connect * @return error *

func (*Client) DirectMessage added in v1.1.0

func (c *Client) DirectMessage(msg Message)

* * DirectMessage * @param msg Message *

func (*Client) From

func (c *Client) From() et.Json

* * From * @return et.Json *

func (*Client) Listener added in v1.1.0

func (c *Client) Listener()

* * read *

func (*Client) Ping added in v1.1.0

func (c *Client) Ping()

* * Ping *

func (*Client) Publish added in v1.1.0

func (c *Client) Publish(channel string, message interface{})

* * Publish a message to a channel * @param channel string * @param message interface{} *

func (*Client) Queue added in v1.1.0

func (c *Client) Queue(channel, queue string, reciveFn func(Message))

* * Queue to a channel * @param channel, queue string * @param reciveFn func(message.Message) *

func (*Client) Reconnect added in v1.1.0

func (c *Client) Reconnect()

func (*Client) ReconnectCallback added in v1.1.0

func (c *Client) ReconnectCallback()

* * ReconnectCallback *

func (*Client) SendMessage added in v1.1.0

func (c *Client) SendMessage(clientId string, message interface{}) error

* * SendMessage * @param clientId string * @param message interface{} * @return error *

func (*Client) SetDirectMessageCallback added in v1.1.8

func (c *Client) SetDirectMessageCallback(reciveFn func(Message))

* * SetDirectMessageCallback * @param reciveFn func(message.Message) *

func (*Client) SetFrom added in v1.1.0

func (c *Client) SetFrom(name string) error

* * SetFrom * @param config et.Json * @return error *

func (*Client) SetReconnectCallback added in v1.1.0

func (c *Client) SetReconnectCallback(reciveFn func(c *Client))

* * SetReconnectCallback * @param reciveFn func() *

func (*Client) Stack added in v1.1.0

func (c *Client) Stack(channel string, reciveFn func(Message))

* * Stack to a channel * @param channel string * @param reciveFn func(message.Message) *

func (*Client) Subscribe added in v1.1.0

func (c *Client) Subscribe(channel string, reciveFn func(Message))

* * Subscribe to a channel * @param channel string * @param reciveFn func(message.Message) *

func (*Client) Unsubscribe added in v1.1.0

func (c *Client) Unsubscribe(channel string)

* * Unsubscribe to a channel * @param channel string *

type ClientConfig added in v1.1.0

type ClientConfig struct {
	ClientId  string
	Name      string
	Url       string
	Header    http.Header
	Reconnect int
}

func (*ClientConfig) From added in v1.1.0

func (s *ClientConfig) From() et.Json

* * From * @return et.Json *

type Hub

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

func NewHub added in v1.1.0

func NewHub() *Hub

* * NewHub * @return *Hub *

func ServerHttp added in v1.1.0

func ServerHttp(port int, username, password string) *Hub

* * ServerHttp * @params port int * @params username string * @params password string * @return *Hub *

func (*Hub) Close

func (h *Hub) Close()

* * Close *

func (*Hub) Describe added in v1.1.0

func (h *Hub) Describe() et.Json

func (*Hub) DrainChannel added in v1.1.0

func (h *Hub) DrainChannel(channel, queue string) error

* * DrainChannel * @param channel *Channel *

func (*Hub) From

func (h *Hub) From() et.Json

* * Identify the hub * @return et.Json *

func (*Hub) GetChanel added in v1.1.0

func (h *Hub) GetChanel(name string) *Channel

* * GetChanel * @param name string * @return *Channel *

func (*Hub) GetChannels

func (h *Hub) GetChannels(name, queue string) et.Items

* * GetChannels of the hub * @param key string * @return et.Items *

func (*Hub) GetClients

func (h *Hub) GetClients(key string) et.Items

* * GetClients of the hub * @param key string * @return et.Items *

func (*Hub) HttpCluster added in v1.1.30

func (h *Hub) HttpCluster(w http.ResponseWriter, r *http.Request)

* * HttpCluster connect to the server using the http * @param w http.ResponseWriter * @param r *http.Request *

func (*Hub) HttpConnect added in v1.1.0

func (h *Hub) HttpConnect(w http.ResponseWriter, r *http.Request)

* * HttpConnect connect to the server using the http * @param w http.ResponseWriter * @param r *http.Request *

func (*Hub) HttpDescribe added in v1.1.0

func (h *Hub) HttpDescribe(w http.ResponseWriter, r *http.Request)

* * HttpGetPublications * @param w http.ResponseWriter * @param r *http.Request *

func (*Hub) HttpGetPublications added in v1.1.0

func (h *Hub) HttpGetPublications(w http.ResponseWriter, r *http.Request)

* * HttpGetPublications * @param w http.ResponseWriter * @param r *http.Request *

func (*Hub) HttpGetSubscribers added in v1.1.0

func (h *Hub) HttpGetSubscribers(w http.ResponseWriter, r *http.Request)

* * HttpGetSubscribers * @param w http.ResponseWriter * @param r *http.Request *

func (*Hub) HttpStream added in v1.1.0

func (h *Hub) HttpStream(w http.ResponseWriter, r *http.Request)

* * HttpStream connect to the server using the http * @param w http.ResponseWriter * @param r *http.Request *

func (*Hub) IsRun added in v1.1.2

func (h *Hub) IsRun() bool

* * IsRun * @return bool *

func (*Hub) JoinTo added in v1.1.30

func (h *Hub) JoinTo(master et.Json) error

* * JoinTo * @param config *ClientConfig *

func (*Hub) Live added in v1.1.0

func (h *Hub) Live()

* * Live *

func (*Hub) NewChannel added in v1.1.0

func (h *Hub) NewChannel(name string, duration time.Duration) *Channel

* * NewChannel * @param name string * @param duration time.Duration * @return *Channel *

func (*Hub) NewQueue added in v1.1.0

func (h *Hub) NewQueue(name, queue string, duration time.Duration) *Queue

* * NewQueue * @param name string * @param duration time.Duration * @return *Queue *

func (*Hub) Publish

func (h *Hub) Publish(channel, queue string, msg Message, ignored []string, from et.Json)

* * Publish a message to a channel * @param channel string * @param msg Message * @param ignored []string * @param from et.Json * @return error *

func (*Hub) QueueSubscribe added in v1.1.0

func (h *Hub) QueueSubscribe(clientId string, channel, queue string) error

* * QueueSubscribe * @param clientId string * @param channel string * @param queue string * @return error *

func (*Hub) SendMessage

func (h *Hub) SendMessage(clientId string, msg Message) error

* * SendMessage * @param clientId string * @param msg Message * @return error *

func (*Hub) SetName

func (h *Hub) SetName(name string)

* * SetName * @param name string *

func (*Hub) Stack added in v1.1.0

func (h *Hub) Stack(clientId string, channel string) error

* * Stack * @param clientId string * @param channel string * @return error *

func (*Hub) Start

func (h *Hub) Start()

* * Start *

func (*Hub) Subscribe

func (h *Hub) Subscribe(clientId string, channel string) error

* * Subscribe * @param clientId string * @param channel string * @return error *

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(clientId string, channel, queue string) error

* * Unsubscribe a client from hub channels * @param clientId string * @param channel string * @return error *

type Message

type Message struct {
	Created_at time.Time   `json:"created_at"`
	Id         string      `json:"id"`
	From       et.Json     `json:"from"`
	To         string      `json:"to"`
	Ignored    []string    `json:"ignored"`
	Data       interface{} `json:"data"`
	Channel    string      `json:"channel"`
	Queue      string      `json:"queue"`
	Tp         et.Json     `json:"tp"`
	// contains filtered or unexported fields
}

func DecodeMessage

func DecodeMessage(data []byte) (Message, error)

* * DecodeMessage * @param []byte * @return Message *

func NewMessage

func NewMessage(from et.Json, message interface{}, tp TpMessage) Message

* * NewMessage * @param et.Json * @param interface{} * @param TpMessage * @return Message *

func (Message) Encode

func (e Message) Encode() ([]byte, error)

* * Encode return the message as byte array * @return []byte *

func (Message) ToJson

func (e Message) ToJson() et.Json

* * ToJson return the message as et.Json * @return et.Json *

func (Message) ToString

func (e Message) ToString() string

* * ToString return the message as string * @return string *

type Queue added in v1.1.0

type Queue struct {
	Name        string        `json:"name"`
	Queue       string        `json:"queue"`
	Turn        int           `json:"turn"`
	Subscribers []*Subscriber `json:"subscribers"`
	// contains filtered or unexported fields
}

func (*Queue) Count added in v1.1.0

func (c *Queue) Count() int

* * Count return the number of subscribers * @return int *

type Subscriber added in v1.1.0

type Subscriber struct {
	Created_at time.Time           `json:"created_at"`
	Id         string              `json:"id"`
	Name       string              `json:"name"`
	Addr       string              `json:"addr"`
	Channels   map[string]*Channel `json:"channels"`
	Queue      map[string]*Queue   `json:"queue"`
	// contains filtered or unexported fields
}

func (*Subscriber) From added in v1.1.0

func (c *Subscriber) From() et.Json

* * From * @return et.Json *

type TpMessage

type TpMessage int
const (
	TpPing           TpMessage = iota // 0
	TpSetFrom                         // 1
	TpSubscribe                       // 2
	TpQueueSubscribe                  // 3
	TpStack                           // 4
	TpUnsubscribe                     // 5
	TpPublish                         // 6
	TpDirect                          // 7
	TpConnect                         // 8
	TpDisconnect                      // 9
)

func ToTpMessage

func ToTpMessage(s string) TpMessage

func (TpMessage) String

func (s TpMessage) String() string

func (TpMessage) ToJson added in v1.1.0

func (s TpMessage) ToJson() et.Json

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