client

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 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 = message.FuncBlank

type Connection

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

func New

func New(conf *Config) Connection

New create a new websocket client

type DisconnectFunc

type DisconnectFunc = message.FuncBlank

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

type ErrorFunc

type ErrorFunc = message.FuncError

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