client

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultWebsocketPongTimeout 60 * time.Second
	DefaultWebsocketPongTimeout = 60 * time.Second
	// DefaultWebsocketPingPeriod (DefaultPongTimeout * 9) / 10
	DefaultWebsocketPingPeriod = (DefaultWebsocketPongTimeout * 9) / 10
	// DefaultWebsocketMaxMessageSize 10240000
	DefaultWebsocketMaxMessageSize = 10240000
	// DefaultWebsocketReadBufferSize 4096
	DefaultWebsocketReadBufferSize = 4096
	// DefaultWebsocketWriterBufferSize 4096
	DefaultWebsocketWriterBufferSize = 4096
	// DefaultEvtMessageKey is the default prefix of the underline websocket topics
	// that are being established under the hoods.
	//
	// Defaults to ":".
	// Last character of the prefix should be ':'.
	DefaultEvtMessageKey = "ws"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// URL is the target
	Host string

	// ID used to create the client id
	ID string
	// EvtMessagePrefix prefix of the every message
	EvtMessagePrefix []byte
	// WriteTimeout time allowed to write a message to the connection.
	// 0 means no timeout.
	// Default value is 0
	// ReadTimeout time allowed to read a message from the connection.
	// 0 means no timeout.
	// Default value is 0
	// PingPeriod send ping messages to the connection within this period. Must be less than PongTimeout.
	// Default value is 60 *time.Second
	PingPeriod time.Duration
	// MaxMessageSize max message size allowed from connection.
	// Default value is 1024
	MaxMessageSize int64
	// BinaryMessages set it to true in order to denotes binary data messages instead of utf-8 text
	// compatible if you wanna use the Connection's EmitMessage to send a custom binary data to the client, like a native server-client communication.
	// Default value is false
	BinaryMessages bool
	// ReadBufferSize is the buffer size for the connection reader.
	// Default value is 4096
	ReadBufferSize int
	// WriteBufferSize is the buffer size for the connection writer.
	// Default value is 4096
	WriteBufferSize int
}

func (*Config) Validate

func (c *Config) Validate()

Validate validates the configuration

type ConnectFunc

type ConnectFunc func()

type Connection

type Connection interface {
	ID() string
	OnDisconnect(DisconnectFunc)
	OnConnect(ConnectFunc)
	OnError(ErrorFunc)
	Subscribe(string, message.Func)
	Publisher(string) func(interface{}) error
	Pub(string, interface{}) error
	Echo(string, interface{}) error
	Wait() error
	Close() error
}

func New

func New(conf *Config) Connection

New create a new websocket client

type DisconnectFunc

type DisconnectFunc func()

DisconnectFunc is the callback which is fired when the ws client closed.

type ErrorFunc

type ErrorFunc func(error)

ErrorFunc is the callback which fires whenever an error occurs

Jump to

Keyboard shortcuts

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