From a4f2591acb4847ab1661806c340377cecec745ef Mon Sep 17 00:00:00 2001 From: Serhiy Date: Wed, 10 Sep 2025 12:09:36 +0300 Subject: [PATCH 1/2] Add AttrSIPTrunkHostName for SIP trunk host identification --- livekit/attrs.go | 3 ++- rpc/sip.go | 1 + rpc/sip_test.go | 13 +++++++------ sip/sip.go | 1 + sip/sip_test.go | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/livekit/attrs.go b/livekit/attrs.go index 0b8b578e9..da0762140 100644 --- a/livekit/attrs.go +++ b/livekit/attrs.go @@ -12,7 +12,8 @@ const ( AttrSIPDispatchRuleID = AttrSIPPrefix + "ruleID" // AttrSIPTrunkNumber attribute contains number associate with LiveKit SIP Trunk. // This attribute will be omitted if HidePhoneNumber is set. - AttrSIPTrunkNumber = AttrSIPPrefix + "trunkPhoneNumber" + AttrSIPTrunkNumber = AttrSIPPrefix + "trunkPhoneNumber" + AttrSIPTrunkHostName = AttrSIPPrefix + "trunkHostName" // AttrSIPPhoneNumber attribute contains number external to LiveKit SIP (caller for inbound and called number for outbound). // This attribute will be omitted if HidePhoneNumber is set. AttrSIPPhoneNumber = AttrSIPPrefix + "phoneNumber" diff --git a/rpc/sip.go b/rpc/sip.go index 4011d1431..7d75eebb9 100644 --- a/rpc/sip.go +++ b/rpc/sip.go @@ -133,6 +133,7 @@ func NewCreateSIPParticipantRequest( attrs[livekit.AttrSIPPhoneNumber] = req.SipCallTo attrs[livekit.AttrSIPHostName] = hostname attrs[livekit.AttrSIPTrunkNumber] = outboundNumber + attrs[livekit.AttrSIPTrunkHostName] = ownHostname } var features []livekit.SIPFeature diff --git a/rpc/sip_test.go b/rpc/sip_test.go index aa49f32e8..70340ceea 100644 --- a/rpc/sip_test.go +++ b/rpc/sip_test.go @@ -57,12 +57,13 @@ func TestNewCreateSIPParticipantRequest(t *testing.T) { Dtmf: "1234#", PlayDialtone: true, ParticipantAttributes: map[string]string{ - "extra": "1", - livekit.AttrSIPCallID: "call-id", - livekit.AttrSIPTrunkID: "trunk", - livekit.AttrSIPTrunkNumber: "+1111", - livekit.AttrSIPPhoneNumber: "+3333", - livekit.AttrSIPHostName: "sip.example.com", + "extra": "1", + livekit.AttrSIPCallID: "call-id", + livekit.AttrSIPTrunkID: "trunk", + livekit.AttrSIPTrunkNumber: "+1111", + livekit.AttrSIPTrunkHostName: "sip2.example.com", + livekit.AttrSIPPhoneNumber: "+3333", + livekit.AttrSIPHostName: "sip.example.com", }, Headers: map[string]string{ "X-A": "A", diff --git a/sip/sip.go b/sip/sip.go index 0daa50792..3c7aad4bd 100644 --- a/sip/sip.go +++ b/sip/sip.go @@ -831,6 +831,7 @@ func EvaluateDispatchRule(projectID string, trunk *livekit.SIPInboundTrunkInfo, attrs[livekit.AttrSIPPhoneNumber] = call.From.User attrs[livekit.AttrSIPHostName] = call.From.Host attrs[livekit.AttrSIPTrunkNumber] = call.To.User + attrs[livekit.AttrSIPTrunkHostName] = call.To.Host } room, rulePin, err := GetPinAndRoom(rule) diff --git a/sip/sip_test.go b/sip/sip_test.go index 196fa3110..ae8f22be6 100644 --- a/sip/sip_test.go +++ b/sip/sip_test.go @@ -673,6 +673,7 @@ func TestEvaluateDispatchRule(t *testing.T) { livekit.AttrSIPDispatchRuleID: "rule", livekit.AttrSIPPhoneNumber: "+11112222", livekit.AttrSIPTrunkNumber: "+3333", + livekit.AttrSIPTrunkHostName: "sip2.example.com", livekit.AttrSIPHostName: "sip.example.com", }, }, res) From 65d1614cedc1ba625122ebe630b0b577f5eaf332 Mon Sep 17 00:00:00 2001 From: Serhiy Date: Wed, 10 Sep 2025 12:46:00 +0300 Subject: [PATCH 2/2] Fix SIP trunk host name in tests and update attribute comments --- livekit/attrs.go | 4 +++- rpc/sip_test.go | 2 +- sip/sip_test.go | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/livekit/attrs.go b/livekit/attrs.go index da0762140..fa999003d 100644 --- a/livekit/attrs.go +++ b/livekit/attrs.go @@ -12,7 +12,9 @@ const ( AttrSIPDispatchRuleID = AttrSIPPrefix + "ruleID" // AttrSIPTrunkNumber attribute contains number associate with LiveKit SIP Trunk. // This attribute will be omitted if HidePhoneNumber is set. - AttrSIPTrunkNumber = AttrSIPPrefix + "trunkPhoneNumber" + AttrSIPTrunkNumber = AttrSIPPrefix + "trunkPhoneNumber" + // AttrSIPTrunkHostName attribute contains host name associate with LiveKit SIP Trunk. + // This attribute will be omitted if HidePhoneNumber is set. AttrSIPTrunkHostName = AttrSIPPrefix + "trunkHostName" // AttrSIPPhoneNumber attribute contains number external to LiveKit SIP (caller for inbound and called number for outbound). // This attribute will be omitted if HidePhoneNumber is set. diff --git a/rpc/sip_test.go b/rpc/sip_test.go index 70340ceea..c3f6d8a88 100644 --- a/rpc/sip_test.go +++ b/rpc/sip_test.go @@ -61,7 +61,7 @@ func TestNewCreateSIPParticipantRequest(t *testing.T) { livekit.AttrSIPCallID: "call-id", livekit.AttrSIPTrunkID: "trunk", livekit.AttrSIPTrunkNumber: "+1111", - livekit.AttrSIPTrunkHostName: "sip2.example.com", + livekit.AttrSIPTrunkHostName: "xyz.sip.livekit.cloud", livekit.AttrSIPPhoneNumber: "+3333", livekit.AttrSIPHostName: "sip.example.com", }, diff --git a/sip/sip_test.go b/sip/sip_test.go index ae8f22be6..56ebebded 100644 --- a/sip/sip_test.go +++ b/sip/sip_test.go @@ -649,11 +649,14 @@ func TestEvaluateDispatchRule(t *testing.T) { CallingNumber: "+11112222", CallingHost: "sip.example.com", CalledNumber: "+3333", + CalledHost: "sip2.example.com", ExtraAttributes: map[string]string{ "prov-attr": "1", }, } - tr := &livekit.SIPInboundTrunkInfo{SipTrunkId: "trunk"} + tr := &livekit.SIPInboundTrunkInfo{ + SipTrunkId: "trunk", + } res, err := EvaluateDispatchRule("p_123", tr, d, r) require.NoError(t, err) require.Equal(t, &rpc.EvaluateSIPDispatchRulesResponse{