engine

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

package engine implements the [Engine.IO](https://socket.io/docs/v4/engine-io-protocol) protocol

Index

Constants

View Source
const Protocol = 4

Variables

View Source
var (
	ErrSocketConnected = errors.New("Engine.IO: socket was already connected")
	ErrPingTimeout     = errors.New("Engine.IO: did not receive PING packet for a long time")
)
View Source
var DefaultOption = Options{
	Secure: true,
	Path:   "/engine.io/",
}
View Source
var WebsocketDialer *websocket.Dialer = &websocket.Dialer{
	Proxy:            http.ProxyFromEnvironment,
	HandshakeTimeout: 30 * time.Second,
}

Functions

This section is empty.

Types

type Options

type Options struct {
	Secure       bool
	Host         string // [<scheme>://]<host>:<port>
	Path         string
	ExtraQuery   url.Values
	ExtraHeaders http.Header
	DialTimeout  time.Duration
}

type Packet

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

func (*Packet) Body

func (p *Packet) Body() []byte

func (*Packet) MarshalBinary

func (p *Packet) MarshalBinary() (data []byte, err error)

func (*Packet) SetBody

func (p *Packet) SetBody(body []byte)

func (*Packet) String

func (p *Packet) String() string

func (*Packet) Type

func (p *Packet) Type() PacketType

func (*Packet) UnmarshalBinary

func (p *Packet) UnmarshalBinary(data []byte) error

func (*Packet) UnmarshalBody

func (p *Packet) UnmarshalBody(ptr any) error

type PacketType

type PacketType int8
const (
	OPEN PacketType = iota
	CLOSE
	PING
	PONG
	MESSAGE
	UPGRADE
	NOOP

	BINARY PacketType = 'b'
)

func (PacketType) ID

func (t PacketType) ID() byte

func (PacketType) String

func (t PacketType) String() string

type Socket

type Socket struct {
	Dialer *websocket.Dialer
	// contains filtered or unexported fields
}

func NewSocket

func NewSocket(opts Options) (s *Socket, err error)

func (*Socket) Close

func (s *Socket) Close() error

func (*Socket) Conn

func (s *Socket) Conn() *websocket.Conn

func (*Socket) Connected

func (s *Socket) Connected() bool

func (*Socket) Context

func (s *Socket) Context() context.Context

func (*Socket) Dial

func (s *Socket) Dial(ctx context.Context) (err error)

func (*Socket) Emit

func (s *Socket) Emit(body []byte)

func (*Socket) ID

func (s *Socket) ID() string

func (*Socket) OnBinary

func (s *Socket) OnBinary(cb func(s *Socket, data []byte))

func (*Socket) OnConnect

func (s *Socket) OnConnect(cb func(s *Socket))

func (*Socket) OnDialError added in v0.1.2

func (s *Socket) OnDialError(cb func(s *Socket, err error))

func (*Socket) OnDisconnect

func (s *Socket) OnDisconnect(cb func(s *Socket, err error))

func (*Socket) OnMessage

func (s *Socket) OnMessage(cb func(s *Socket, data []byte))

func (*Socket) OnPong

func (s *Socket) OnPong(cb func(s *Socket, data []byte))

func (*Socket) OnReconnect added in v0.1.2

func (s *Socket) OnReconnect(cb func(s *Socket))

func (*Socket) OnRecv

func (s *Socket) OnRecv(cb func(s *Socket, data []byte))

func (*Socket) OnSend

func (s *Socket) OnSend(cb func(s *Socket, data []byte))

func (*Socket) OnceBinary

func (s *Socket) OnceBinary(cb func(s *Socket, data []byte))

func (*Socket) OnceConnect

func (s *Socket) OnceConnect(cb func(s *Socket))

func (*Socket) OnceDisconnect

func (s *Socket) OnceDisconnect(cb func(s *Socket, err error))

func (*Socket) OnceMessage

func (s *Socket) OnceMessage(cb func(s *Socket, data []byte))

func (*Socket) OncePong

func (s *Socket) OncePong(cb func(s *Socket, data []byte))

func (*Socket) Status

func (s *Socket) Status() SocketStatus

func (*Socket) URL

func (s *Socket) URL() *url.URL

type SocketStatus

type SocketStatus = int32
const (
	SocketClosed SocketStatus = iota
	SocketOpening
	SocketConnected
)

type UnexpectedPacketTypeError

type UnexpectedPacketTypeError struct {
	Type PacketType
}

func (*UnexpectedPacketTypeError) Error

func (e *UnexpectedPacketTypeError) Error() string

Jump to

Keyboard shortcuts

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