Socket send batches of videos
All checks were successful
gitea/video-server-backend/pipeline/head This commit looks good
All checks were successful
gitea/video-server-backend/pipeline/head This commit looks good
This commit is contained in:
parent
5cefad8df3
commit
02accfa66b
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
var upgrader = websocket.Upgrader{
|
var upgrader = websocket.Upgrader{
|
||||||
ReadBufferSize: 1024,
|
ReadBufferSize: 1024,
|
||||||
WriteBufferSize: 1024,
|
WriteBufferSize: 4096,
|
||||||
CheckOrigin: func(r *http.Request) bool {
|
CheckOrigin: func(r *http.Request) bool {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
@ -53,36 +53,46 @@ func connectSearchSocket(w http.ResponseWriter, r *http.Request) {
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
files := []string{}
|
var msg = []byte{}
|
||||||
err = filepath.Walk(VIDEOS_DIR, func(path string, info os.FileInfo, err error) error {
|
err = filepath.Walk(VIDEOS_DIR, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
fmt.Println("checking " + path)
|
||||||
return err
|
if strings.HasSuffix(path, ".mp4") && strings.Contains(path, query) {
|
||||||
}
|
fmt.Println("found video " + path)
|
||||||
|
jsonMsg, err := json.Marshal(Video{Filename: path})
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
jsonMsg = append(jsonMsg, []byte("\n")...)
|
||||||
|
|
||||||
if strings.HasSuffix(path, ".mp4") {
|
if len(msg)+len(jsonMsg) > 4096 {
|
||||||
files = append(files, path)
|
fmt.Println("sending message")
|
||||||
|
err = conn.WriteMessage(websocket.TextMessage, msg)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
msg = jsonMsg
|
||||||
|
} else {
|
||||||
|
msg = append(msg, jsonMsg...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// http.Error(w, "Could not read video directory.", http.StatusInternalServerError)
|
log.Println(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
// Send remaining messages
|
||||||
if strings.Contains(file, query) {
|
if len(msg) > 0 {
|
||||||
jsonMsg, err := json.Marshal(Video{Filename: file})
|
err = conn.WriteMessage(websocket.TextMessage, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
|
||||||
|
|
||||||
err = conn.WriteMessage(websocket.TextMessage, jsonMsg)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("done")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func streamVideo(w http.ResponseWriter, r *http.Request) {
|
func streamVideo(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user