ws

package
v0.0.0-...-59da782 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

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 CloseOther

func CloseOther(userId, device, uuid string)

挤掉其他所有端

func GetUserInfo

func GetUserInfo(store *sessions.CookieStore, c *gin.Context) (userId, device, uuid, appId string, level int, loginTime int64)

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 UserInfoHandel func(store *sessions.CookieStore, context *gin.Context) (userId, device, uuid, appId string, level int, loginTime int64)

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.

Jump to

Keyboard shortcuts

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