]> 127.0.0.1 Git - part/.git/commitdiff
1 v0.28.20240721000404
authorqydysky <qydysky@foxmail.com>
Sat, 20 Jul 2024 23:58:44 +0000 (07:58 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 20 Jul 2024 23:58:44 +0000 (07:58 +0800)
websocket/Recoder.go

index f8b4915f549c16bb511c078b6b0af308dfaae861..d6ee7dbd381f1f4b45559b73696141263a8849c3 100644 (file)
@@ -7,6 +7,7 @@ import (
        "fmt"
        "io"
        "strconv"
+       "sync/atomic"
        "time"
 
        "github.com/dustin/go-humanize"
@@ -98,7 +99,7 @@ func Play(filePath string) (s *Server, close func()) {
                defer timer.Stop()
 
                var (
-                       cu   float64
+                       cu   atomic.Int64
                        data []byte
                        e    error
                )
@@ -111,6 +112,14 @@ func Play(filePath string) (s *Server, close func()) {
                                                timer.Stop()
                                        case "play":
                                                timer.Reset(time.Second)
+                                       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"),
+                                                       })
+                                               }
                                        }
                                }
                                return false
@@ -124,7 +133,7 @@ func Play(filePath string) (s *Server, close func()) {
                                return
                        }
 
-                       cu += 1
+                       cu.Add(1)
 
                        for !ctx.Done(sg) {
                                if data == nil {
@@ -137,7 +146,7 @@ func Play(filePath string) (s *Server, close func()) {
                                }
 
                                tIndex := bytes.Index(data, []byte{','})
-                               if d, _ := strconv.ParseFloat(string(data[:tIndex]), 64); d < cu {
+                               if d, _ := strconv.ParseFloat(string(data[:tIndex]), 64); d < float64(cu.Load()) {
                                        danmuIndex := tIndex + bytes.Index(data[tIndex+2:], []byte{','}) + 3
                                        s.Interface().Push_tag(`send`, Uinterface{
                                                Id:   0, //send to all