websocket_fasthttp/socket_handler.go
2017-11-28 00:42:27 +09:00

75 lines
1.9 KiB
Go

package websocket_fasthttp
import (
"time"
"github.com/valyala/fasthttp"
)
type SocketHandler interface {
// Init invoked when server is stated
// If you override ths method, must call
//
// func (sh *SocketHandler) Init() error {
// if err := sh.SocketHandlers.Init(); nil != err {
// return err
// }
// ...
// ...
// return nil
// }
Init(serverCTX ServerContext) error
// Handshake do handshake client and server
// id is identity of client socket. if id is "", disallow connection
Handshake(serverCTX ServerContext, ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader)
SocketContext(serverCTX ServerContext) SocketContext
// OnConnect invoked when client is connected
// If you override ths method, must call
//
// func (sh *SocketHandler) OnConnect(soc cwf.Socket) cwf.Socket {
// soc = sh.SocketHandlers.OnConnect(newSoc)
// newSoc := ...
// return newSoc
// }
OnConnect(soc Socket)
Handle(soc Socket, stopChan <-chan struct{}, doneChan chan<- struct{})
// OnDisconnect invoked when client is disconnected
// If you override ths method, must call
//
// func (sh *SocketHandler) OnDisconnect(soc cwf.Socket) {
// ...
// sh.SocketHandlers.OnDisconnect(soc)
// }
OnDisconnect(soc Socket)
// Destroy invoked when server is stopped
// If you override ths method, must call
//
// func (sh *SocketHandler) Destroy() {
// ...
// sh.SocketHandlers.Destroy()
// }
Destroy()
GetSocket(id string) Socket
GetSockets() map[string]Socket
GetMaxMessageSize() int64
GetWriteTimeout() time.Duration
GetReadTimeout() time.Duration
GetPongTimeout() time.Duration
GetPingTimeout() time.Duration
GetPingPeriod() time.Duration
// Validate is check handler value
// If you override ths method, must call
//
// func (sh *SocketHandlers) Validate() {
// sh.SocketHandlers.Validate()
// ...
// }
Validate()
addSocket(soc Socket)
removeSocket(soc Socket)
}