77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
|
|
// ************************************
|
|||
|
|
// @package: websocketServer
|
|||
|
|
// @description: WsServer/WssServer接口,以便统一调用
|
|||
|
|
// @author:
|
|||
|
|
// @revision history:
|
|||
|
|
// @create date: 2022-02-22 16:07:27
|
|||
|
|
// ************************************
|
|||
|
|
package websocketServer
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"github.com/gorilla/websocket"
|
|||
|
|
webServer "Framework/webServer"
|
|||
|
|
"sync"
|
|||
|
|
"time"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// IServer
|
|||
|
|
// @description: WsServer/WssServer接口,以便统一调用
|
|||
|
|
type IServer interface {
|
|||
|
|
//-------------------------------------
|
|||
|
|
// HttpServer方法
|
|||
|
|
|
|||
|
|
// HttpServer接口
|
|||
|
|
webServer.IWebServer
|
|||
|
|
|
|||
|
|
// 设置地址
|
|||
|
|
SetAddr(addr string)
|
|||
|
|
|
|||
|
|
// 启动HttpServer
|
|||
|
|
Start(wg *sync.WaitGroup)
|
|||
|
|
|
|||
|
|
//-------------------------------------
|
|||
|
|
// websocket方法
|
|||
|
|
|
|||
|
|
// 注册websocket回调
|
|||
|
|
RegisterWebsocketHandler(path string, eventCallback *EventCallbackFuncs, configObj *webServer.HandlerConfig)
|
|||
|
|
|
|||
|
|
// 注册正则websocket回调
|
|||
|
|
RegisterRegexWebsocketHandler(path string, eventCallback *EventCallbackFuncs, configObj *webServer.HandlerConfig)
|
|||
|
|
|
|||
|
|
// 设置websocket参数结构
|
|||
|
|
SetUpgrader(upgrader *websocket.Upgrader)
|
|||
|
|
|
|||
|
|
// 获取websocket参数结构
|
|||
|
|
GetUpgrader() *websocket.Upgrader
|
|||
|
|
|
|||
|
|
// 设置接收到Ping消息时,是否自动回复Pong信息
|
|||
|
|
SetAutoPong(autuPong bool)
|
|||
|
|
|
|||
|
|
// 获取接收到Ping消息时,是否自动回复Pong信息
|
|||
|
|
GetAutoPong() bool
|
|||
|
|
|
|||
|
|
// 设置心跳检测信息
|
|||
|
|
SetHeartbeatDetectInfo(heartbeatCloseCount int, heartbeatCycle time.Duration)
|
|||
|
|
|
|||
|
|
// 获取心跳检测信息
|
|||
|
|
GetHeartbeatDetectInfo() (heartbeatCloseCount int, heartbeatCycle time.Duration)
|
|||
|
|
|
|||
|
|
// 设置广播并发数
|
|||
|
|
SetBroadcastConcurrent(n int)
|
|||
|
|
|
|||
|
|
// 允许新连接
|
|||
|
|
EnableNewConn()
|
|||
|
|
|
|||
|
|
// 禁用新连接
|
|||
|
|
DisableNewConn()
|
|||
|
|
|
|||
|
|
// 多播消息(给指定多用户发送消息)
|
|||
|
|
MulticastMessage(ctxs []*Context, messageType int, data []byte) (err error)
|
|||
|
|
|
|||
|
|
// 消息广播
|
|||
|
|
BroadcastMessage(messageType int, data []byte) (err error)
|
|||
|
|
|
|||
|
|
// 关闭所有连接
|
|||
|
|
CloseAll()
|
|||
|
|
}
|