@@ -22,6 +22,7 @@ import (
2222 "net/http"
2323 "net/url"
2424 "strings"
25+ "sync"
2526 "time"
2627
2728 "github.com/frostbyte73/core"
@@ -38,6 +39,10 @@ import (
3839 "github.com/livekit/ingress/pkg/utils"
3940)
4041
42+ const (
43+ sessionNotifyTimeout = 3 * time .Minute
44+ )
45+
4146type proxyWhipHandler struct {
4247 logger logger.Logger
4348 params * params.Params
@@ -47,6 +52,9 @@ type proxyWhipHandler struct {
4752
4853 done core.Fuse
4954 rpcServer rpc.IngressHandlerServer
55+
56+ mu sync.Mutex
57+ watchdog * time.Timer
5058}
5159
5260func NewProxyWHIPHandler (p * params.Params , bus psrpc.MessageBus , ua string ) (WHIPHandler , error ) {
@@ -183,6 +191,13 @@ func (h *proxyWhipHandler) close(isRTCClosed bool) {
183191 return
184192 }
185193
194+ h .mu .Lock ()
195+ if h .watchdog != nil {
196+ h .watchdog .Stop ()
197+ h .watchdog = nil
198+ }
199+ h .mu .Unlock ()
200+
186201 utils .DeregisterIngressRpcHandlers (h .rpcServer , h .params .IngressInfo )
187202 if h .participantID != "" {
188203 if isRTCClosed {
@@ -225,6 +240,8 @@ func (h *proxyWhipHandler) close(isRTCClosed bool) {
225240}
226241
227242func (h * proxyWhipHandler ) WaitForSessionEnd (ctx context.Context ) error {
243+ h .resetWatchDog ()
244+
228245 select {
229246 case <- h .done .Watch ():
230247 case <- ctx .Done ():
@@ -313,11 +330,35 @@ func (h *proxyWhipHandler) ICERestartWHIPResource(ctx context.Context, req *rpc.
313330}
314331
315332func (h * proxyWhipHandler ) WHIPRTCConnectionNotify (ctx context.Context , req * rpc.WHIPRTCConnectionNotifyRequest ) (* google_protobuf2.Empty , error ) {
316- h .logger .Infow ("WHIPRTCConnectionNotify" , "participantID" , h .participantID , "req" , req )
333+ tctx , done := context .WithTimeout (context .Background (), 10 * time .Second )
334+ defer done ()
335+
336+ h .resetWatchDog ()
337+
338+ if req .Video != nil {
339+ h .params .SetInputVideoState (tctx , req .Video , true )
340+ }
341+
342+ if req .Audio != nil {
343+ h .params .SetInputAudioState (tctx , req .Audio , true )
344+ }
317345
318346 if req .Closed {
319347 h .close (true )
320348 }
321349
322350 return & google_protobuf2.Empty {}, nil
323351}
352+
353+ func (h * proxyWhipHandler ) resetWatchDog () {
354+ h .mu .Lock ()
355+ if h .watchdog != nil {
356+ h .watchdog .Stop ()
357+ }
358+
359+ h .watchdog = time .AfterFunc (sessionNotifyTimeout , func () {
360+ h .logger .Infow ("no Notify call from the SFU, terminating ingress" )
361+ h .done .Break ()
362+ })
363+ h .mu .Unlock ()
364+ }
0 commit comments