transport

package
v0.0.0-...-8d8ec6f Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlDefaultPingInterval   = 30 * time.Second
	PlDefaultPingTimeout    = 60 * time.Second
	PlDefaultReceiveTimeout = 60 * time.Second
	PlDefaultSendTimeout    = 60 * time.Second

	StopMessage     = "stop"
	UpgradedMessage = "upgrade"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	GetMessage() (message string, err error)
	WriteMessage(message string) error
	Close() error
	PingParams() (interval, timeout time.Duration)
}

Connection represents an end-point connection with transport

type PollingClientConnection

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

PollingClientConnection represents XHR polling client connection

func (*PollingClientConnection) Close

func (polling *PollingClientConnection) Close() error

Close the client connection gracefully

func (*PollingClientConnection) GetMessage

func (polling *PollingClientConnection) GetMessage() (string, error)

GetMessage performs a GET request to wait for the following message

func (*PollingClientConnection) PingParams

func (polling *PollingClientConnection) PingParams() (time.Duration, time.Duration)

PingParams returns PingInterval and PingTimeout params

func (*PollingClientConnection) WriteMessage

func (polling *PollingClientConnection) WriteMessage(m string) error

WriteMessage performs a POST request to send a message to server

type PollingClientTransport

type PollingClientTransport struct {
	PingInterval   time.Duration
	PingTimeout    time.Duration
	ReceiveTimeout time.Duration
	SendTimeout    time.Duration

	Headers http.Header
	// contains filtered or unexported fields
}

PollingClientTransport represents polling client transport parameters

func DefaultPollingClientTransport

func DefaultPollingClientTransport() *PollingClientTransport

DefaultPollingClientTransport returns client polling transport with default params

func (*PollingClientTransport) Connect

func (t *PollingClientTransport) Connect(url string) (Connection, error)

Connect to server, perform 3 HTTP requests in connecting sequence

func (*PollingClientTransport) HandleConnection

func (t *PollingClientTransport) HandleConnection(w http.ResponseWriter, r *http.Request) (Connection, error)

HandleConnection for the polling client is a placeholder

func (*PollingClientTransport) Serve

Serve for the polling client is a placeholder

func (*PollingClientTransport) SetSid

func (t *PollingClientTransport) SetSid(sid string, conn Connection)

SetSid for the polling client is a placeholder

type PollingConnection

type PollingConnection struct {
	Transport *PollingTransport
	// contains filtered or unexported fields
}

PollingConnection represents a XHR polling connection

func (*PollingConnection) Close

func (polling *PollingConnection) Close() error

Close the polling connection and delete session

func (*PollingConnection) GetMessage

func (polling *PollingConnection) GetMessage() (string, error)

GetMessage waits for incoming message from the connection

func (*PollingConnection) PingParams

func (polling *PollingConnection) PingParams() (time.Duration, time.Duration)

PingParams returns a connection ping params

func (*PollingConnection) PollingWriter

func (polling *PollingConnection) PollingWriter(w http.ResponseWriter, r *http.Request)

PollingWriter for writing polling answer

func (*PollingConnection) WriteMessage

func (polling *PollingConnection) WriteMessage(message string) error

WriteMessage to the connection

type PollingTransport

type PollingTransport struct {
	PingInterval   time.Duration
	PingTimeout    time.Duration
	ReceiveTimeout time.Duration
	SendTimeout    time.Duration

	Headers http.Header
	// contains filtered or unexported fields
}

PollingTransport represens the XHR polling transport params

func DefaultPollingTransport

func DefaultPollingTransport() *PollingTransport

DefaultPollingTransport returns PollingTransport with default params

func (*PollingTransport) Connect

func (t *PollingTransport) Connect(url string) (Connection, error)

Connect for the polling transport is a placeholder

func (*PollingTransport) HandleConnection

func (t *PollingTransport) HandleConnection(w http.ResponseWriter, r *http.Request) (Connection, error)

HandleConnection returns a pointer to a new Connection

func (*PollingTransport) Serve

Serve is for receiving messages from client, simple decoding also here

func (*PollingTransport) SetSid

func (t *PollingTransport) SetSid(sessionID string, connection Connection)

SetSid to the given sessionID and connection

type PollingTransportParams

type PollingTransportParams struct {
	Headers http.Header
}

PollingTransportParams represents XHR polling transport params

type Transport

type Transport interface {
	Connect(url string) (conn Connection, err error)
	HandleConnection(w http.ResponseWriter, r *http.Request) (conn Connection, err error)
	Serve(w http.ResponseWriter, r *http.Request)
	SetSid(sid string, conn Connection)
}

Transport represents a connection transport

type WebsocketConnection

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

WebsocketConnection represents websocket connection

func (*WebsocketConnection) Close

func (ws *WebsocketConnection) Close() error

Close the connection

func (*WebsocketConnection) GetMessage

func (ws *WebsocketConnection) GetMessage() (string, error)

GetMessage from the connection

func (*WebsocketConnection) PingParams

func (ws *WebsocketConnection) PingParams() (time.Duration, time.Duration)

PingParams returns ping params

func (*WebsocketConnection) WriteMessage

func (ws *WebsocketConnection) WriteMessage(m string) error

WriteMessage message m into a connection

type WebsocketTransport

type WebsocketTransport struct {
	PingInterval   time.Duration
	PingTimeout    time.Duration
	ReceiveTimeout time.Duration
	SendTimeout    time.Duration

	BufferSize      int
	Headers         http.Header
	TLSClientConfig *tls.Config
}

WebsocketTransport implements websocket transport

func DefaultWebsocketTransport

func DefaultWebsocketTransport() *WebsocketTransport

DefaultWebsocketTransport returns websocket connection with default params

func NewWebsocketTransport

func NewWebsocketTransport(params WebsocketTransportParams) *WebsocketTransport

NewWebsocketTransport returns websocket transport with given params

func (*WebsocketTransport) Connect

func (t *WebsocketTransport) Connect(url string) (Connection, error)

Connect to the given url

func (*WebsocketTransport) HandleConnection

func (t *WebsocketTransport) HandleConnection(w http.ResponseWriter, r *http.Request) (Connection, error)

HandleConnection

func (*WebsocketTransport) Serve

Serve does nothing here. Websocket connection does not require any additional processing

func (*WebsocketTransport) SetSid

func (t *WebsocketTransport) SetSid(string, Connection)

SetSid does nothing for the websocket transport, it's used only when transport changes (from)

type WebsocketTransportParams

type WebsocketTransportParams struct {
	Headers         http.Header
	TLSClientConfig *tls.Config
}

WebsocketTransportParams is a parameters for getting non-default websocket transport

Jump to

Keyboard shortcuts

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