websocket_fasthttp/socket_handler.go

69 lines
1.7 KiB
Go
Raw Normal View History

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