Documentation ¶
Index ¶
- Constants
- Variables
- func WebSocketHandler(handler WSServer) http.HandlerFunc
- type SpxError
- type WSClient
- type WSConn
- func (wsConn *WSConn) Close()
- func (wsConn *WSConn) RPC(msgType uint8, token *string, in interface{}, out interface{}) (err error)
- func (wsConn *WSConn) ServerConnIsAlive() bool
- func (wsConn *WSConn) WaitResponse(timeout time.Duration) (msg WSMsg, err error)
- func (wsConn *WSConn) Write(msg WSMsg) (seq uint8, err error)
- func (wsConn *WSConn) WriteAndWaitResponse(msg WSMsg) (response WSMsg, err error)
- type WSMsg
- type WSServer
Constants ¶
View Source
const (
MsgClient = 16
)
Variables ¶
View Source
var ( ErrorHttpTimeout = SpxError{100, "we did not get a response from the server.", "http timeout"} ErrorJWTInvalid = SpxError{101, "invalid API security credentials", "missing or invalid jwt access token"} ErrorInvalidRequest = SpxError{102, "unexpected request parameters", "invalid parameters"} ErrorTimeout = SpxError{103, "operation timeout", "operation timeout"} ErrorClosed = SpxError{104, "socket closed", "underlying fd/socket closed normally"} ErrorInternal = SpxError{999, "unexpected error", "internal error"} )
View Source
var ( NoResponse = WSMsg{0x00, msgNoResponse} AutoRedial bool = true )
View Source
var (
LogAll bool
)
Functions ¶
func WebSocketHandler ¶
func WebSocketHandler(handler WSServer) http.HandlerFunc
Types ¶
type SpxError ¶
type SpxError struct { Code int `json:"code"` Text string `json:"text"` Detail string `json:"error"` }
type WSConn ¶
type WSConn struct { RemoteIP net.IP // store the client public IP on the server side ClientId string // store the device id on the server side // contains filtered or unexported fields }
func GetWebSocketByClientId ¶
func GetWebSocketByRemoteIP ¶
func WebSocketDial ¶
WebSocketDial opens a new web socket connection
func (*WSConn) Close ¶
func (wsConn *WSConn) Close()
Close will terminate the connection with the remote peer. This is the normal scenario. This informs the peer of a normal closure.
func (*WSConn) ServerConnIsAlive ¶
func (*WSConn) WaitResponse ¶
type WSMsg ¶
type WSMsg []byte
WSMsg is a slice, so pass it by value to all
func EncodeBytes ¶
EncodeBytes will add the raw []byte to the msg
func EncodeResponse ¶
EncodeResponse will reuse previous message
func (WSMsg) IsResponse ¶
Click to show internal directories.
Click to hide internal directories.