Documentation
¶
Index ¶
- Constants
- type Channel
- func (ch *Channel) Broadcast(message []byte)
- func (ch *Channel) Count() int
- func (ch *Channel) Describe() et.Json
- func (ch *Channel) Low() string
- func (ch *Channel) NextTurn(queue string) *Client
- func (ch *Channel) QueueSubscribe(client *Client, queue string)
- func (ch *Channel) Subscribe(client *Client)
- func (ch *Channel) Unsubcribe(clientId string) error
- func (ch *Channel) Up() string
- type Client
- type Hub
- func (h *Hub) Close()
- func (h *Hub) ConnectHttp(w http.ResponseWriter, r *http.Request) (*Client, error)
- func (h *Hub) From() et.Json
- func (h *Hub) GetChannels() []*Channel
- func (h *Hub) GetClients() []*Client
- func (h *Hub) GetSubscribers(channel string) []*Client
- func (h *Hub) Mute(channel string, msg Message, ignored []string, from et.Json) error
- func (h *Hub) Publish(channel string, msg Message, ignored []string, from et.Json) error
- func (h *Hub) Queue(clientId string, channel, queue string) error
- func (h *Hub) RedisAdapter(params *RedisAdapterParams) error
- func (h *Hub) SendMessage(clientId string, msg Message) error
- func (h *Hub) SetName(name string)
- func (h *Hub) Start()
- func (h *Hub) Subscribe(clientId string, channel string) error
- func (h *Hub) Unsubscribe(clientId string, channel string) error
- type Message
- type MessageBroadcast
- type RedisAdapter
- type RedisAdapterParams
- type TpBroadcast
- type TpMessage
- type WsMessage
Constants ¶
const ( MSG_CLIENT_CONNECT = "Client connected id:%s name:%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) QueueSubscribe ¶
* * QueueSubscribe a client to channel * @param client *Client *
func (*Channel) Unsubcribe ¶
* * Unsubcribe a client from channel * @param clientId string * @return error *
type Client ¶
type Hub ¶
func (*Hub) ConnectHttp ¶
* * ConnectHttp connect to the server using the http * @param w http.ResponseWriter * @param r *http.Request * @return *Client * @return error *
func (*Hub) GetChannels ¶
* * GetChannels of the hub * @return []*Channel *
func (*Hub) GetClients ¶
* * GetChannels of the hub * @return []*Channel *
func (*Hub) GetSubscribers ¶
* * GetSubscribers * @param channel string * @return []*Client *
func (*Hub) Mute ¶
* * Mute a message to a channel * @param channel string * @param msg Message * @param ignored []string * @param from et.Json * @return error *
func (*Hub) Publish ¶
* * Publish a message to a channel * @param channel string * @param msg Message * @param ignored []string * @param from et.Json * @return error *
func (*Hub) Queue ¶
* * Queue a client to hub channels * @param clientId string * @param channel string * @return error *
func (*Hub) RedisAdapter ¶
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 ¶
* * SendMessage * @param clientId string * @param msg Message * @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"`
Tp TpMessage `json:"tp"`
Channel string `json:"channel"`
Queue string `json:"queue"`
Data interface{} `json:"data"`
}
func DecodeMessage ¶
* * DecodeMessage * @param []byte * @return Message *
func NewMessage ¶
* * NewMessage * @param et.Json * @param interface{} * @param TpMessage * @return Message *
type MessageBroadcast ¶
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 ¶
func (m MessageBroadcast) Encode() ([]byte, error)
* * Encode return the message as byte array * @return []byte * @return error *
type RedisAdapter ¶
type RedisAdapter struct {
// contains filtered or unexported fields
}
func NewRedisAdapter ¶
func NewRedisAdapter(params *RedisAdapterParams) (*RedisAdapter, error)
* * NewRedisAdapter return a new RedisAdapter * @param params *RedisAdapterParams * @return *RedisAdapter * @return error *
func (*RedisAdapter) Broadcast ¶
* * 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 ¶
func (a *RedisAdapter) Close() error
* * Close the RedisAdapter * @return error *
type RedisAdapterParams ¶
* * RedisAdapter is a struct to manage the Redis connection * to broadcast messages to all clients in the cluster hub *