@@ -397,7 +397,9 @@ func (c *outboundCall) connectMedia() {
397397 c .media .HandleDTMF (c .handleDTMF )
398398}
399399
400- func sipResponse (ctx context.Context , tx sip.ClientTransaction , stop <- chan struct {}, setState func (code sip.StatusCode )) (* sip.Response , error ) {
400+ type sipRespFunc func (code sip.StatusCode , hdrs Headers )
401+
402+ func sipResponse (ctx context.Context , tx sip.ClientTransaction , stop <- chan struct {}, setState sipRespFunc ) (* sip.Response , error ) {
401403 cnt := 0
402404 for {
403405 select {
@@ -411,12 +413,12 @@ func sipResponse(ctx context.Context, tx sip.ClientTransaction, stop <-chan stru
411413 return nil , psrpc .NewErrorf (psrpc .Canceled , "transaction failed to complete (%d intermediate responses)" , cnt )
412414 case res := <- tx .Responses ():
413415 status := res .StatusCode
416+ if setState != nil {
417+ setState (res .StatusCode , res .Headers ())
418+ }
414419 if status / 100 != 1 { // != 1xx
415420 return res , nil
416421 }
417- if setState != nil {
418- setState (res .StatusCode )
419- }
420422 // continue
421423 cnt ++
422424 }
@@ -442,6 +444,18 @@ func (c *outboundCall) setStatus(v CallStatus) {
442444 })
443445}
444446
447+ func (c * outboundCall ) setExtraAttrs (hdrToAttr map [string ]string , opts livekit.SIPHeaderOptions , cc Signaling , hdrs Headers ) {
448+ extra := HeadersToAttrs (nil , hdrToAttr , opts , cc , hdrs )
449+ if c .lkRoom != nil && len (extra ) != 0 {
450+ room := c .lkRoom .Room ()
451+ if room != nil {
452+ room .LocalParticipant .SetAttributes (extra )
453+ } else {
454+ c .log .Warnw ("could not set attributes on nil room" , nil , "attrs" , extra )
455+ }
456+ }
457+ }
458+
445459func (c * outboundCall ) sipSignal (ctx context.Context ) error {
446460 ctx , span := tracer .Start (ctx , "outboundCall.sipSignal" )
447461 defer span .End ()
@@ -479,11 +493,15 @@ func (c *outboundCall) sipSignal(ctx context.Context) error {
479493 toUri := CreateURIFromUserAndAddress (c .sipConf .to , c .sipConf .address , TransportFrom (c .sipConf .transport ))
480494
481495 ringing := false
482- sdpResp , err := c .cc .Invite (ctx , toUri , c .sipConf .user , c .sipConf .pass , c .sipConf .headers , sdpOfferData , func (code sip.StatusCode ) {
483- if ! ringing && code >= sip .StatusRinging {
496+ sdpResp , err := c .cc .Invite (ctx , toUri , c .sipConf .user , c .sipConf .pass , c .sipConf .headers , sdpOfferData , func (code sip.StatusCode , hdrs Headers ) {
497+ if code == sip .StatusOK {
498+ return // is set separately
499+ }
500+ if ! ringing && code >= sip .StatusRinging && code < sip .StatusOK {
484501 ringing = true
485502 c .setStatus (CallRinging )
486503 }
504+ c .setExtraAttrs (nil , 0 , nil , hdrs )
487505 })
488506 if err != nil {
489507 // TODO: should we retry? maybe new offer will work
@@ -526,15 +544,7 @@ func (c *outboundCall) sipSignal(ctx context.Context) error {
526544 }
527545 joinDur ()
528546
529- extra := HeadersToAttrs (nil , c .sipConf .headersToAttrs , c .sipConf .includeHeaders , c .cc )
530- if c .lkRoom != nil && len (extra ) != 0 {
531- room := c .lkRoom .Room ()
532- if room != nil {
533- room .LocalParticipant .SetAttributes (extra )
534- } else {
535- c .log .Warnw ("could not set attributes on nil room" , nil , "attrs" , extra )
536- }
537- }
547+ c .setExtraAttrs (c .sipConf .headersToAttrs , c .sipConf .includeHeaders , c .cc , nil )
538548 c .state .DeferUpdate (func (info * livekit.SIPCallInfo ) {
539549 info .AudioCodec = mc .Audio .Codec .Info ().SDPName
540550 if r := c .lkRoom .Room (); r != nil {
@@ -684,7 +694,7 @@ func (c *sipOutbound) RemoteHeaders() Headers {
684694 return c .inviteOk .Headers ()
685695}
686696
687- func (c * sipOutbound ) Invite (ctx context.Context , to URI , user , pass string , headers map [string ]string , sdpOffer []byte , setState func ( code sip. StatusCode ) ) ([]byte , error ) {
697+ func (c * sipOutbound ) Invite (ctx context.Context , to URI , user , pass string , headers map [string ]string , sdpOffer []byte , setState sipRespFunc ) ([]byte , error ) {
688698 ctx , span := tracer .Start (ctx , "sipOutbound.Invite" )
689699 defer span .End ()
690700 c .mu .Lock ()
@@ -814,7 +824,7 @@ func (c *sipOutbound) AckInviteOK(ctx context.Context) error {
814824 return c .c .sipCli .WriteRequest (sip .NewAckRequest (c .invite , c .inviteOk , nil ))
815825}
816826
817- func (c * sipOutbound ) attemptInvite (ctx context.Context , callID sip.CallIDHeader , dest string , to * sip.ToHeader , offer []byte , authHeaderName , authHeader string , headers Headers , setState func ( code sip. StatusCode ) ) (* sip.Request , * sip.Response , error ) {
827+ func (c * sipOutbound ) attemptInvite (ctx context.Context , callID sip.CallIDHeader , dest string , to * sip.ToHeader , offer []byte , authHeaderName , authHeader string , headers Headers , setState sipRespFunc ) (* sip.Request , * sip.Response , error ) {
818828 ctx , span := tracer .Start (ctx , "sipOutbound.attemptInvite" )
819829 defer span .End ()
820830 req := sip .NewRequest (sip .INVITE , to .Address )
0 commit comments