subscriber.go 756 B

123456789101112131415161718192021222324252627282930313233343536
  1. package ps
  2. import (
  3. "bytes"
  4. "github.com/gobwas/ws/wsutil"
  5. . "m7s.live/engine/v4"
  6. "m7s.live/engine/v4/common"
  7. "m7s.live/engine/v4/util"
  8. )
  9. type PSSubscriber struct {
  10. Subscriber
  11. }
  12. func (ps *PSSubscriber) OnEvent(event any) {
  13. switch v := event.(type) {
  14. case *PSTrack:
  15. wsutil.WriteServerBinary(ps, util.ConcatBuffers(v.GetPSM()))
  16. enter := false
  17. go v.Play(ps.IO, func(data *common.DataFrame[*util.ListItem[util.Buffer]]) error {
  18. if !enter {
  19. if bytes.Compare(data.Data.Value[:3], []byte{0, 0, 1}) == 0 {
  20. enter = true
  21. } else {
  22. return nil
  23. }
  24. }
  25. // fmt.Printf("% 02X", data.Value.Value[:10])
  26. // fmt.Println()
  27. return wsutil.WriteServerBinary(ps, data.Data.Value)
  28. })
  29. default:
  30. ps.Subscriber.OnEvent(event)
  31. }
  32. }