fusenapi/server/websocket/internal/logic/allocation_processing_factory.go

34 lines
773 B
Go
Raw Normal View History

2023-08-30 09:40:40 +00:00
package logic
import (
"fusenapi/constants"
)
// 消息分发工厂
type allocationProcessorFactory interface {
allocationMessage(data []byte)
}
var mapAllocationProcessor = make(map[constants.Websocket]allocationProcessorFactory)
func (w *wsConnectItem) newAllocationProcessor(msgType constants.Websocket) allocationProcessorFactory {
if obj, ok := mapAllocationProcessor[msgType]; ok {
return obj
}
var obj allocationProcessorFactory
switch msgType {
//图片渲染
case constants.WEBSOCKET_RENDER_IMAGE:
2023-08-30 10:00:26 +00:00
obj = &renderProcessor{*w}
2023-08-30 09:40:40 +00:00
//刷新重连请求恢复上次连接的标识
case constants.WEBSOCKET_REQUEST_REUSE_LAST_CONNECT:
2023-08-30 10:00:26 +00:00
obj = &reuseConnProcessor{*w}
2023-08-30 09:40:40 +00:00
default:
}
if obj != nil {
mapAllocationProcessor[msgType] = obj
}
return obj
}