raw.go 582 B

123456789101112131415161718192021222324252627282930313233
  1. package jessica
  2. import (
  3. "github.com/gobwas/ws"
  4. . "m7s.live/engine/v4"
  5. "m7s.live/engine/v4/util"
  6. )
  7. type JessicaH26x struct {
  8. JessicaBase
  9. }
  10. func (j *JessicaH26x) OnEvent(event any) {
  11. switch v := event.(type) {
  12. case VideoFrame:
  13. annexB := v.GetAnnexB()
  14. if j.IsWebSocket {
  15. if err := ws.WriteHeader(j, ws.Header{
  16. Fin: true,
  17. OpCode: ws.OpBinary,
  18. Length: int64(util.SizeOfBuffers(annexB)),
  19. }); err != nil {
  20. j.Stop()
  21. return
  22. }
  23. }
  24. if _, err := annexB.WriteTo(j.Writer); err != nil {
  25. j.Stop()
  26. }
  27. default:
  28. j.Subscriber.OnEvent(event)
  29. }
  30. }