ws

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 16 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_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_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"
	PARAMS_UPDATED              = "Params updated"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Name        string         `json:"name"`
	Group       map[string]int `json:"group"`
	Subscribers []*Client      `json:"subscribers"`
}

* * Channel *

func (*Channel) Broadcast added in v0.0.177

func (ch *Channel) Broadcast(message []byte)

* * Broadcast a message to all subscribers * @param message []byte *

func (*Channel) Count added in v0.0.177

func (ch *Channel) Count() int

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

func (*Channel) Describe added in v1.0.11

func (ch *Channel) Describe() et.Json

* * Describe return the channel name * @return et.Json *

func (*Channel) Low added in v0.0.177

func (ch *Channel) Low() string

* * Low return the channel name in lowercase * @return string *

func (*Channel) NextTurn added in v0.0.177

func (ch *Channel) NextTurn(queue string) *Client

* * NextTurn return the next subscriber * @return *Client *

func (*Channel) QueueSubscribe added in v0.0.177

func (ch *Channel) QueueSubscribe(client *Client, queue string)

* * QueueSubscribe a client to channel * @param client *Client *

func (*Channel) Subscribe added in v0.0.177

func (ch *Channel) Subscribe(client *Client)

* * Subscribe a client to channel * @param client *Client *

func (*Channel) Unsubcribe

func (ch *Channel) Unsubcribe(clientId string) error

* * Unsubcribe a client from channel * @param clientId string * @return error *

func (*Channel) Up added in v0.0.177

func (ch *Channel) Up() string

* * Up return the channel name in uppercase * @return string *

type Client

type Client struct {
	Created_at time.Time `json:"created_at"`

	Id   string `json:"id"`
	Name string `json:"name"`
	Addr string `json:"addr"`

	Channels []string `json:"channels"`
	// contains filtered or unexported fields
}

func (*Client) Describe added in v1.0.11

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

* * Describe * @return et.Json *

func (*Client) From added in v0.0.177

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

* * From * @return et.Json *

type Hub

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

func NewWs added in v1.0.8

func NewWs() *Hub

* * NewWs * @return *Hub *

func (*Hub) Close added in v0.0.177

func (h *Hub) Close()

* * Close *

func (*Hub) ConnectHttp added in v1.0.7

func (h *Hub) ConnectHttp(w http.ResponseWriter, r *http.Request) (*Client, error)

* * ConnectHttp connect to the server using the http * @param w http.ResponseWriter * @param r *http.Request * @return *Client * @return error *

func (*Hub) GetChannels added in v1.0.11

func (h *Hub) GetChannels() []*Channel

* * GetChannels of the hub * @return []*Channel *

func (*Hub) GetClients added in v1.0.11

func (h *Hub) GetClients() []*Client

* * GetChannels of the hub * @return []*Channel *

func (*Hub) GetSubscribers

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

* * GetSubscribers * @param channel string * @return []*Client *

func (*Hub) Mute added in v0.0.177

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

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

func (*Hub) Publish

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

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

func (*Hub) Queue added in v1.0.11

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

* * Queue a client to hub channels * @param clientId string * @param channel string * @return error *

func (*Hub) RedisAdapter added in v0.0.177

func (h *Hub) RedisAdapter(params *RedisAdapterParams) error

* * RedisAdapter is a struct to manage the Redis connection * to broadcast messages to all clients in the cluster hub * @param params *RedisAdapterParams * @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 added in v0.0.177

func (h *Hub) SetName(name string)

* * SetName * @param name string *

func (*Hub) Start added in v1.0.8

func (h *Hub) Start()

* * Start the Websocket Hub *

func (*Hub) Subscribe added in v0.0.44

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

* * Subscribe a client to hub channels * @param clientId string * @param channel string * @return error *

func (*Hub) Unsubscribe added in v0.0.44

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

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

type Message added in v0.0.177

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"`
	Tp         TpMessage   `json:"tp"`
	Channel    string      `json:"channel"`
	Queue      string      `json:"queue"`
	Data       interface{} `json:"data"`
}

func DecodeMessage added in v0.0.177

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

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

func NewMessage added in v0.0.177

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

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

func (Message) Encode added in v0.0.177

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

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

func (Message) ToJson added in v1.0.11

func (e Message) ToJson() (et.Json, error)

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

func (Message) ToString added in v0.0.177

func (e Message) ToString() string

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

type MessageBroadcast added in v0.0.177

type MessageBroadcast struct {
	Kind    TpBroadcast `json:"kind"`
	To      string      `json:"channel"`
	Msg     Message     `json:"msg"`
	Ignored []string    `json:"ignored"`
	From    et.Json     `json:"from"`
}

* * MessageBroadcast is a struct to manage the message to broadcast *

func (MessageBroadcast) Encode added in v0.0.177

func (m MessageBroadcast) Encode() ([]byte, error)

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

type RedisAdapter added in v0.0.177

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

func NewRedisAdapter added in v0.0.177

func NewRedisAdapter(params *RedisAdapterParams) (*RedisAdapter, error)

* * NewRedisAdapter return a new RedisAdapter * @param params *RedisAdapterParams * @return *RedisAdapter * @return error *

func (*RedisAdapter) Broadcast added in v0.0.177

func (a *RedisAdapter) Broadcast(to string, msg Message, ignored []string, from et.Json) error

* * Broadcast a message to all clients in the cluster hub * @param to string * @param msg Message * @param ignored []string * @param from et.Json * @return error *

func (*RedisAdapter) Close added in v0.0.177

func (a *RedisAdapter) Close() error

* * Close the RedisAdapter * @return error *

func (*RedisAdapter) Command added in v0.0.177

func (a *RedisAdapter) Command(command string, params et.Json) error

* * Command send a command to all clients in the cluster hub * @param command string * @param params et.Json * @return error *

func (*RedisAdapter) Direct added in v0.0.177

func (a *RedisAdapter) Direct(to string, msg Message) error

* * Direct send a message to a specific client in the cluster hub * @param to string * @param msg Message * @return error *

type RedisAdapterParams added in v0.0.177

type RedisAdapterParams struct {
	Addr     string
	Password string
	DB       int
}

* * RedisAdapter is a struct to manage the Redis connection * to broadcast messages to all clients in the cluster hub *

type TpBroadcast added in v0.0.177

type TpBroadcast int
const (
	BroadcastAll TpBroadcast = iota
	BroadcastDirect
)

type TpMessage added in v1.0.11

type TpMessage int
const (
	TpPing TpMessage = iota
	TpSetFrom
	TpSubscribe
	TpUnsubscribe
	TpQueue
	TpPublish
	TpDirect
	TpConnect
	TpDisconnect
)

func ToTpMessage added in v1.0.11

func ToTpMessage(s string) TpMessage

func (TpMessage) String added in v1.0.11

func (s TpMessage) String() string

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