provides cancelation when a component stop responding it closes all resources

This commit is contained in:
Leandro Moreira
2024-01-31 00:21:15 -03:00
parent 1e29f3c4ab
commit a903aa17d7
6 changed files with 97 additions and 43 deletions

View File

@@ -51,18 +51,15 @@ func NewSRTController(c *entities.Config, l *zap.Logger, lc fx.Lifecycle) (*SRTC
}, nil
}
func (c *SRTController) Connect(params *entities.RequestParams) (*astisrt.Connection, error) {
func (c *SRTController) Connect(cancel context.CancelFunc, params entities.RequestParams) (*astisrt.Connection, error) {
c.l.Sugar().Infow("trying to connect srt")
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,
"offer", params.String(),
)
conn, err := astisrt.Dial(astisrt.DialOptions{
@@ -74,9 +71,10 @@ func (c *SRTController) Connect(params *entities.RequestParams) (*astisrt.Connec
},
OnDisconnect: func(conn *astisrt.Connection, err error) {
c.l.Sugar().Fatalw("Disconnected from SRT",
c.l.Sugar().Infow("Canceling SRT",
"error", err,
)
cancel()
},
Host: params.SRTHost,