Documentation ¶
Overview ¶
Package signalr provides the client side implementation of the WebSocket portion of the SignalR protocol. This was almost entirely written using https://blog.3d-logic.com/2015/03/29/signalr-on-the-wire-an-informal-description-of-the-signalr-protocol/ as a reference guide.
Index ¶
- type Client
- func (c *Client) Connect() (conn *websocket.Conn, err error)
- func (c *Client) Init() (err error)
- func (c *Client) Messages() <-chan Message
- func (c *Client) Negotiate() (err error)
- func (c *Client) Reconnect() (conn *websocket.Conn, err error)
- func (c *Client) Send(m hubs.ClientMsg) (err error)
- func (c *Client) Start(conn WebsocketConn) (err error)
- type JSONWriter
- type Message
- type MessageReader
- type Scheme
- type WebsocketConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // The host providing the SignalR service. Host string // The relative path where the SignalR service is provided. Endpoint string // The websockets protocol version. Protocol string ConnectionData string // The HTTPClient used to initialize the websocket connection. HTTPClient *http.Client // This field holds a struct that can read messages from and write JSON // objects to a websocket. In practice, this is simply a raw websocket // connection that results from a successful connection to the SignalR // server. Conn WebsocketConn // An optional setting to provide a non-default TLS configuration to use // when connecting to the websocket. TLSClientConfig *tls.Config // Either HTTPS or HTTP. Scheme Scheme // Set a maximum number of negotiate retries. MaxNegotiateRetries int // The time to wait before retrying, in the event that an error occurs // when contacting the SignalR service. RetryWaitDuration time.Duration ConnectionToken string ConnectionID string // Header values that should be applied to all HTTP requests. Headers map[string]string AccessToken string // contains filtered or unexported fields }
Client represents a SignlR client. It manages connections so that the caller doesn't have to.
func (*Client) Init ¶
Init connects to the host and performs the websocket initialization routines that are part of the SignalR specification.
func (*Client) Messages ¶
Messages returns the channel that receives persistent connection messages.
func (*Client) Negotiate ¶
Negotiate implements the negotiate step of the SignalR connection sequence.
func (*Client) Reconnect ¶
Reconnect implements the reconnect step of the SignalR connection sequence.
func (*Client) Start ¶
func (c *Client) Start(conn WebsocketConn) (err error)
Start implements the start step of the SignalR connection sequence.
type JSONWriter ¶
type JSONWriter interface {
WriteJSON(v interface{}) error
}
JSONWriter is the interface that wraps WriteJSON.
WriteJSON is defined at https://godoc.org/github.com/gorilla/websocket#Conn.WriteJSON
At a high level, it writes a structure to the underlying websocket and returns any error that was encountered during the write operation.
type Message ¶
type Message struct { // message id, present for all non-KeepAlive messages C string // an array containing actual data M []hubs.ClientMsg // indicates that the transport was initialized (a.k.a. init message) S int // groups token – an encrypted string representing group membership G string }
Message represents a message sent from the server to the persistent websocket connection.
type MessageReader ¶
MessageReader is the interface that wraps ReadMessage.
ReadMessage is defined at https://godoc.org/github.com/gorilla/websocket#Conn.ReadMessage
At a high level, it reads messages and returns:
- the type of message read
- the bytes that were read
- any errors encountered during reading the message
type Scheme ¶
type Scheme string
Scheme represents a type of transport scheme. For the purposes of this project, we only provide constants for schemes relevant to HTTP and websockets.
type WebsocketConn ¶
type WebsocketConn interface { MessageReader JSONWriter }
WebsocketConn is a combination of MessageReader and JSONWriter. It is used to provide an interface to objects that can read from and write to a websocket connection.