mirror of
https://github.com/flavioribeiro/donut.git
synced 2025-10-06 07:26:49 +08:00
move components to plural named packages
This commit is contained in:
54
internal/controllers/srt_controller.go
Normal file
54
internal/controllers/srt_controller.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
astisrt "github.com/asticode/go-astisrt/pkg"
|
||||
"github.com/flavioribeiro/donut/internal/entities"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type SRTController struct {
|
||||
c *entities.Config
|
||||
l *zap.Logger
|
||||
}
|
||||
|
||||
func NewSRTController(c *entities.Config, l *zap.Logger) *SRTController {
|
||||
return &SRTController{
|
||||
c: c,
|
||||
l: l,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *SRTController) Connect(params *entities.RequestParams) (*astisrt.Connection, error) {
|
||||
if params == nil {
|
||||
return nil, entities.ErrMissingRemoteOffer
|
||||
}
|
||||
|
||||
if err := params.Valid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.l.Sugar().Infow("Connecting to SRT ",
|
||||
"offer", params,
|
||||
)
|
||||
|
||||
conn, err := astisrt.Dial(astisrt.DialOptions{
|
||||
ConnectionOptions: []astisrt.ConnectionOption{
|
||||
astisrt.WithLatency(c.c.SRTConnectionLatencyMS),
|
||||
astisrt.WithStreamid(params.SRTStreamID),
|
||||
},
|
||||
|
||||
OnDisconnect: func(conn *astisrt.Connection, err error) {
|
||||
c.l.Sugar().Fatalw("Disconnected from SRT",
|
||||
"error", err,
|
||||
)
|
||||
},
|
||||
|
||||
Host: params.SRTHost,
|
||||
Port: params.SRTPort,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.l.Sugar().Infow("Connected to SRT")
|
||||
return conn, nil
|
||||
}
|
Reference in New Issue
Block a user