refactor sip create participant (#2949)
This commit is contained in:
+30
-21
@@ -300,28 +300,18 @@ func (s *SIPService) DeleteSIPDispatchRule(ctx context.Context, req *livekit.Del
|
|||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SIPService) CreateSIPParticipantWithToken(ctx context.Context, req *livekit.CreateSIPParticipantRequest, wsUrl, token string) (*livekit.SIPParticipantInfo, error) {
|
func (s *SIPService) CreateSIPParticipant(ctx context.Context, req *livekit.CreateSIPParticipantRequest) (*livekit.SIPParticipantInfo, error) {
|
||||||
if err := EnsureSIPCallPermission(ctx); err != nil {
|
log := logger.GetLogger().WithValues("roomName", req.RoomName, "sipTrunk", req.SipTrunkId, "toUser", req.SipCallTo)
|
||||||
return nil, twirpAuthError(err)
|
ireq, err := s.CreateSIPParticipantRequest(ctx, req, "", "")
|
||||||
}
|
|
||||||
if s.store == nil {
|
|
||||||
return nil, ErrSIPNotConnected
|
|
||||||
}
|
|
||||||
callID := sip.NewCallID()
|
|
||||||
log := logger.GetLogger()
|
|
||||||
log = log.WithValues("callId", callID, "roomName", req.RoomName, "sipTrunk", req.SipTrunkId, "toUser", req.SipCallTo)
|
|
||||||
|
|
||||||
trunk, err := s.store.LoadSIPOutboundTrunk(ctx, req.SipTrunkId)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorw("cannot get trunk to update sip participant", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ireq, err := rpc.NewCreateSIPParticipantRequest(callID, wsUrl, token, req, trunk)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorw("cannot create sip participant request", err)
|
log.Errorw("cannot create sip participant request", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log = log.WithValues("fromUser", ireq.Number, "toHost", trunk.Address)
|
log = log.WithValues(
|
||||||
|
"callId", ireq.SipCallId,
|
||||||
|
"fromUser", ireq.Number,
|
||||||
|
"toHost", ireq.Address,
|
||||||
|
)
|
||||||
|
|
||||||
// CreateSIPParticipant will wait for LiveKit Participant to be created and that can take some time.
|
// CreateSIPParticipant will wait for LiveKit Participant to be created and that can take some time.
|
||||||
// Thus, we must set a higher deadline for it, if it's not set already.
|
// Thus, we must set a higher deadline for it, if it's not set already.
|
||||||
@@ -343,9 +333,28 @@ func (s *SIPService) CreateSIPParticipantWithToken(ctx context.Context, req *liv
|
|||||||
ParticipantId: resp.ParticipantId,
|
ParticipantId: resp.ParticipantId,
|
||||||
ParticipantIdentity: resp.ParticipantIdentity,
|
ParticipantIdentity: resp.ParticipantIdentity,
|
||||||
RoomName: req.RoomName,
|
RoomName: req.RoomName,
|
||||||
SipCallId: callID,
|
SipCallId: ireq.SipCallId,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
func (s *SIPService) CreateSIPParticipant(ctx context.Context, req *livekit.CreateSIPParticipantRequest) (*livekit.SIPParticipantInfo, error) {
|
|
||||||
return s.CreateSIPParticipantWithToken(ctx, req, "", "")
|
func (s *SIPService) CreateSIPParticipantRequest(ctx context.Context, req *livekit.CreateSIPParticipantRequest, wsUrl, token string) (*rpc.InternalCreateSIPParticipantRequest, error) {
|
||||||
|
if err := EnsureSIPCallPermission(ctx); err != nil {
|
||||||
|
return nil, twirpAuthError(err)
|
||||||
|
}
|
||||||
|
if s.store == nil {
|
||||||
|
return nil, ErrSIPNotConnected
|
||||||
|
}
|
||||||
|
callID := sip.NewCallID()
|
||||||
|
|
||||||
|
trunk, err := s.store.LoadSIPOutboundTrunk(ctx, req.SipTrunkId)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorw("cannot get trunk to update sip participant", err,
|
||||||
|
"callId", callID,
|
||||||
|
"roomName", req.RoomName,
|
||||||
|
"sipTrunk", req.SipTrunkId,
|
||||||
|
"toUser", req.SipCallTo,
|
||||||
|
)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return rpc.NewCreateSIPParticipantRequest(callID, wsUrl, token, req, trunk)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user