]> 127.0.0.1 Git - part/.git/commitdiff
Improve v0.22.7
authorqydysky <32743305+qydysky@users.noreply.github.com>
Wed, 15 Feb 2023 17:08:35 +0000 (01:08 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Wed, 15 Feb 2023 17:08:35 +0000 (01:08 +0800)
file/FileWR.go
websocket/Recoder.go
websocket/Server.go

index 7bfe0d24795d1a7bd44ad48d7fd542980003270f..15c2cf80d46c98b2bcba429236a285e55e443cc5 100644 (file)
@@ -244,6 +244,10 @@ func (t *File) Delete() error {
        }
        defer t.Unlock()
 
+       if t.IsDir() {
+               return os.RemoveAll(t.Config.FilePath)
+       }
+
        return os.Remove(t.Config.FilePath)
 }
 
index 5078727a79b0bcd3b042a94b78423f3599b2aa63..5e703d78555513dbcd5d8e1e2a569d994723f229 100644 (file)
@@ -92,15 +92,34 @@ func Play(filePath string, perReadSize int, maxReadSize int) (s *Server, close f
                f := file.New(filePath, 0, false)
                defer f.Close()
 
-               startT := time.Now()
                timer := time.NewTicker(time.Second)
+               defer timer.Stop()
+
                var (
+                       cu   float64
                        data []byte
                        err  error
                )
 
+               s.Interface().Pull_tag(map[string]func(any) (disable bool){
+                       `recv`: func(a any) (disable bool) {
+                               if d, ok := a.(Uinterface); ok {
+                                       switch string(d.Data) {
+                                       case "pause":
+                                               timer.Stop()
+                                       case "play":
+                                               timer.Reset(time.Second)
+                                       default:
+                                               cu, _ = strconv.ParseFloat(string(d.Data), 64)
+                                       }
+                               }
+                               return false
+                       },
+               })
+
                for sg.Islive() {
-                       cu := (<-timer.C).Sub(startT).Seconds()
+                       <-timer.C
+                       cu += 1
 
                        for sg.Islive() {
                                if data == nil {
@@ -112,6 +131,8 @@ func Play(filePath string, perReadSize int, maxReadSize int) (s *Server, close f
                                        tIndex := bytes.Index(data, []byte{','})
                                        if d, _ := strconv.ParseFloat(string(data[:tIndex]), 64); d > cu {
                                                break
+                                       } else if d-cu > 2 {
+                                               continue
                                        }
                                        danmuIndex := tIndex + bytes.Index(data[tIndex+2:], []byte{','}) + 3
                                        s.Interface().Push_tag(`send`, Uinterface{
index cef76fc236ec6dce798ca18c6ca6624abb86298e..839a8e6530a66e3b399e0f1cc7fe0f2a103868ac 100644 (file)
@@ -116,40 +116,41 @@ func (t *Server) WS(w http.ResponseWriter, r *http.Request) (o chan uintptr) {
        return
 }
 
-//how to use
-// ws_mq.Pull_tag(map[string]func(interface{})(bool){
-//     `recv`:func(data interface{})(bool){
-//             if tmp,ok := data.(Uinterface);ok {
-//                     log.Println(tmp.Id,string(tmp.Data))
-
-//                     if string(tmp.Data) == `close` {
-//                             ws_mq.Push_tag(`close`,Uinterface{//close
-//                                     Id:0,//close all connect
-//                             })
-//                             //or
-//                             // ws_mq.Push_tag(`close`,Uinterface{//close
-//                             //      Id:tmp.Id,//close this connect
-//                             // })
-//                             return false
-//                     }
-
-//                             ws_mq.Push_tag(`send`,Uinterface{//just reply
-//                                     Id:tmp.Id,
-//                                     Data:tmp.Data,
-//                             })
-//                             //or
-//                             ws_mq.Push_tag(`send`,Uinterface{//just reply
-//                                     Id:0,//send to all
-//                                     Data:tmp.Data,
-//                             })
-//                     }
-//                     return false
-//             },
-//             `error`:func(data interface{})(bool){
-//                     log.Println(data)
-//                     return false
-//             },
-//     })
+// how to use
+//
+//     ws_mq.Pull_tag(map[string]func(interface{})(bool){
+//             `recv`:func(data interface{})(bool){
+//                     if tmp,ok := data.(Uinterface);ok {
+//                             log.Println(tmp.Id,string(tmp.Data))
+//
+//                             if string(tmp.Data) == `close` {
+//                                     ws_mq.Push_tag(`close`,Uinterface{//close
+//                                             Id:0,//close all connect
+//                                     })
+//                                     //or
+//                                     // ws_mq.Push_tag(`close`,Uinterface{//close
+//                                     //      Id:tmp.Id,//close this connect
+//                                     // })
+//                                     return false
+//                             }
+//
+//                                     ws_mq.Push_tag(`send`,Uinterface{//just reply
+//                                             Id:tmp.Id,
+//                                             Data:tmp.Data,
+//                                     })
+//                                     //or
+//                                     ws_mq.Push_tag(`send`,Uinterface{//just reply
+//                                             Id:0,//send to all
+//                                             Data:tmp.Data,
+//                                     })
+//                             }
+//                             return false
+//                     },
+//                     `error`:func(data interface{})(bool){
+//                             log.Println(data)
+//                             return false
+//                     },
+//             })
 func (t *Server) Interface() *mq.Msgq {
        return t.ws_mq
 }