engine

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ParserProtocol int = 3

ParserProtocol is the version of the Engine.IO parser protocol that this library implements

Variables

View Source
var ErrDisconnected = errors.New("Transport disconnected")

ErrDisconnected is returned when the transport is closed

View Source
var ErrInvalidType = errors.New("Invalid packet type")

ErrInvalidType is returned when a packet contains an invalid type

View Source
var ErrPacketTooShort = errors.New("Packet is too short")

ErrPacketTooShort is returned when a packet does not contain enough bytes to be parsed

Functions

func CreateOpenPingPongHandler

func CreateOpenPingPongHandler() http.HandlerFunc

func CreateTestSocketIOHandler

func CreateTestSocketIOHandler(handler func(c *websocket.Conn)) http.HandlerFunc

func CreateTestSocketIOServer

func CreateTestSocketIOServer(mux *http.ServeMux) (*httptest.Server, string)

func QuickEncode

func QuickEncode(p Packet) []byte

Types

type BinaryPacket

type BinaryPacket struct {
	Type PacketType
	Data []byte
}

BinaryPacket represents a engine.io packet with binary (byte) contents

func (*BinaryPacket) Encode

func (p *BinaryPacket) Encode(binary bool) ([]byte, error)

Encode returns the encoded engine.io packet

func (*BinaryPacket) GetData

func (p *BinaryPacket) GetData() []byte

GetData returns the data contained in the packet

func (*BinaryPacket) GetType

func (p *BinaryPacket) GetType() PacketType

GetType returns the engine.io packet type of the packet

type Conn

type Conn interface {
	ID() string
	SupportsBinary() bool
	Read() <-chan Packet
	Write() chan<- Packet
	Opened() <-chan OpenData
	Connected() bool
	Close() error
	KeepAliveContext(context.Context)
}

type ConnConfig

type ConnConfig struct {
	ConnectTimeout        time.Duration
	OutgoingChannelLength int32
}

type KeepAliveConn

type KeepAliveConn struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

KeepAliveConn wraps a Conn and handles the Ping/Pong process

func NewKeepAliveConn

func NewKeepAliveConn(conn PacketConn, readBufferSize int, outgoing chan Packet) *KeepAliveConn

NewKeepAliveConn returns a new instance of KeepAliveConn

func (*KeepAliveConn) Close

func (k *KeepAliveConn) Close() error

Close stops the Ping/Pong process and closes the wrapped Conn

func (*KeepAliveConn) Connected added in v0.9.5

func (k *KeepAliveConn) Connected() bool

func (*KeepAliveConn) ID

func (k *KeepAliveConn) ID() string

ID returns the ID of the wrapped Conn

func (*KeepAliveConn) KeepAliveContext

func (k *KeepAliveConn) KeepAliveContext(ctx context.Context)

KeepAliveContext starts the Ping/Pong process

func (*KeepAliveConn) Opened

func (k *KeepAliveConn) Opened() <-chan OpenData

func (*KeepAliveConn) Read

func (k *KeepAliveConn) Read() <-chan Packet

func (*KeepAliveConn) SupportsBinary

func (k *KeepAliveConn) SupportsBinary() bool

SupportsBinary returns whether the wrapped Conn supports binary

func (*KeepAliveConn) Write

func (k *KeepAliveConn) Write() chan<- Packet

type OpenData

type OpenData struct {
	SID          string `json:"sid"`
	PingInterval int64
	PingTimeout  int64
}

type Packet

type Packet interface {
	GetType() PacketType
	Encode(bool) ([]byte, error)
	GetData() []byte
}

Packet represents a generic engine.io packet

func DecodeBinaryPacket

func DecodeBinaryPacket(packet []byte) (Packet, error)

DecodeBinaryPacket returns a BinaryPacket from the contents of the byte array

func DecodeStringPacket

func DecodeStringPacket(packet string) (Packet, error)

DecodeStringPacket returns a StringPacket or BinaryPacket from the contents of the string

type PacketConn

type PacketConn interface {
	ID() string
	SupportsBinary() bool
	Read() (Packet, error)
	Write(Packet) error
	Close() error
	Connected() bool
}

type PacketType

type PacketType uint8

PacketType is the type of engine.io the packet being encoded or decoded

const (
	// Open is a packet that is sent when a connection is first opened
	Open PacketType = iota
	// Close is a packet that is sent when a connection is closed
	Close
	// Ping is a packet that is sent to indicated that the connection is still active
	Ping
	// Pong is a packet that is sent to indicate that the remote ping was received
	Pong
	// Message is a packet that is sent to transfer data
	Message
	// Upgrade is a packet that is sent to indicate that an upgrade should occur
	Upgrade
	// NoOp is a packet that is sent that should cause no action when received
	NoOp
)

type RawConn

type RawConn struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RawConn is a connection to an Engine.IO connection

func DialContext

func DialContext(ctx context.Context, address string) (*RawConn, error)

DialContext creates a RawConn to the Engine.IO server located at address

func (*RawConn) Close

func (conn *RawConn) Close() error

Close closes the underlying transport

func (*RawConn) Connected added in v0.9.5

func (conn *RawConn) Connected() bool

func (*RawConn) ID

func (conn *RawConn) ID() string

ID returns the remote ID assigned to this connection

func (*RawConn) Read

func (conn *RawConn) Read() (Packet, error)

func (*RawConn) SupportsBinary

func (conn *RawConn) SupportsBinary() bool

SupportsBinary returns true if the underlying connection supports sending raw binary data (bytes), false otherwise

func (*RawConn) Write

func (conn *RawConn) Write(packet Packet) error

type StringPacket

type StringPacket struct {
	Type PacketType
	Data *string
}

StringPacket represents an engine.io packet with UTF-8 string contents

func (*StringPacket) Encode

func (p *StringPacket) Encode(binary bool) ([]byte, error)

Encode returns the encoded engine.io packet

func (*StringPacket) GetData

func (p *StringPacket) GetData() []byte

GetData returns the data contained in the packet

func (*StringPacket) GetType

func (p *StringPacket) GetType() PacketType

GetType returns the engine.io packet type of the packet

Jump to

Keyboard shortcuts

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