raw.go 629 B

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