websocket

package
v0.0.0-...-4601921 Latest Latest
Warning

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

Go to latest
Published: May 13, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IN_CHANNEL_SIZE  = 100
	OUT_CHANNEL_SIZE = 10
)
View Source
const (
	MAX_RECONNECT_WAIT = time.Second * 30
)

Variables

View Source
var (
	ErrReconnect      = NewError("Reconnect (no delay)", false, true, 0)
	ErrDelayReconnect = NewError("Reconnect (with delay)", false, true, time.Second)
	ErrClosed         = NewError("Closed", false, false, 0)
)
View Source
var DefaultConfig = Config{
	ConnectTimeout:  time.Second * 30,
	ActivityTimeout: time.Second * 120,
	PingTimeout:     time.Second * 30,
}

Functions

This section is empty.

Types

type Channel

type Channel interface {
	Handler

	UpdateClientState(connected bool)

	SetActive(active bool)

	Subscribe()
	Unsubscribe()

	Bind(event string, h Handler)
	Unbind(event string, h Handler)

	BindAll(h Handler)
	UnbindAll(h Handler)

	BindFunc(event string, h func(Event))
	UnbindFunc(event string, h func(Event))

	BindAllFunc(h func(Event))
	UnbindAllFunc(h func(Event))
}

type ChannelClient

type ChannelClient interface {
	Client

	SendEvent(event Event)

	SendSubscribe(channel string)
	SendUnsubscribe(channel string)

	Subscribe(channel string) Channel
	Unsubscribe(channel string)
}

type Channels

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

func NewChannels

func NewChannels(client ChannelClient) *Channels

func (*Channels) Add

func (c *Channels) Add(channel string, ch Channel)

func (*Channels) Bind

func (c *Channels) Bind(event string, h Handler)

func (*Channels) ConnectedState

func (c *Channels) ConnectedState(connected bool)

func (*Channels) Find

func (c *Channels) Find(channel string) Channel

func (*Channels) HandleEvent

func (c *Channels) HandleEvent(event Event)

func (*Channels) Remove

func (c *Channels) Remove(channel string)

func (*Channels) SubscriptionSucceded

func (c *Channels) SubscriptionSucceded(channel string, succeded bool)

func (*Channels) Unbind

func (c *Channels) Unbind(event string, h Handler)

type Client

type Client interface {
	// return true to reconnect
	HandleDisconnect() bool
	HandleConnected()

	HandleMessage([]byte) error

	SendMessage([]byte)

	SendPing()

	Close()
}

func NewClient

func NewClient(url string) (Client, error)

type Config

type Config struct {
	ConnectTimeout  time.Duration
	ActivityTimeout time.Duration
	PingTimeout     time.Duration
}

func (Config) NewClient

func (cf Config) NewClient(websocketUrl string) (Client, error)

type DelayError

type DelayError interface {
	net.Error
	Delay() time.Duration // Delay reconnect?
}

type Error

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

func NewError

func NewError(reason string, timeout bool, temp bool, delay time.Duration) *Error

func (*Error) Delay

func (e *Error) Delay() time.Duration

func (*Error) Error

func (e *Error) Error() string

func (*Error) Temporary

func (e *Error) Temporary() bool

func (*Error) Tiemout

func (e *Error) Tiemout() bool

type Event

type Event interface {
	GetEvent() string
	SetEvent(string)
	GetChannel() string
	SetChannel(string)

	GetData() interface{}
	SetData(interface{})
	GetDataString() string
	SetDataString(string)
}

type Handler

type Handler interface {
	HandleEvent(Event)
}

type HandlerFunc

type HandlerFunc func(Event)

func (HandlerFunc) HandleEvent

func (f HandlerFunc) HandleEvent(e Event)

type PlainClient

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

func (*PlainClient) Close

func (c *PlainClient) Close()

func (*PlainClient) HandleConnected

func (c *PlainClient) HandleConnected()

func (*PlainClient) HandleDisconnect

func (c *PlainClient) HandleDisconnect() bool

func (*PlainClient) HandleMessage

func (c *PlainClient) HandleMessage(msg []byte) error

func (*PlainClient) SendMessage

func (c *PlainClient) SendMessage(msg []byte)

func (*PlainClient) SendPing

func (c *PlainClient) SendPing()

type PublicChannel

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

func NewPublicChannel

func NewPublicChannel(channel string, client ChannelClient) *PublicChannel

func (*PublicChannel) Bind

func (c *PublicChannel) Bind(event string, h Handler)

func (*PublicChannel) BindAll

func (c *PublicChannel) BindAll(h Handler)

func (*PublicChannel) BindAllFunc

func (c *PublicChannel) BindAllFunc(h func(Event))

func (*PublicChannel) BindFunc

func (c *PublicChannel) BindFunc(event string, h func(Event))

func (*PublicChannel) HandleEvent

func (c *PublicChannel) HandleEvent(event Event)

func (*PublicChannel) SetActive

func (c *PublicChannel) SetActive(active bool)

func (*PublicChannel) Subscribe

func (c *PublicChannel) Subscribe()

func (*PublicChannel) Unbind

func (c *PublicChannel) Unbind(event string, h Handler)

func (*PublicChannel) UnbindAll

func (c *PublicChannel) UnbindAll(h Handler)

func (*PublicChannel) UnbindAllFunc

func (c *PublicChannel) UnbindAllFunc(h func(Event))

func (*PublicChannel) UnbindFunc

func (c *PublicChannel) UnbindFunc(event string, h func(Event))

func (*PublicChannel) Unsubscribe

func (c *PublicChannel) Unsubscribe()

func (*PublicChannel) UpdateClientState

func (c *PublicChannel) UpdateClientState(connected bool)

type Socket

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

func NewSocket

func NewSocket(u *url.URL, cf Config, client Client) *Socket

func (*Socket) Close

func (s *Socket) Close()

Close Websocket and don't reconnect.

func (*Socket) HandleConnected

func (s *Socket) HandleConnected()

func (*Socket) HandlePong

func (s *Socket) HandlePong()

func (*Socket) SendMessage

func (s *Socket) SendMessage(msg []byte)

func (*Socket) SetActivityTimeout

func (s *Socket) SetActivityTimeout(activityTimeout time.Duration)

func (*Socket) SetTimeout

func (s *Socket) SetTimeout(reason TimeoutReason, d time.Duration)

type TimeoutReason

type TimeoutReason int
const (
	NoTimeout TimeoutReason = iota
	ConnectTimeout
	ActivityTimeout
	PingTimeout
)

type TimeoutTimer

type TimeoutTimer struct {
	C      <-chan time.Time
	Reason TimeoutReason
	// contains filtered or unexported fields
}

func (*TimeoutTimer) Expired

func (t *TimeoutTimer) Expired() bool

func (*TimeoutTimer) Reset

func (t *TimeoutTimer) Reset()

func (*TimeoutTimer) SetTimeout

func (t *TimeoutTimer) SetTimeout(reason TimeoutReason, d time.Duration)

func (*TimeoutTimer) Stop

func (t *TimeoutTimer) Stop()

Jump to

Keyboard shortcuts

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