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

33 lines
809 B
Go
Raw Normal View History

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