Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect() error
- func (c *Client) Disconnect() error
- func (c *Client) NewSubscription(channel string) (*Subscription, error)
- func (c *Client) OnConnect(handler ConnectHandler)
- func (c *Client) OnDisconnect(handler DisconnectHandler)
- func (c *Client) OnError(handler ErrorHandler)
- func (c *Client) OnMessage(handler MessageHandler)
- func (c *Client) OnPrivateSub(handler PrivateSubHandler)
- func (c *Client) OnRefresh(handler RefreshHandler)
- func (c *Client) Publish(channel string, data []byte) error
- func (c *Client) RPC(data []byte) ([]byte, error)
- func (c *Client) Send(data []byte) error
- func (c *Client) SetConnectData(data proto.Raw)
- func (c *Client) SetHeader(key, value string)
- func (c *Client) SetToken(token string)
- type ClientInfo
- type Config
- type ConnectEvent
- type ConnectHandler
- type DisconnectEvent
- type DisconnectHandler
- type Error
- type ErrorEvent
- type ErrorHandler
- type EventHub
- type JoinEvent
- type JoinHandler
- type LeaveEvent
- type LeaveHandler
- type MessageEvent
- type MessageHandler
- type PresenceStats
- type PrivateSubEvent
- type PrivateSubHandler
- type Publication
- type PublishEvent
- type PublishHandler
- type RefreshHandler
- type SubscribeErrorEvent
- type SubscribeErrorHandler
- type SubscribeSuccessEvent
- type SubscribeSuccessHandler
- type Subscription
- func (s *Subscription) Channel() string
- func (s *Subscription) History() ([]Publication, error)
- func (s *Subscription) OnJoin(handler JoinHandler)
- func (s *Subscription) OnLeave(handler LeaveHandler)
- func (s *Subscription) OnPublish(handler PublishHandler)
- func (s *Subscription) OnSubscribeError(handler SubscribeErrorHandler)
- func (s *Subscription) OnSubscribeSuccess(handler SubscribeSuccessHandler)
- func (s *Subscription) OnUnsubscribe(handler UnsubscribeHandler)
- func (s *Subscription) Presence() (map[string]ClientInfo, error)
- func (s *Subscription) PresenceStats() (PresenceStats, error)
- func (s *Subscription) Publish(data []byte) error
- func (s *Subscription) Status() int
- func (s *Subscription) Subscribe() error
- func (s *Subscription) Unsubscribe() error
- type SubscriptionEventHub
- type UnsubscribeEvent
- type UnsubscribeHandler
Constants ¶
const ( DISCONNECTED = iota CONNECTING CONNECTED RECONNECTING CLOSED )
Describe client connection statuses.
const ( // DefaultHandshakeTimeout ... DefaultHandshakeTimeout = time.Second // DefaultReadTimeout ... DefaultReadTimeout = 5 * time.Second // DefaultWriteTimeout ... DefaultWriteTimeout = time.Second // DefaultPingInterval ... DefaultPingInterval = 25 * time.Second // DefaultPrivateChannelPrefix ... DefaultPrivateChannelPrefix = "$" )
const ( NEW = iota SUBSCRIBING SUBSCRIBED SUBERROR UNSUBSCRIBED )
Describe different states of Sub.
Variables ¶
var ( // ErrTimeout ... ErrTimeout = errors.New("timeout") // ErrClientClosed ... ErrClientClosed = errors.New("client closed") // ErrClientDisconnected ... ErrClientDisconnected = errors.New("client disconnected") // ErrClientExpired ... ErrClientExpired = errors.New("client connection expired") // ErrReconnectFailed ... ErrReconnectFailed = errors.New("reconnect failed") // ErrDuplicateSubscription ... ErrDuplicateSubscription = errors.New("duplicate subscription") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client describes client connection to Centrifugo server.
func (*Client) NewSubscription ¶ added in v0.2.0
func (c *Client) NewSubscription(channel string) (*Subscription, error)
NewSubscription allows to create new subscription on channel.
func (*Client) OnConnect ¶ added in v0.2.0
func (c *Client) OnConnect(handler ConnectHandler)
OnConnect is a function to handle connect event.
func (*Client) OnDisconnect ¶ added in v0.2.0
func (c *Client) OnDisconnect(handler DisconnectHandler)
OnDisconnect is a function to handle disconnect event.
func (*Client) OnError ¶ added in v0.2.0
func (c *Client) OnError(handler ErrorHandler)
OnError is a function that will receive unhandled errors for logging.
func (*Client) OnMessage ¶ added in v0.2.0
func (c *Client) OnMessage(handler MessageHandler)
OnMessage allows to process async message from server to client.
func (*Client) OnPrivateSub ¶ added in v0.2.0
func (c *Client) OnPrivateSub(handler PrivateSubHandler)
OnPrivateSub needed to handle private channel subscriptions.
func (*Client) OnRefresh ¶ added in v0.2.0
func (c *Client) OnRefresh(handler RefreshHandler)
OnRefresh handles refresh event when client's credentials expired and must be refreshed.
func (*Client) RPC ¶
RPC allows to make RPC – send data to server ant wait for response. RPC handler must be registered on server.
func (*Client) SetConnectData ¶
SetConnectData allows to set data to send in connect message.
type ClientInfo ¶
type ClientInfo = proto.ClientInfo
ClientInfo is short information about client connection.
type Config ¶
type Config struct { // PrivateChannelPrefix is private channel prefix. PrivateChannelPrefix string // ReadTimeout is how long to wait read operations to complete. ReadTimeout time.Duration // WriteTimeout is Websocket write timeout. WriteTimeout time.Duration // PingInterval is how often to send ping commands to server. PingInterval time.Duration // HandshakeTimeout specifies the duration for the handshake to complete. HandshakeTimeout time.Duration // TLSConfig specifies the TLS configuration to use with tls.Client. // If nil, the default configuration is used. TLSConfig *tls.Config // EnableCompression specifies if the client should attempt to negotiate // per message compression (RFC 7692). Setting this value to true does not // guarantee that compression will be supported. Currently only "no context // takeover" modes are supported. EnableCompression bool // CookieJar specifies the cookie jar. // If CookieJar is nil, cookies are not sent in requests and ignored // in responses. CookieJar http.CookieJar // Header specifies custom HTTP Header to send. Header http.Header }
Config contains various client options.
type ConnectEvent ¶
ConnectEvent is a connect event context passed to OnConnect callback.
type ConnectHandler ¶
type ConnectHandler interface {
OnConnect(*Client, ConnectEvent)
}
ConnectHandler is an interface describing how to handle connect event.
type DisconnectEvent ¶
DisconnectEvent is a disconnect event context passed to OnDisconnect callback.
type DisconnectHandler ¶
type DisconnectHandler interface {
OnDisconnect(*Client, DisconnectEvent)
}
DisconnectHandler is an interface describing how to handle disconnect event.
type ErrorEvent ¶
type ErrorEvent struct {
Message string
}
ErrorEvent is an error event context passed to OnError callback.
type ErrorHandler ¶
type ErrorHandler interface {
OnError(*Client, ErrorEvent)
}
ErrorHandler is an interface describing how to handle error event.
type EventHub ¶
type EventHub struct {
// contains filtered or unexported fields
}
EventHub has all event handlers for client.
type JoinEvent ¶
type JoinEvent struct {
ClientInfo
}
JoinEvent has info about user who joined channel.
type JoinHandler ¶
type JoinHandler interface {
OnJoin(*Subscription, JoinEvent)
}
JoinHandler is a function to handle join messages.
type LeaveEvent ¶
type LeaveEvent struct {
ClientInfo
}
LeaveEvent has info about user who left channel.
type LeaveHandler ¶
type LeaveHandler interface {
OnLeave(*Subscription, LeaveEvent)
}
LeaveHandler is a function to handle leave messages.
type MessageEvent ¶
type MessageEvent struct {
Data []byte
}
MessageEvent is an event for async message from server to client.
type MessageHandler ¶
type MessageHandler interface {
OnMessage(*Client, MessageEvent)
}
MessageHandler is an interface describing how to async message from server.
type PresenceStats ¶
PresenceStats represents short presence information.
type PrivateSubEvent ¶
PrivateSubEvent contains info required to create PrivateSign when client wants to subscribe on private channel.
type PrivateSubHandler ¶
type PrivateSubHandler interface {
OnPrivateSub(*Client, PrivateSubEvent) (string, error)
}
PrivateSubHandler is an interface describing how to handle private subscription request.
type Publication ¶
type Publication = proto.Publication
Publication allows to deliver custom payload to all channel subscribers.
type PublishEvent ¶
type PublishEvent struct {
Publication
}
PublishEvent has info about received channel Publication.
type PublishHandler ¶
type PublishHandler interface {
OnPublish(*Subscription, PublishEvent)
}
PublishHandler is a function to handle messages published in channels.
type RefreshHandler ¶
RefreshHandler is an interface describing how to handle token refresh event.
type SubscribeErrorEvent ¶
type SubscribeErrorEvent struct {
Error string
}
SubscribeErrorEvent is a subscribe error event context passed to event callback.
type SubscribeErrorHandler ¶
type SubscribeErrorHandler interface {
OnSubscribeError(*Subscription, SubscribeErrorEvent)
}
SubscribeErrorHandler is a function to handle subscribe error event.
type SubscribeSuccessEvent ¶
SubscribeSuccessEvent is a subscribe success event context passed to event callback.
type SubscribeSuccessHandler ¶
type SubscribeSuccessHandler interface {
OnSubscribeSuccess(*Subscription, SubscribeSuccessEvent)
}
SubscribeSuccessHandler is a function to handle subscribe success event.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents client subscription to channel.
func (*Subscription) Channel ¶
func (s *Subscription) Channel() string
Channel returns subscription channel.
func (*Subscription) History ¶
func (s *Subscription) History() ([]Publication, error)
History allows to extract channel history.
func (*Subscription) OnJoin ¶ added in v0.2.0
func (s *Subscription) OnJoin(handler JoinHandler)
OnJoin allows to set JoinHandler to SubEventHandler.
func (*Subscription) OnLeave ¶ added in v0.2.0
func (s *Subscription) OnLeave(handler LeaveHandler)
OnLeave allows to set LeaveHandler to SubEventHandler.
func (*Subscription) OnPublish ¶ added in v0.2.0
func (s *Subscription) OnPublish(handler PublishHandler)
OnPublish allows to set PublishHandler to SubEventHandler.
func (*Subscription) OnSubscribeError ¶ added in v0.2.0
func (s *Subscription) OnSubscribeError(handler SubscribeErrorHandler)
OnSubscribeError allows to set SubscribeErrorHandler to SubEventHandler.
func (*Subscription) OnSubscribeSuccess ¶ added in v0.2.0
func (s *Subscription) OnSubscribeSuccess(handler SubscribeSuccessHandler)
OnSubscribeSuccess allows to set SubscribeSuccessHandler to SubEventHandler.
func (*Subscription) OnUnsubscribe ¶ added in v0.2.0
func (s *Subscription) OnUnsubscribe(handler UnsubscribeHandler)
OnUnsubscribe allows to set UnsubscribeHandler to SubEventHandler.
func (*Subscription) Presence ¶
func (s *Subscription) Presence() (map[string]ClientInfo, error)
Presence allows to extract channel history.
func (*Subscription) PresenceStats ¶
func (s *Subscription) PresenceStats() (PresenceStats, error)
PresenceStats allows to extract channel presence stats.
func (*Subscription) Publish ¶
func (s *Subscription) Publish(data []byte) error
Publish allows to publish data to channel.
func (*Subscription) Status ¶
func (s *Subscription) Status() int
Status returns current Subscription status.
func (*Subscription) Subscribe ¶
func (s *Subscription) Subscribe() error
Subscribe allows to subscribe again after unsubscribing.
func (*Subscription) Unsubscribe ¶
func (s *Subscription) Unsubscribe() error
Unsubscribe allows to unsubscribe from channel.
type SubscriptionEventHub ¶
type SubscriptionEventHub struct {
// contains filtered or unexported fields
}
SubscriptionEventHub contains callback functions that will be called when corresponding event happens with subscription to channel.
type UnsubscribeEvent ¶
type UnsubscribeEvent struct{}
UnsubscribeEvent is an event passed to unsubscribe event handler.
type UnsubscribeHandler ¶
type UnsubscribeHandler interface {
OnUnsubscribe(*Subscription, UnsubscribeEvent)
}
UnsubscribeHandler is a function to handle unsubscribe event.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Simple Go chat client for https://github.com/centrifugal/centrifuge/tree/master/examples/events example.
|
Simple Go chat client for https://github.com/centrifugal/centrifuge/tree/master/examples/events example. |
benchmark
This code is an adapted version of Nats benchmarking suite from https://github.com/nats-io/go-nats/blob/master/examples/nats-bench.go for Centrifuge.
|
This code is an adapted version of Nats benchmarking suite from https://github.com/nats-io/go-nats/blob/master/examples/nats-bench.go for Centrifuge. |
jwt
Private channel subscription example.
|
Private channel subscription example. |
internal
|
|
proto
Package proto is a generated protocol buffer package.
|
Package proto is a generated protocol buffer package. |