Skip to content

Commit

Permalink
Do not close the audio stream when REFER fails. (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc authored Jan 24, 2025
1 parent edd55f5 commit 0cc2261
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions pkg/sip/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,10 @@ func (c *inboundCall) transferCall(ctx context.Context, transferTo string, heade
go func() {
aw := c.media.GetAudioWriter()

tones.Play(rctx, aw, ringVolume, tones.ETSIRinging)
aw.Close()
err := tones.Play(rctx, aw, ringVolume, tones.ETSIRinging)
if err != nil && !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) {
c.log.Infow("cannot play dial tone", "error", err)
}
}()
}

Expand All @@ -901,7 +903,7 @@ func (c *inboundCall) transferCall(ctx context.Context, transferTo string, heade
return err
}

c.log.Infow("inbound call tranferred", "transferTo", transferTo)
c.log.Infow("inbound call transferred", "transferTo", transferTo)

// Give time for the peer to hang up first, but hang up ourselves if this doesn't happen within 1 second
time.AfterFunc(referByeTimeout, func() { c.Close() })
Expand Down
10 changes: 6 additions & 4 deletions pkg/sip/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,20 @@ func (c *outboundCall) transferCall(ctx context.Context, transferTo string, head
go func() {
aw := c.media.GetAudioWriter()

tones.Play(rctx, aw, ringVolume, tones.ETSIRinging)
aw.Close()
err := tones.Play(rctx, aw, ringVolume, tones.ETSIRinging)
if err != nil && !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) {
c.log.Infow("cannot play dial tone", "error", err)
}
}()
}

err = c.cc.transferCall(ctx, transferTo, headers)
if err != nil {
c.log.Infow("outound call failed to transfer", "error", err, "transferTo", transferTo)
c.log.Infow("outbound call failed to transfer", "error", err, "transferTo", transferTo)
return err
}

c.log.Infow("outbound call tranferred", "transferTo", transferTo)
c.log.Infow("outbound call transferred", "transferTo", transferTo)

// Give time for the peer to hang up first, but hang up ourselves if this doesn't happen within 1 second
time.AfterFunc(referByeTimeout, func() { c.CloseWithReason(CallHangup, "call transferred", livekit.DisconnectReason_CLIENT_INITIATED) })
Expand Down

0 comments on commit 0cc2261

Please sign in to comment.