diff --git a/pkg/service/ioservice_sip.go b/pkg/service/ioservice_sip.go index b4ffdfa62..95a13e6e5 100644 --- a/pkg/service/ioservice_sip.go +++ b/pkg/service/ioservice_sip.go @@ -22,6 +22,8 @@ import ( "github.com/livekit/protocol/logger" "github.com/livekit/protocol/rpc" "github.com/livekit/protocol/sip" + "github.com/livekit/psrpc" + "google.golang.org/protobuf/types/known/emptypb" ) // matchSIPTrunk finds a SIP Trunk definition matching the request. @@ -100,3 +102,27 @@ func (s *IOInfoService) GetSIPTrunkAuthentication(ctx context.Context, req *rpc. Password: trunk.AuthPassword, }, nil } + +func (s *IOInfoService) UpdateSIPCallState(ctx context.Context, req *rpc.UpdateSIPCallStateRequest) (*emptypb.Empty, error) { + log := logger.GetLogger() + log = log.WithValues("callID", req.CallInfo.CallId, "callStatus", req.CallInfo.CallStatus.String()) + + log.Infow("SIP call state updated") + + if req.CallInfo == nil { + return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "no call info in UpdateSIPCallState request") + } + + switch req.CallInfo.CallStatus { + case livekit.SIPCallStatus_SIP_CALL_STATUS_PARTICIPANT_JOINED: + s.telemetry.SIPParticipantCreated(ctx, req.CallInfo) + case livekit.SIPCallStatus_SIP_CALL_STATUS_CALL_INCOMING: + s.telemetry.SIPCallIncoming(ctx, req.CallInfo) + case livekit.SIPCallStatus_SIP_CALL_STATUS_ACTIVE: + s.telemetry.SIPCallStarted(ctx, req.CallInfo) + case livekit.SIPCallStatus_SIP_CALL_STATUS_DISCONNECTED: + s.telemetry.SIPCallEnded(ctx, req.CallInfo) + } + + return &emptypb.Empty{}, nil +} diff --git a/pkg/telemetry/events.go b/pkg/telemetry/events.go index 7c1d7928a..fe26d2716 100644 --- a/pkg/telemetry/events.go +++ b/pkg/telemetry/events.go @@ -544,9 +544,9 @@ func (t *telemetryService) SIPParticipantCreated(ctx context.Context, sipCall *l }) } -func (t *telemetryService) SIPCallAccepted(ctx context.Context, sipCall *livekit.SIPCallInfo) { +func (t *telemetryService) SIPCallIncoming(ctx context.Context, sipCall *livekit.SIPCallInfo) { t.enqueue(func() { - t.SendEvent(ctx, newSIPCallEvent(livekit.AnalyticsEventType_SIP_CALL_ACCEPTED, sipCall)) + t.SendEvent(ctx, newSIPCallEvent(livekit.AnalyticsEventType_SIP_CALL_INCOMING, sipCall)) }) } diff --git a/pkg/telemetry/telemetryservice.go b/pkg/telemetry/telemetryservice.go index c63ba2b96..ff282178a 100644 --- a/pkg/telemetry/telemetryservice.go +++ b/pkg/telemetry/telemetryservice.go @@ -82,7 +82,7 @@ type TelemetryService interface { SIPDispatchRuleCreated(ctx context.Context, dispatchRule *livekit.SIPDispatchRuleInfo) SIPDispatchRuleDeleted(ctx context.Context, dispatchRule *livekit.SIPDispatchRuleInfo) SIPParticipantCreated(ctx context.Context, sipCall *livekit.SIPCallInfo) - SIPCallAccepted(ctx context.Context, sipCall *livekit.SIPCallInfo) + SIPCallIncoming(ctx context.Context, sipCall *livekit.SIPCallInfo) SIPCallStarted(ctx context.Context, sipCall *livekit.SIPCallInfo) SIPCallEnded(ctx context.Context, sipCall *livekit.SIPCallInfo)