@@ -57,7 +57,7 @@ func expectNoResponse(t *testing.T, tx sip.ClientTransaction) {
5757type TestHandler struct {
5858 GetAuthCredentialsFunc func (ctx context.Context , call * rpc.SIPCall ) (AuthInfo , error )
5959 DispatchCallFunc func (ctx context.Context , info * CallInfo ) CallDispatch
60- OnCallEndFunc func (ctx context.Context , callInfo * livekit.SIPCallInfo , reason string )
60+ OnSessionEndFunc func (ctx context.Context , callIdentifier * CallIdentifier , callInfo * livekit.SIPCallInfo , reason string )
6161}
6262
6363func (h TestHandler ) GetAuthCredentials (ctx context.Context , call * rpc.SIPCall ) (AuthInfo , error ) {
@@ -81,9 +81,9 @@ func (h TestHandler) DeregisterTransferSIPParticipantTopic(sipCallId string) {
8181 // no-op
8282}
8383
84- func (h TestHandler ) OnCallEnd (ctx context.Context , callInfo * livekit.SIPCallInfo , reason string ) {
85- if h .OnCallEndFunc != nil {
86- h .OnCallEndFunc (ctx , callInfo , reason )
84+ func (h TestHandler ) OnSessionEnd (ctx context.Context , callIdentifier * CallIdentifier , callInfo * livekit.SIPCallInfo , reason string ) {
85+ if h .OnSessionEndFunc != nil {
86+ h .OnSessionEndFunc (ctx , callIdentifier , callInfo , reason )
8787 }
8888}
8989
@@ -177,13 +177,16 @@ func TestService_AuthDrop(t *testing.T) {
177177 })
178178}
179179
180- func TestService_OnCallEnd (t * testing.T ) {
180+ func TestService_OnSessionEnd (t * testing.T ) {
181181 const (
182- expectedCallID = "test-call-id"
183- expectedReason = "test-reason"
182+ expectedCallID = "test-call-id"
183+ expectedSipCallID = "test-sip-call-id"
184+ expectedProjectID = "test-project"
185+ expectedReason = "test-reason"
184186 )
185187
186188 callEnded := make (chan struct {})
189+ var receivedCallIdentifier * CallIdentifier
187190 var receivedCallInfo * livekit.SIPCallInfo
188191 var receivedReason string
189192
@@ -202,7 +205,8 @@ func TestService_OnCallEnd(t *testing.T) {
202205 },
203206 }
204207 },
205- OnCallEndFunc : func (ctx context.Context , callInfo * livekit.SIPCallInfo , reason string ) {
208+ OnSessionEndFunc : func (ctx context.Context , callIdentifier * CallIdentifier , callInfo * livekit.SIPCallInfo , reason string ) {
209+ receivedCallIdentifier = callIdentifier
206210 receivedCallInfo = callInfo
207211 receivedReason = reason
208212 close (callEnded )
@@ -228,21 +232,37 @@ func TestService_OnCallEnd(t *testing.T) {
228232 s .SetHandler (h )
229233 require .NoError (t , s .Start ())
230234
231- // Call OnCallEnd directly
232- h .OnCallEnd (context .Background (), & livekit.SIPCallInfo {
235+ // Call OnSessionEnd directly with test data
236+ h .OnSessionEnd (context .Background (), & CallIdentifier {
237+ ProjectID : expectedProjectID ,
238+ CallID : expectedCallID ,
239+ SipCallID : expectedSipCallID ,
240+ }, & livekit.SIPCallInfo {
233241 CallId : expectedCallID ,
242+ ParticipantAttributes : map [string ]string {
243+ "projectID" : expectedProjectID ,
244+ AttrSIPCallIDFull : expectedSipCallID ,
245+ },
234246 }, expectedReason )
235247
236- // Wait for OnCallEnd to be called
248+ // Wait for OnSessionEnd to be called
237249 select {
238250 case <- callEnded :
239251 // Success
240252 case <- time .After (time .Second ):
241- t .Fatal ("OnCallEnd was not called" )
253+ t .Fatal ("OnSessionEnd was not called" )
242254 }
243255
244- // Verify the parameters passed to OnCallEnd
256+ // Verify the CallIdentifier fields are correctly populated
257+ require .NotNil (t , receivedCallIdentifier , "CallIdentifier should not be nil" )
258+ require .Equal (t , expectedProjectID , receivedCallIdentifier .ProjectID , "CallIdentifier.ProjectID should match" )
259+ require .Equal (t , expectedCallID , receivedCallIdentifier .CallID , "CallIdentifier.CallID should match" )
260+ require .Equal (t , expectedSipCallID , receivedCallIdentifier .SipCallID , "CallIdentifier.SipCallID should match" )
261+
262+ // Verify the CallInfo fields
245263 require .NotNil (t , receivedCallInfo , "CallInfo should not be nil" )
264+ require .Equal (t , expectedProjectID , receivedCallInfo .ParticipantAttributes ["projectID" ], "CallInfo.ParticipantAttributes[projectID] should match" )
246265 require .Equal (t , expectedCallID , receivedCallInfo .CallId , "CallInfo.CallId should match" )
266+ require .Equal (t , expectedSipCallID , receivedCallInfo .ParticipantAttributes [AttrSIPCallIDFull ], "CallInfo.ParticipantAttributes[sip.callIDFull] should match" )
247267 require .Equal (t , expectedReason , receivedReason , "Reason should match" )
248268}
0 commit comments