Skip to content

Commit

Permalink
Fix typo and improve logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Nov 29, 2023
1 parent 7f558b9 commit 8ad35d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/sip/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sync"

"github.com/emiago/sipgo"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/rpc"
"golang.org/x/exp/maps"

Expand Down Expand Up @@ -79,12 +80,17 @@ func (c *Client) Stop() error {

func (c *Client) UpdateSIPParticipant(ctx context.Context, req *rpc.InternalUpdateSIPParticipantRequest) (*rpc.InternalUpdateSIPParticipantResponse, error) {
if req.CallTo == "" {
logger.Infow("Disconnect SIP participant",
"roomName", req.RoomName, "participant", req.ParticipantId)
// Disconnect participant
if call := c.getCall(req.ParticipantId); call != nil {
call.Close()
}
return &rpc.InternalUpdateSIPParticipantResponse{}, nil
}
logger.Infow("Updating SIP participant",
"roomName", req.RoomName, "participant", req.ParticipantId,
"from", req.Number, "to", req.CallTo, "address", req.Address)
err := c.getOrCreateCall(req.ParticipantId).Update(ctx, sipOutboundConfig{
address: req.Address,
from: req.Number,
Expand Down
12 changes: 8 additions & 4 deletions pkg/sip/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,28 @@ func (c *outboundCall) Update(ctx context.Context, sipNew sipOutboundConfig, lkN
if c.sipCur == sipNew && c.lkCur == lkNew {
return nil
}
if c.sipCur.address == "" || c.sipCur.to == "" {
if sipNew.address == "" || sipNew.to == "" {
logger.Infow("Shutdown of outbound SIP call",
"roomName", lkNew.roomName, "from", sipNew.from, "to", sipNew.to, "address", sipNew.address)
// shutdown the call
c.close()
return nil
}
if err := c.startMedia(); err != nil {
c.close()
return err
return fmt.Errorf("start media failed: %w", err)
}
if err := c.updateRoom(lkNew); err != nil {
c.close()
return err
return fmt.Errorf("update room failed: %w", err)
}
if err := c.updateSIP(sipNew); err != nil {
c.close()
return err
return fmt.Errorf("update SIP failed: %w", err)
}
c.relinkMedia()
logger.Infow("Outbound SIP update complete",
"roomName", lkNew.roomName, "from", sipNew.from, "to", sipNew.to, "address", sipNew.address)
return nil
}

Expand Down

0 comments on commit 8ad35d7

Please sign in to comment.