]> 127.0.0.1 Git - part/.git/commitdiff
2 v0.28.20240721004428
authorqydysky <qydysky@foxmail.com>
Sun, 21 Jul 2024 00:38:03 +0000 (08:38 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 21 Jul 2024 00:38:03 +0000 (08:38 +0800)
websocket/Recoder.go

index 241e0dc2392b68a8fb53e862283da8cc7cda79ff..7d7b01898adffb67e915742cf68387f0f0e7f869 100644 (file)
@@ -100,9 +100,10 @@ func Play(filePath string) (s *Server, close func()) {
                defer timer.Stop()
 
                var (
-                       cu   atomic.Int64
-                       data []byte
-                       e    error
+                       cu       atomic.Int64
+                       data     []byte
+                       sendData = pslice.New[byte]()
+                       e        error
                )
 
                s.Interface().Pull_tag(map[string]func(any) (disable bool){
@@ -116,10 +117,6 @@ func Play(filePath string) (s *Server, close func()) {
                                        default:
                                                if d, err := strconv.ParseFloat(data, 64); err == nil && d > 0 {
                                                        cu.Store(int64(d))
-                                                       s.Interface().Push_tag(`send`, Uinterface{
-                                                               Id:   0, //send to all
-                                                               Data: []byte("ok"),
-                                                       })
                                                }
                                        }
                                }
@@ -127,8 +124,6 @@ func Play(filePath string) (s *Server, close func()) {
                        },
                })
 
-               sendData := pslice.New[byte]()
-
                for !ctx.Done(sg) {
                        select {
                        case <-timer.C:
@@ -141,13 +136,11 @@ func Play(filePath string) (s *Server, close func()) {
                        sendData.Reset()
                        sendData.Append([]byte("["))
                        for !ctx.Done(sg) {
-                               if data == nil {
-                                       if data, e = f.ReadUntil([]byte{'\n'}, 70, humanize.MByte); e != nil && !errors.Is(e, io.EOF) {
-                                               panic(e)
-                                       }
-                                       if len(data) == 0 {
-                                               return
-                                       }
+                               if data, e = f.ReadUntil([]byte{'\n'}, 70, humanize.MByte); e != nil && !errors.Is(e, io.EOF) {
+                                       panic(e)
+                               }
+                               if len(data) == 0 {
+                                       return
                                }
 
                                tIndex := bytes.Index(data, []byte{','})