Documentation ¶
Index ¶
- type Authentication
- type AuthenticationI
- type CodecI
- type Context
- func (p *Context) Close() error
- func (p *Context) GetConn() *websocket.Conn
- func (p *Context) GetHub() HubI
- func (p *Context) GetId() int
- func (p *Context) Go()
- func (p *Context) HandShake(r *http.Request, c *gin.Context) bool
- func (p *Context) Message(b []byte)
- func (p *Context) Open(r *http.Request, c *gin.Context) bool
- func (p *Context) Send(message []byte)
- func (p *Context) SetUp(id int, conn *websocket.Conn, hub HubI)
- type ContextConnI
- type CtxOption
- type DefaultHandler
- type HandlerI
- type Hub
- func (h *Hub) FindContextConnById(id int) (ctx ContextConnI)
- func (h *Hub) GetLogger() log.Logger
- func (h *Hub) IdIsOnLine(id int) (onLine bool, ctx ContextConnI)
- func (h *Hub) OnlineMapping() map[int]ContextConnI
- func (h *Hub) Register(id int, i ContextConnI)
- func (h *Hub) Serve(w http.ResponseWriter, r *http.Request, c *gin.Context, ...)
- func (h *Hub) TotalOnline() int
- func (h *Hub) UnRegister(id int)
- type HubI
- type HubOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authentication ¶
type Authentication struct { }
func (*Authentication) Authenticate ¶
func (p *Authentication) Authenticate(r *http.Request, c *gin.Context, conn *websocket.Conn) (int, bool)
Authenticate todo: implement Authenticate method, based on jwt token auth 1. get token key from http header 2. if not get token key from cookies 3. if not get token key from first message 4. parse token key to find user
type AuthenticationI ¶
type AuthenticationI interface {
Authenticate(r *http.Request, c *gin.Context, conn *websocket.Conn) (int, bool)
}
AuthenticationI authenticate conn users
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context websocket context
func NewContext ¶
NewContext 实例化 websocket context function
type ContextConnI ¶
type ContextConnI interface { SetUp(id int, conn *websocket.Conn, hub HubI) Send(message []byte) GetHub() HubI GetId() int GetConn() *websocket.Conn Go() HandShake(r *http.Request, c *gin.Context) bool Open(r *http.Request, c *gin.Context) bool Close() error }
ContextConnI context conn interface
type DefaultHandler ¶
type DefaultHandler struct { }
DefaultHandler 默认的示例 处理业务接口
func (*DefaultHandler) Message ¶
func (p *DefaultHandler) Message(ctx ContextConnI, msg []byte)
Message read callback 处理收到的消息信令
type HandlerI ¶
type HandlerI interface { HandShake(r *http.Request, c *gin.Context) bool Open(r *http.Request, c *gin.Context) bool Message(ctx ContextConnI, msg []byte) Close(ctx ContextConnI) }
HandlerI conn handler interface
type Hub ¶
type Hub struct { // Inbound messages from the clients. Broadcast chan []byte // contains filtered or unexported fields }
func (*Hub) FindContextConnById ¶
func (h *Hub) FindContextConnById(id int) (ctx ContextConnI)
func (*Hub) IdIsOnLine ¶
func (h *Hub) IdIsOnLine(id int) (onLine bool, ctx ContextConnI)
func (*Hub) OnlineMapping ¶
func (h *Hub) OnlineMapping() map[int]ContextConnI
func (*Hub) Register ¶
func (h *Hub) Register(id int, i ContextConnI)
func (*Hub) Serve ¶
func (h *Hub) Serve(w http.ResponseWriter, r *http.Request, c *gin.Context, authentication AuthenticationI, ctx ContextConnI)
Serve 1. context 2. id 3. conn 4. open message close 5. go writer reader
func (*Hub) TotalOnline ¶
func (*Hub) UnRegister ¶
type HubI ¶
type HubI interface { TotalOnline() int UnRegister(id int) Register(id int, i ContextConnI) FindContextConnById(id int) ContextConnI IdIsOnLine(id int) (bool, ContextConnI) GetLogger() log.Logger }
HubI hub ws interface websocket 长链接相关接口方法的定义
Click to show internal directories.
Click to hide internal directories.