Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion pkg/sip/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions pkg/sip/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type Handler interface {
RegisterTransferSIPParticipantTopic(sipCallId string) error
DeregisterTransferSIPParticipantTopic(sipCallId string)

OnInboundInfo(log logger.Logger, callInfo *rpc.SIPCall, headers Headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not have something more generic like OnRemoteHeaders(), applicable to both outbound and inbound?

The inbound call can stay where it is, and the outbound can happen on 200 (or any non-100 reponse)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's different logic here for inbound vs outbound. I could add both hooks now, but they won't do anything for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, would be nice, but not a showstopper.
Lets just remember to rename this to something that may apply to both directions once we introduce that.

OnSessionEnd(ctx context.Context, callIdentifier *CallIdentifier, callInfo *livekit.SIPCallInfo, reason string)
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/sip/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"math/rand"
"sync"
"testing"
"time"

Expand All @@ -22,8 +23,6 @@ import (

"github.com/livekit/media-sdk/sdp"

"sync"

"github.com/livekit/sip/pkg/config"
"github.com/livekit/sip/pkg/stats"
)
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down