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 {
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{
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
}