Documentation ¶
Index ¶
- func CloseCb(cb func(wsc *WsConnection)) func(*WsConnection)
- func CloseOther(userId, device, uuid string)
- func GetUserInfo(store *sessions.CookieStore, c *gin.Context) (userId, device, uuid, appId string, level int, loginTime int64)
- func MsgRecvCb(cb func(wsc *WsConnection, msg []byte)) func(*WsConnection)
- func MsgSendCb(cb func(wsc *WsConnection, message interface{}) ([]byte, error)) func(*WsConnection)
- func PingPeriod(pingPeriod time.Duration) func(*WsConnection)
- func ReadWait(readWait time.Duration) func(*WsConnection)
- func ServeWs(store *sessions.CookieStore, context *gin.Context, callInfo UserInfoHandel)
- func WriteChanCapacity(cap int) func(*WsConnection)
- func WriteReadLimit(limit int64) func(*WsConnection)
- func WriteWait(writeWait time.Duration) func(*WsConnection)
- type UserInfoHandel
- type WsConnection
- func (wsc *WsConnection) Args() interface{}
- func (wsc *WsConnection) Close(args ...interface{}) error
- func (wsc *WsConnection) GetRemoteAddr() string
- func (wsc *WsConnection) OnStart() error
- func (wsc *WsConnection) OnStop()
- func (wsc *WsConnection) TryWriteResponse(resp interface{}) bool
- func (wsc *WsConnection) WriteResponse(resp interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseCb ¶
func CloseCb(cb func(wsc *WsConnection)) func(*WsConnection)
CloseCb sets the callback on the connection closed. It should only be used in the constructor - not Goroutine-safe.
func GetUserInfo ¶
func MsgRecvCb ¶
func MsgRecvCb(cb func(wsc *WsConnection, msg []byte)) func(*WsConnection)
MsgRecvCb sets the callback on msg received from websocket connection. It should only be used in the constructor - not Goroutine-safe.
func MsgSendCb ¶
func MsgSendCb(cb func(wsc *WsConnection, message interface{}) ([]byte, error)) func(*WsConnection)
MsgSendCb sets the callback on msg to send to websocket connection. It should only be used in the constructor - not Goroutine-safe.
func PingPeriod ¶
func PingPeriod(pingPeriod time.Duration) func(*WsConnection)
PingPeriod sets the duration for sending websocket pings. It should only be used in the constructor - not Goroutine-safe.
func ReadWait ¶
func ReadWait(readWait time.Duration) func(*WsConnection)
ReadWait sets the amount of time to wait before a websocket read times out. It should only be used in the constructor - not Goroutine-safe.
func ServeWs ¶
func ServeWs(store *sessions.CookieStore, context *gin.Context, callInfo UserInfoHandel)
ServeWs handles websocket requests from the peer.
func WriteChanCapacity ¶
func WriteChanCapacity(cap int) func(*WsConnection)
WriteChanCapacity sets the capacity of the websocket write channel. It should only be used in the constructor - not Goroutine-safe.
func WriteReadLimit ¶
func WriteReadLimit(limit int64) func(*WsConnection)
func WriteWait ¶
func WriteWait(writeWait time.Duration) func(*WsConnection)
WriteWait sets the amount of time to wait before a websocket write times out. It should only be used in the constructor - not Goroutine-safe.
Types ¶
type UserInfoHandel ¶
type WsConnection ¶
type WsConnection struct { cmn.BaseService // contains filtered or unexported fields }
A single websocket connection contains listener id, underlying ws connection, and the event switch for subscribing to events.
In case of an error, the connection is stopped.
func NewWSConnection ¶
func NewWSConnection(baseConn *websocket.Conn, args interface{}, options ...func(*WsConnection)) *WsConnection
NewWSConnection wraps websocket.Conn.
See the commentary on the func(*wsConnection) functions for a detailed description of how to configure ping period and pong wait time. NOTE: if the write buffer is full, pongs may be dropped, which may cause clients to disconnect. see https://github.com/gorilla/websocket/issues/97
func (*WsConnection) Args ¶
func (wsc *WsConnection) Args() interface{}
Args return extra info injected into wsc
func (*WsConnection) Close ¶
func (wsc *WsConnection) Close(args ...interface{}) error
func (*WsConnection) GetRemoteAddr ¶
func (wsc *WsConnection) GetRemoteAddr() string
GetRemoteAddr returns the remote address of the underlying connection. It implements WSRPCConnection
func (*WsConnection) OnStart ¶
func (wsc *WsConnection) OnStart() error
OnStart implements cmn.Service by starting the read and write routines. It blocks until the connection closes.
func (*WsConnection) OnStop ¶
func (wsc *WsConnection) OnStop()
OnStop implements cmn.Service by unsubscribing remoteAddr from all subscriptions.
func (*WsConnection) TryWriteResponse ¶
func (wsc *WsConnection) TryWriteResponse(resp interface{}) bool
TryWriteResponse attempts to push a response to the writeChan, but does not block. It implements WSRPCConnection. It is Goroutine-safe
func (*WsConnection) WriteResponse ¶
func (wsc *WsConnection) WriteResponse(resp interface{})
WriteResponse pushes a response to the writeChan, and blocks until it is accepted. It implements WSRPCConnection. It is Goroutine-safe.