This commit is contained in:
2024-10-24 05:06:19 +08:00
parent 35db859788
commit 020f2eea9b
7 changed files with 218 additions and 272 deletions

View File

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

View File

@@ -1,47 +1,20 @@
package websocket
type MessageType string
type RequestType 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"
const (
TypeStreamNextVideo RequestType = "StreamNextVideo"
TypeStreamPrevVideo RequestType = "StreamPrevVideo"
TypeQuit RequestType = "Quit"
)
type Request struct {
Type MessageType `json:"type"`
Args []string `json:"args"`
UserID string `json:"user_id"`
Timestamp int64 `json:"timestamp"`
Type RequestType `json:"type"`
}
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,
}
type Date struct {
Timestamp int64 `json:"timestamp"`
CurrentVideoPath string `json:"currentVideoPath"`
VideoList []string `json:"videoList"`
Output string `json:"output"`
}