Documentation ¶
Index ¶
- Variables
- func DefaultUpgrader() *websocket.Upgrader
- func NewProcessor(upgrader *websocket.Upgrader, idGenerator func() (string, error), ...) (pushKit.Processor, error)
- func PolyfillWebSocketRequest(r *http.Request)
- type MessageType
- type WsChannel
- func (channel *WsChannel) BindBsid(bsid string)
- func (channel *WsChannel) BindGroup(group string)
- func (channel *WsChannel) BindUser(user string)
- func (channel *WsChannel) Close(reason string) (err error)
- func (channel *WsChannel) Initialize() error
- func (channel *WsChannel) Push(data []byte) error
- func (channel *WsChannel) PushMessage(messageType *MessageType, data []byte) (err error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( MessageTypeText = &MessageType{ value: websocket.TextMessage, gzipConfig: nil, brotliConfig: nil, } MessageTypeBinary = &MessageType{ value: websocket.BinaryMessage, gzipConfig: nil, brotliConfig: nil, } )
View Source
var IsWebSocketUpgrade func(r *http.Request) bool = websocket.IsWebSocketUpgrade
IsWebSocketUpgrade 是否是WebSocket请求?
Functions ¶
func NewProcessor ¶
func NewProcessor(upgrader *websocket.Upgrader, idGenerator func() (string, error), listener pushKit.Listener, messageType *MessageType, pongInterval time.Duration) (pushKit.Processor, error)
NewProcessor
!!!: 需要先调用 pushKit.MustSetUp 或 pushKit.SetUp.
@param upgrader 可以为nil(将使用默认的) @param idGenerator 可以为nil(将使用xid) @param listener 不能为nil @param msgType 消息类型 @param pongInterval pong的周期(<=0则不发送pong)
func PolyfillWebSocketRequest ¶
PolyfillWebSocketRequest
此函数是为了避免情况: 代理(e.g.Nginx)没有设置WebSocket穿透,导致WebSocket服务收到的WebSocket请求的header有问题.
Types ¶
type MessageType ¶ added in v3.0.57
type MessageType struct {
// contains filtered or unexported fields
}
func NewBrotliMessageType ¶ added in v3.0.61
func NewBrotliMessageType(level, compressThreshold int) (*MessageType, error)
NewBrotliMessageType
PS: 此种情况下,必定使用 websocket.BinaryMessage(二进制数据).
@param compressThreshold 压缩阈值,单位: byte
func NewGzipMessageType ¶ added in v3.0.57
func NewGzipMessageType(level, compressThreshold int) (*MessageType, error)
NewGzipMessageType
PS: 此种情况下,必定使用 websocket.BinaryMessage(二进制数据).
@param compressThreshold 压缩阈值,单位: byte
func (*MessageType) String ¶ added in v3.0.63
func (msgType *MessageType) String()
type WsChannel ¶
type WsChannel struct { pushKit.BaseChannel // contains filtered or unexported fields }
func (*WsChannel) Initialize ¶
func (*WsChannel) PushMessage ¶
func (channel *WsChannel) PushMessage(messageType *MessageType, data []byte) (err error)
PushMessage 推送消息给客户端.
@param MessageType MessageTypeText || MessageTypeBinary
Click to show internal directories.
Click to hide internal directories.