centrifuge

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 2 Imported by: 0

README

This repo allows to generate Centrifuge/Centrifugo client libraries for iOS and Android app development using gomobile tool.

Gomobile is experimental project with all the ensuing circumstances.

You can download libraries for iOS and Android from releases page. See examples to dive into.

Note that on iOS this library does not include bitcode (it's still optional on iOS but can become required at any moment).

See how to import generated library on iOS and on Android – in two words you need to import centrifuge.aar (Android) or Centrifuge.framework (iOS).

API documentation on Godoc – this can be useful as iOS and Android code generated from Go code so you can rely on that docs when hacking with library.

For contributors

To build mobile libraries from Go source code using gomobile:

go get -u golang.org/x/mobile/cmd/gomobile
gomobile init
gomobile bind -target=ios github.com/centrifugal/centrifuge-mobile
gomobile bind -target=android github.com/centrifugal/centrifuge-mobile

Release

go get -u golang.org/x/mobile/cmd/gomobile
gomobile init
export ANDROID_NDK_HOME=/path/to/android-ndk-rXX
make release

Documentation

Index

Constants

View Source
const (
	DefaultReadTimeoutMilliseconds  = 5000
	DefaultWriteTimeoutMilliseconds = 5000
	DefaultPingIntervalMilliseconds = 25000
	DefaultPrivateChannelPrefix     = "$"
)

Config defaults.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client to connect to Centrifuge-based server or Centrifugo.

func New

func New(u string, config *Config) *Client

New initializes Client.

func (*Client) Close

func (c *Client) Close() error

Close closes Client connection and cleans ups everything.

func (*Client) Connect

func (c *Client) Connect() error

Connect dials to server and sends connect message.

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect client from server.

func (*Client) NamedRPC added in v0.5.2

func (c *Client) NamedRPC(method string, data []byte) (*RPCResult, error)

NamedRPC allows to make RPC with method.

func (*Client) NewSubscription added in v0.2.0

func (c *Client) NewSubscription(channel string) (*Subscription, error)

NewSubscription allows to create new Subscription to 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) OnServerJoin added in v0.6.0

func (c *Client) OnServerJoin(handler ServerJoinHandler)

OnServerJoin ...

func (*Client) OnServerLeave added in v0.6.0

func (c *Client) OnServerLeave(handler ServerLeaveHandler)

OnServerLeave ...

func (*Client) OnServerPublish added in v0.6.0

func (c *Client) OnServerPublish(handler ServerPublishHandler)

OnServerPublish ...

func (*Client) OnServerSubscribe added in v0.6.0

func (c *Client) OnServerSubscribe(handler ServerSubscribeHandler)

OnServerSubscribe ...

func (*Client) OnServerUnsubscribe added in v0.6.0

func (c *Client) OnServerUnsubscribe(handler ServerUnsubscribeHandler)

OnServerUnsubscribe ...

func (*Client) Publish added in v0.1.0

func (c *Client) Publish(channel string, data []byte) (*PublishResult, error)

Publish data into channel.

func (*Client) RPC added in v0.1.0

func (c *Client) RPC(data []byte) (*RPCResult, error)

RPC allows to make RPC – send data to server ant wait for response. RPC handler must be registered on server.

func (*Client) Send added in v0.1.0

func (c *Client) Send(data []byte) error

Send data to server asynchronously.

func (*Client) SetConnectData added in v0.1.0

func (c *Client) SetConnectData(data []byte)

SetConnectData allows to set data to send in connect message.

func (*Client) SetHeader added in v0.1.0

func (c *Client) SetHeader(key, value string)

SetHeader allows to set custom header sent in Upgrade HTTP request.

func (*Client) SetName added in v0.6.0

func (c *Client) SetName(name string)

SetName allows to set client name.

func (*Client) SetToken added in v0.1.0

func (c *Client) SetToken(token string)

SetToken allows to set connection token so client authenticate itself on connect.

func (*Client) SetVersion added in v0.6.0

func (c *Client) SetVersion(version string)

SetVersion allows to set client version.

type ClientInfo

type ClientInfo struct {
	Client   string
	User     string
	ConnInfo []byte
	ChanInfo []byte
}

ClientInfo ...

type Config

type Config struct {
	ReadTimeoutMilliseconds  int
	WriteTimeoutMilliseconds int
	PingIntervalMilliseconds int
	PrivateChannelPrefix     string
}

Config contains various client options.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns Config with default options.

type ConnectEvent added in v0.1.0

type ConnectEvent struct {
	ClientID string
	Version  string
	Data     []byte
}

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 added in v0.1.0

type DisconnectEvent struct {
	Reason    string
	Reconnect bool
}

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 added in v0.1.0

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 HistoryData added in v0.1.0

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

HistoryData ...

func (*HistoryData) ItemAt added in v0.1.0

func (d *HistoryData) ItemAt(i int) *Publication

ItemAt to get Publication by index.

func (*HistoryData) NumItems added in v0.1.0

func (d *HistoryData) NumItems() int

NumItems to get total number of Publication items in collection.

type JoinEvent added in v0.1.0

type JoinEvent struct {
	Client   string
	User     string
	ConnInfo []byte
	ChanInfo []byte
}

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 added in v0.1.0

type LeaveEvent struct {
	Client   string
	User     string
	ConnInfo []byte
	ChanInfo []byte
}

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 added in v0.1.0

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 PresenceData added in v0.1.0

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

PresenceData contains presence information for channel.

func (*PresenceData) ItemAt added in v0.1.0

func (d *PresenceData) ItemAt(i int) *ClientInfo

ItemAt to get ClientInfo by index.

func (*PresenceData) NumItems added in v0.1.0

func (d *PresenceData) NumItems() int

NumItems to get total number of ClientInfo items in collection.

type PresenceStats added in v0.1.0

type PresenceStats struct {
	NumClients int
	NumUsers   int
}

PresenceStats ...

type PrivateSign

type PrivateSign struct {
	Token string
}

PrivateSign confirms that client can subscribe on private channel.

type PrivateSubEvent added in v0.1.0

type PrivateSubEvent struct {
	ClientID string
	Channel  string
}

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 added in v0.1.0

type Publication struct {
	Offset int64
	Data   []byte
	Info   *ClientInfo
}

Publication ...

type PublishEvent added in v0.1.0

type PublishEvent struct {
	Offset int64
	Data   []byte
	Info   *ClientInfo
}

PublishEvent has info about received channel Publication.

type PublishHandler added in v0.1.0

type PublishHandler interface {
	OnPublish(*Subscription, *PublishEvent)
}

PublishHandler is a function to handle messages published in channels.

type PublishResult added in v0.6.0

type PublishResult struct{}

type RPCResult added in v0.6.0

type RPCResult struct {
	Data []byte
}

type RefreshHandler

type RefreshHandler interface {
	OnRefresh(*Client) (string, error)
}

RefreshHandler is an interface describing how to handle credentials refresh event.

type ServerJoinEvent added in v0.6.0

type ServerJoinEvent struct {
	Channel  string
	Client   string
	User     string
	ConnInfo []byte
	ChanInfo []byte
}

ServerJoinEvent has info about user who left channel.

type ServerJoinHandler added in v0.6.0

type ServerJoinHandler interface {
	OnServerJoin(*Client, *ServerJoinEvent)
}

ServerJoinHandler ...

type ServerLeaveEvent added in v0.6.0

type ServerLeaveEvent struct {
	Channel  string
	Client   string
	User     string
	ConnInfo []byte
	ChanInfo []byte
}

ServerLeaveEvent has info about user who joined channel.

type ServerLeaveHandler added in v0.6.0

type ServerLeaveHandler interface {
	OnServerLeave(*Client, *ServerLeaveEvent)
}

ServerLeaveHandler ...

type ServerPublishEvent added in v0.6.0

type ServerPublishEvent struct {
	Channel string
	Offset  int64
	Data    []byte
	Info    *ClientInfo
}

ServerPublishEvent has info about received channel Publication.

type ServerPublishHandler added in v0.6.0

type ServerPublishHandler interface {
	OnServerPublish(*Client, *ServerPublishEvent)
}

ServerPublishHandler ...

type ServerSubscribeEvent added in v0.6.0

type ServerSubscribeEvent struct {
	Channel      string
	Resubscribed bool
	Recovered    bool
}

type ServerSubscribeHandler added in v0.6.0

type ServerSubscribeHandler interface {
	OnServerSubscribe(*Client, *ServerSubscribeEvent)
}

ServerSubscribeHandler ...

type ServerUnsubscribeEvent added in v0.6.0

type ServerUnsubscribeEvent struct {
	Channel string
}

ServerUnsubscribeEvent is an event passed to unsubscribe event handler.

type ServerUnsubscribeHandler added in v0.6.0

type ServerUnsubscribeHandler interface {
	OnServerUnsubscribe(*Client, *ServerUnsubscribeEvent)
}

ServerUnsubscribeHandler ...

type SubscribeErrorEvent added in v0.1.0

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 added in v0.1.0

type SubscribeSuccessEvent struct {
	Resubscribed bool
	Recovered    bool
}

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 added in v0.1.0

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

Subscription describes client subscription to channel.

func (*Subscription) Channel added in v0.1.0

func (s *Subscription) Channel() string

Channel returns subscription channel.

func (*Subscription) History added in v0.1.0

func (s *Subscription) History() (*HistoryData, 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 added in v0.1.0

func (s *Subscription) Presence() (*PresenceData, error)

Presence allows to extract presence information for channel.

func (*Subscription) PresenceStats added in v0.1.0

func (s *Subscription) PresenceStats() (*PresenceStats, error)

PresenceStats allows to extract presence stats information for channel.

func (*Subscription) Publish added in v0.1.0

func (s *Subscription) Publish(data []byte) (*PublishResult, error)

Publish allows to publish JSON encoded data to subscription channel.

func (*Subscription) Subscribe added in v0.1.0

func (s *Subscription) Subscribe() error

Subscribe allows to subscribe again after unsubscribing.

func (*Subscription) Unsubscribe added in v0.1.0

func (s *Subscription) Unsubscribe() error

Unsubscribe allows to unsubscribe from channel.

type UnsubscribeEvent added in v0.1.0

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.

Directories

Path Synopsis
examples
go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL