# README
Websocket client for Centrifuge library and Centrifugo server.
There is no v1 release of this library yet – API still evolves. At the moment patch version updates only contain backwards compatible changes, minor version updates can have backwards incompatible API changes.
Feature matrix
- connect to server using JSON protocol format
- connect to server using Protobuf protocol format
- connect with token (JWT)
- connect with custom header
- automatic reconnect in case of errors, network problems etc
- an exponential backoff for reconnect
- connect and disconnect events
- handle disconnect reason
- subscribe on a channel and handle asynchronous Publications
- handle Join and Leave messages
- handle Unsubscribe notifications
- reconnect on subscribe timeout
- publish method of Subscription
- unsubscribe method of Subscription
- presence method of Subscription
- presence stats method of Subscription
- history method of Subscription
- top-level publish method
- top-level presence method
- top-level presence stats method
- top-level history method
- top-level unsubscribe method
- send asynchronous messages to server
- handle asynchronous messages from server
- send RPC commands
- publish to channel without being subscribed
- subscribe to private channels with token (JWT)
- connection token (JWT) refresh
- private channel subscription token (JWT) refresh
- handle connection expired error
- handle subscription expired error
- ping/pong to find broken connection
- message recovery mechanism for client-side subscriptions
- server-side subscriptions
- message recovery mechanism for server-side subscriptions
- history stream pagination
Run tests
First run Centrifugo instance:
docker run -d -p 8000:8000 centrifugo/centrifugo:latest centrifugo --client_insecure
Then run go test
# Constants
Describe client connection statuses.
Describe client connection statuses.
Describe client connection statuses.
Config defaults.
Config defaults.
Config defaults.
Config defaults.
Config defaults.
Config defaults.
Describe client connection statuses.
Different states of Subscription.
Different states of Subscription.
Different states of Subscription.
Different states of Subscription.
Different states of Subscription.
# Variables
ErrClientClosed can be returned if client already closed.
ErrClientDisconnected can be returned if client goes to disconnected state while operation in progress.
ErrDuplicateSubscription returned if subscription to the same channel already registered in current client instance.
ErrReconnectFailed returned when reconnect to server failed (never happen by default since client keeps reconnecting forever).
ErrSubscribeClosed returned if Subscription was closed.
ErrTimeout returned if operation timed out.
# Structs
Client represents client connection to Centrifugo or Centrifuge library based server.
ClientInfo contains information about client connection.
Config contains various client options.
ConnectEvent is a connect event context passed to OnConnect callback.
DisconnectEvent is a disconnect event context passed to OnDisconnect callback.
Error represents protocol-level error.
ErrorEvent is an error event context passed to OnError callback.
HistoryResult contains the result of history op.
JoinEvent has info about user who joined channel.
LeaveEvent has info about user who left channel.
MessageEvent is an event for async message from server to client.
HistoryResult contains the result of presence op.
PresenceStats represents short presence information.
PresenceStatsResult wraps presence stats.
PrivateSubEvent contains info required to create PrivateSign when client wants to subscribe on private channel.
Publication is a data sent to channel.
PublishEvent has info about received channel Publication.
PublishResult contains the result of publish.
RPCResult contains data returned from server as RPC result.
ServerJoinEvent has info about user who left channel.
ServerLeaveEvent has info about user who joined channel.
ServerPublishEvent has info about received channel Publication.
No description provided by the author
ServerUnsubscribeEvent is an event passed to unsubscribe event handler.
SubscribeErrorEvent is a subscribe error event context passed to event callback.
SubscribeSuccessEvent is a subscribe success event context passed to event callback.
Subscription represents client subscription to channel.
UnsubscribeEvent is an event passed to unsubscribe event handler.
No description provided by the author
# Interfaces
ConnectHandler is an interface describing how to handle connect event.
DisconnectHandler is an interface describing how to handle disconnect event.
ErrorHandler is an interface describing how to handle error event.
JoinHandler is a function to handle join messages.
LeaveHandler is a function to handle leave messages.
MessageHandler is an interface describing how to handle async message from server.
PrivateSubHandler is an interface describing how to handle private subscription request.
PublishHandler is a function to handle messages published in channels.
RefreshHandler is an interface describing how to handle token refresh event.
ServerJoinHandler is an interface describing how to handle Join events from server-side subscriptions.
ServerLeaveHandler is an interface describing how to handle Leave events from server-side subscriptions.
ServerPublishHandler is an interface describing how to handle Publication from server-side subscriptions.
ServerSubscribeHandler is an interface describing how to handle subscribe events from server-side subscriptions.
ServerUnsubscribeHandler is an interface describing how to handle unsubscribe events from server-side subscriptions.
SubscribeErrorHandler is a function to handle subscribe error event.
SubscribeSuccessHandler is a function to handle subscribe success event.
UnsubscribeHandler is a function to handle unsubscribe event.