Documentation
¶
Index ¶
- Variables
- func Bridge(t *Transport, c *msg.Channel) error
- func Handle(handler func(*WebSocketConn)) http.Handler
- func HandleFallback(fallback http.Handler, handler func(*WebSocketConn)) http.Handler
- func NewDevice(url string, token string) msg.Device
- type Conn
- type Description
- type Server
- type Transport
- type WebSocketConn
- type WebSocketUpgrader
Constants ¶
This section is empty.
Variables ¶
var ErrNotBinary = errors.New("received non-binary web socket message")
ErrNotBinary indicates that a non-binary websocket frame was received.
Functions ¶
func Bridge ¶
Bridge will forward and return messages from the provided transport to the given channel.
func Handle ¶
func Handle(handler func(*WebSocketConn)) http.Handler
Handle returns an HTTP handler that upgrades websocket requests and invokes handler.
func HandleFallback ¶
func HandleFallback(fallback http.Handler, handler func(*WebSocketConn)) http.Handler
HandleFallback returns an HTTP handler that upgrades websocket requests and invokes handler.
Types ¶
type Conn ¶
type Conn interface {
LocalAddr() net.Addr
RemoteAddr() net.Addr
SetReadDeadline(time.Time) error
Read() ([]byte, error)
Write([]byte) (int, error)
Close() error
}
Conn exchanges packet-oriented binary messages over a connection.
type Description ¶
type Description struct {
UUID string `json:"uuid"`
Connected time.Time `json:"connected"`
DeviceID string `json:"device_id,omitempty"`
DeviceName string `json:"device_name,omitempty"`
AppName string `json:"app_name,omitempty"`
AppVersion string `json:"app_version,omitempty"`
AttachURL string `json:"attach_url"`
AttachToken string `json:"attach_token,omitempty"`
}
Description describes a remotely connected device.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements a NAOS Connect server.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves the NAOS Connect HTTP and websocket endpoints.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport adapts a connection to the msg.Transport interface.
func NewTransport ¶
NewTransport wraps the provided connection in a raw transport.
type WebSocketConn ¶
type WebSocketConn struct {
// contains filtered or unexported fields
}
WebSocketConn adapts a Gorilla websocket connection to Conn.
func NewWebSocketConn ¶
func NewWebSocketConn(conn *websocket.Conn) *WebSocketConn
NewWebSocketConn wraps a Gorilla websocket connection.
func (*WebSocketConn) Close ¶
func (c *WebSocketConn) Close() error
Close closes the websocket connection.
func (*WebSocketConn) LocalAddr ¶
func (c *WebSocketConn) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (*WebSocketConn) Read ¶
func (c *WebSocketConn) Read() ([]byte, error)
Read returns the next binary websocket message.
func (*WebSocketConn) RemoteAddr ¶
func (c *WebSocketConn) RemoteAddr() net.Addr
RemoteAddr returns the remote network address.
func (*WebSocketConn) SetReadDeadline ¶
func (c *WebSocketConn) SetReadDeadline(t time.Time) error
SetReadDeadline forwards the read deadline to the websocket connection.
type WebSocketUpgrader ¶
type WebSocketUpgrader struct {
// contains filtered or unexported fields
}
WebSocketUpgrader upgrades HTTP requests to the NAOS Connect websocket transport.
func NewWebSocketUpgrader ¶
func NewWebSocketUpgrader(fallback http.Handler) *WebSocketUpgrader
NewWebSocketUpgrader returns a websocket upgrader with NAOS Connect defaults.
func (*WebSocketUpgrader) Upgrade ¶
func (u *WebSocketUpgrader) Upgrade(w http.ResponseWriter, r *http.Request) (*WebSocketConn, error)
Upgrade upgrades a websocket request or forwards to the fallback handler.