From c83d51303cc4eb1f88be7f88f25cf6794b7b8320 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Tue, 16 Dec 2025 15:06:52 +0200 Subject: [PATCH] Add inbound call info callback. --- pkg/service/service.go | 4 ++++ pkg/sip/inbound.go | 4 +++- pkg/sip/server.go | 1 + pkg/sip/service_test.go | 10 ++++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/service/service.go b/pkg/service/service.go index 4ab713e7..c6aa97a6 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -254,6 +254,10 @@ func (s *Service) DeregisterTransferSIPParticipantTopic(sipCallId string) { } } +func (s *Service) OnInboundInfo(log logger.Logger, callInfo *rpc.SIPCall, headers sip.Headers) { + +} + func (s *Service) OnSessionEnd(ctx context.Context, callIdentifier *sip.CallIdentifier, callInfo *livekit.SIPCallInfo, reason string) { s.log.Infow("SIP call ended", "callID", callInfo.CallId, "reason", reason) } diff --git a/pkg/sip/inbound.go b/pkg/sip/inbound.go index 1ffa1e20..60a2770f 100644 --- a/pkg/sip/inbound.go +++ b/pkg/sip/inbound.go @@ -382,7 +382,9 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE From: ToSIPUri("", from), To: ToSIPUri("", to), } - for _, h := range cc.RemoteHeaders() { + rheaders := cc.RemoteHeaders() + s.handler.OnInboundInfo(log, callInfo, rheaders) + for _, h := range rheaders { switch h := h.(type) { case *sip.ViaHeader: callInfo.Via = append(callInfo.Via, &livekit.SIPUri{ diff --git a/pkg/sip/server.go b/pkg/sip/server.go index bedfcd9e..219f1562 100644 --- a/pkg/sip/server.go +++ b/pkg/sip/server.go @@ -124,6 +124,7 @@ type Handler interface { RegisterTransferSIPParticipantTopic(sipCallId string) error DeregisterTransferSIPParticipantTopic(sipCallId string) + OnInboundInfo(log logger.Logger, callInfo *rpc.SIPCall, headers Headers) OnSessionEnd(ctx context.Context, callIdentifier *CallIdentifier, callInfo *livekit.SIPCallInfo, reason string) } diff --git a/pkg/sip/service_test.go b/pkg/sip/service_test.go index 5b21fb7c..0f7451c5 100644 --- a/pkg/sip/service_test.go +++ b/pkg/sip/service_test.go @@ -5,6 +5,7 @@ import ( "fmt" "log/slog" "math/rand" + "sync" "testing" "time" @@ -22,8 +23,6 @@ import ( "github.com/livekit/media-sdk/sdp" - "sync" - "github.com/livekit/sip/pkg/config" "github.com/livekit/sip/pkg/stats" ) @@ -61,6 +60,7 @@ func expectNoResponse(t *testing.T, tx sip.ClientTransaction) { type TestHandler struct { GetAuthCredentialsFunc func(ctx context.Context, call *rpc.SIPCall) (AuthInfo, error) DispatchCallFunc func(ctx context.Context, info *CallInfo) CallDispatch + OnInboundInfoFunc func(log logger.Logger, call *rpc.SIPCall, headers Headers) OnSessionEndFunc func(ctx context.Context, callIdentifier *CallIdentifier, callInfo *livekit.SIPCallInfo, reason string) } @@ -85,6 +85,12 @@ func (h TestHandler) DeregisterTransferSIPParticipantTopic(sipCallId string) { // no-op } +func (h TestHandler) OnInboundInfo(log logger.Logger, call *rpc.SIPCall, headers Headers) { + if h.OnInboundInfoFunc != nil { + h.OnInboundInfoFunc(log, call, headers) + } +} + func (h TestHandler) OnSessionEnd(ctx context.Context, callIdentifier *CallIdentifier, callInfo *livekit.SIPCallInfo, reason string) { if h.OnSessionEndFunc != nil { h.OnSessionEndFunc(ctx, callIdentifier, callInfo, reason)