This commit is contained in:
2024-10-24 02:35:37 +08:00
parent ac45ad5b44
commit 35db859788
12 changed files with 416 additions and 292 deletions

6
websocket/outputer.go Normal file
View File

@@ -0,0 +1,6 @@
package websocket
type Outputer interface {
Broadcast(v Response)
Single(userID string, v Response)
}

47
websocket/websocket.go Normal file
View File

@@ -0,0 +1,47 @@
package websocket
type MessageType string
var (
TypeOutput MessageType = "Output"
TypeStreamNextVideo MessageType = "StreamNextVideo"
TypeStreamPrevVideo MessageType = "StreamPrevVideo"
TypeGetCurrentVideoPath MessageType = "GetCurrentVideoPath"
TypeGetVideoList MessageType = "GetVideoList"
TypeQuit MessageType = "Quit"
TypeRemoveVideo MessageType = "RemoveVideo"
TypeAddVideo MessageType = "AddVideo"
)
type Request struct {
Type MessageType `json:"type"`
Args []string `json:"args"`
UserID string `json:"user_id"`
Timestamp int64 `json:"timestamp"`
}
type Response struct {
Type MessageType `json:"type"`
Success bool `json:"success"`
Data any `json:"data"`
Message string `json:"message"`
UserID string `json:"user_id"`
Timestamp int64 `json:"timestamp"`
}
func MakeResponse(messageType MessageType, success bool, data any, message string) Response {
return Response{
Type: messageType,
Success: success,
Data: data,
Message: message,
}
}
func MakeOutput(output string) Response {
return Response{
Success: true,
Type: TypeOutput,
Data: output,
}
}