Documentation
¶
Index ¶
- Constants
- func Close() error
- func ConnectWs(host, scheme, clientId, name string) (*websocket.Conn, error)
- type Channel
- type Client
- type Conn
- type Hub
- func (h *Hub) GetSubscribers(channel string) []*Client
- func (h *Hub) Identify() et.Json
- 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) RedisAdapter(params *RedisAdapterParams) error
- func (h *Hub) Run()
- func (h *Hub) SendMessage(clientId string, msg Message) error
- func (h *Hub) SetName(name string)
- func (h *Hub) Stack(clientId string, channel string) error
- func (h *Hub) Subscribe(clientId string, channel string) error
- func (h *Hub) Unsubscribe(clientId string, channel string) error
- type HubParams
- type Message
- type MessageBroadcast
- type PubSub
- func (p *PubSub) Close()
- func (p *PubSub) Connect() (bool, error)
- func (p *PubSub) IsConnected() bool
- func (p *PubSub) Params(params et.Json) error
- func (p *PubSub) Ping()
- func (p *PubSub) Publish(channel string, message interface{})
- func (p *PubSub) SendMessage(clientId string, message interface{}) error
- func (p *PubSub) Stack(channel string, reciveFn func(m.Message))
- func (p *PubSub) Subscribe(channel string, reciveFn func(m.Message))
- func (p *PubSub) Type() string
- func (p *PubSub) Unsubscribe(channel string)
- type RedisAdapter
- type RedisAdapterParams
- type TpBroadcast
- type WsMessage
Constants ¶
const ( MSG_CLIENT_CONNECT = "Client connected %s to Hub:%s" MSG_CLIENT_DISCONNECT = "Client disconnected %s to Hub:%s" 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_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" PARAMS_UPDATED = "Params updated" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Channel ¶
type Channel struct {
Name string
TpBroadcast TpBroadcast
Subscribers []*Client
// contains filtered or unexported fields
}
Channel is a hub websocket channel
func (*Channel) Unsubcribe ¶ added in v0.0.2
Unsubcribe a client from channel
type Client ¶
type Client struct {
Created_at time.Time
Id string
Name string
Addr string
Channels []string
// contains filtered or unexported fields
}
func ConnectHttp ¶ added in v0.0.2
Connect to the server from the http client
type Hub ¶
type Hub struct {
Id string
Name string
Params *HubParams
// contains filtered or unexported fields
}
func (*Hub) GetSubscribers ¶ added in v0.0.2
Return client list subscribed to channel
func (*Hub) RedisAdapter ¶ added in v0.0.2
func (h *Hub) RedisAdapter(params *RedisAdapterParams) error
Set a adapter to make a cluster hub
func (*Hub) SendMessage ¶
Send a message to a client in a channel
type Message ¶
type Message struct {
Created_at time.Time `json:"created_at"`
Id string `json:"id"`
From et.Json `json:"from"`
Ignored []string `json:"ignored"`
Tp m.TpMessage `json:"tp"`
Channel string `json:"channel"`
Data interface{} `json:"data"`
// contains filtered or unexported fields
}
func DecodeMessage ¶
Decode return the message as struct
func NewMessage ¶
NewMessage create a new message
type MessageBroadcast ¶ added in v0.0.2
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.2
func (m MessageBroadcast) Encode() ([]byte, error)
Encode return the message as byte
type PubSub ¶ added in v0.0.2
func (*PubSub) Close ¶ added in v0.0.2
func (p *PubSub) Close()
Close the client websocket connection
func (*PubSub) IsConnected ¶ added in v0.0.2
Check if the client is connected
func (*PubSub) SendMessage ¶ added in v0.0.2
Send a message to the server
func (*PubSub) Stack ¶ added in v0.0.2
Subscribe to a channel type fisrt, so send message to first client
func (*PubSub) Unsubscribe ¶ added in v0.0.2
Unsubscribe from a channel
type RedisAdapter ¶ added in v0.0.2
type RedisAdapter struct {
// contains filtered or unexported fields
}
func NewRedisAdapter ¶
func NewRedisAdapter(params *RedisAdapterParams) (*RedisAdapter, error)
NewRedisAdapter create a new RedisAdapter
func (*RedisAdapter) Broadcast ¶ added in v0.0.2
Broadcast a message to all clients in the cluster hub
func (*RedisAdapter) Close ¶ added in v0.0.2
func (a *RedisAdapter) Close() error
Close the connection
type RedisAdapterParams ¶ added in v0.0.2
* * 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.2
type TpBroadcast int
const ( TpAll TpBroadcast = iota TpRoundRobin TpDirect TpCommand )
func (TpBroadcast) String ¶ added in v0.0.2
func (tp TpBroadcast) String() string
String return the string representation of the broadcast type