Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateLetter(length int) string
- type ListenerBuilderConfig
- type ListenerSystem
- func (ls *ListenerSystem) Callback(cb func(*Payload) error) error
- func (ls *ListenerSystem) CloseClient(id string, statusCode ws.StatusCode) error
- func (ls *ListenerSystem) CloseClientWithMessage(id string, statusCode ws.StatusCode, message string) error
- func (ls *ListenerSystem) Listen() error
- func (ls *ListenerSystem) SendBinary(id string, data []byte) error
- func (ls *ListenerSystem) SendPing(id string)
- func (ls *ListenerSystem) SendText(id string, text []byte) error
- type Payload
Constants ¶
View Source
const ( OpText ws.OpCode = 0x1 OpBinary ws.OpCode = 0x2 OpInvalidData ws.OpCode = 0x5 OpConnected ws.OpCode = 0x6 OpPingTimeout ws.OpCode = 0x7 OpClose ws.OpCode = 0x8 OpPing ws.OpCode = 0x9 OpPong ws.OpCode = 0xa StatusNormalClosure ws.StatusCode = 1000 StatusGoingAway ws.StatusCode = 1001 StatusProtocolError ws.StatusCode = 1002 StatusUnsupportedData ws.StatusCode = 1003 StatusNoMeaningYet ws.StatusCode = 1004 StatusInvalidFramePayloadData ws.StatusCode = 1007 StatusPolicyViolation ws.StatusCode = 1008 StatusMessageTooBig ws.StatusCode = 1009 StatusMandatoryExt ws.StatusCode = 1010 StatusInternalServerError ws.StatusCode = 1011 StatusTLSHandshake ws.StatusCode = 1015 )
External opcode defined to be more specifically about some events
Variables ¶
View Source
var ( // ErrCallbackISNil defined when user did not set callback func ErrCallbackISNil = errors.New("Callback should not be nil") // ErrUserNotFound in session list ErrUserNotFound = errors.New("UserID not found") )
Functions ¶
Types ¶
type ListenerBuilderConfig ¶
type ListenerBuilderConfig struct { ReadBufferSize int WriteBufferSize int Port int IDLength int WorkerCount int PingFailCount int QueueSize uint64 PingInterval time.Duration }
ListenerBuilderConfig is used when you want to constructing listener system use DefaultConfig for more safety
func DefaultConfig ¶
func DefaultConfig() *ListenerBuilderConfig
DefaultConfig to construct websocket server
func (*ListenerBuilderConfig) Build ¶
func (c *ListenerBuilderConfig) Build() (*ListenerSystem, error)
Build ListenerSystem from config
type ListenerSystem ¶
type ListenerSystem struct {
// contains filtered or unexported fields
}
ListenerSystem will listen all the traffic including new connection, bi-directional communication, etc.
func (*ListenerSystem) Callback ¶
func (ls *ListenerSystem) Callback(cb func(*Payload) error) error
Callback used to set an action to incoming message
func (*ListenerSystem) CloseClient ¶
func (ls *ListenerSystem) CloseClient(id string, statusCode ws.StatusCode) error
CloseClient without any specified messaage
func (*ListenerSystem) CloseClientWithMessage ¶
func (ls *ListenerSystem) CloseClientWithMessage(id string, statusCode ws.StatusCode, message string) error
CloseClientWithMessage return err if connection id not found or connection already closed
func (*ListenerSystem) Listen ¶
func (ls *ListenerSystem) Listen() error
Listen every connection, message, event, etc.
func (*ListenerSystem) SendBinary ¶
func (ls *ListenerSystem) SendBinary(id string, data []byte) error
SendBinary byte to specified user
func (*ListenerSystem) SendPing ¶
func (ls *ListenerSystem) SendPing(id string)
SendPing to user to check whether the user is still active
Click to show internal directories.
Click to hide internal directories.