Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben committed Oct 29, 2024
1 parent 045e35f commit 1b3d68d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
16 changes: 10 additions & 6 deletions pkg/sip/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ func (c *Client) createSIPParticipant(ctx context.Context, req *rpc.InternalCrea
callInfo.Error = retErr.Error()
}

c.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: callInfo,
})
if c.ioClient != nil {
c.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: callInfo,
})
}
}()

roomConf := RoomConfig{
Expand Down Expand Up @@ -215,9 +217,11 @@ func (c *Client) createSIPParticipant(ctx context.Context, req *rpc.InternalCrea
callInfo.CallStatus = livekit.SIPCallStatus_SCS_DISCONNECTED
}

c.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: callInfo,
})
if c.ioClient != nil {
c.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: callInfo,
})
}

}()

Expand Down
24 changes: 15 additions & 9 deletions pkg/sip/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ func (s *Server) onInvite(req *sip.Request, tx sip.ServerTransaction) {
}
callInfo.EndedAt = time.Now().UnixNano()

s.ioClient.UpdateSIPCallState(context.Background(), &rpc.UpdateSIPCallStateRequest{
CallInfo: callInfo,
})
if s.ioClient != nil {
s.ioClient.UpdateSIPCallState(context.Background(), &rpc.UpdateSIPCallStateRequest{
CallInfo: callInfo,
})
}
}
}

Expand Down Expand Up @@ -166,9 +168,11 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (*liv
CreatedAt: time.Now().UnixNano(),
}

s.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: callInfo,
})
if s.ioClient != nil {
s.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: callInfo,
})
}

if err := cc.ValidateInvite(); err != nil {
if s.conf.HideInboundPort {
Expand Down Expand Up @@ -483,9 +487,11 @@ func (c *inboundCall) handleInvite(ctx context.Context, req *sip.Request, trunkI

c.started.Break()

c.s.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: c.callInfo,
})
if c.s.ioClient != nil {
c.s.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: c.callInfo,
})
}

// Wait for the caller to terminate the call.
select {
Expand Down
8 changes: 5 additions & 3 deletions pkg/sip/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ func (c *outboundCall) Start(ctx context.Context) {
c.callInfo.StartedAt = time.Now().UnixNano()
c.callInfo.CallStatus = livekit.SIPCallStatus_SCS_ACTIVE

c.c.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: c.callInfo,
})
if c.c.ioClient != nil {
c.c.ioClient.UpdateSIPCallState(context.WithoutCancel(ctx), &rpc.UpdateSIPCallStateRequest{
CallInfo: c.callInfo,
})
}

select {
case <-c.Disconnected():
Expand Down
7 changes: 1 addition & 6 deletions pkg/sip/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/rpc"
"github.com/livekit/psrpc"

"github.com/livekit/sip/pkg/media"

Expand Down Expand Up @@ -91,16 +90,12 @@ func testInvite(t *testing.T, h Handler, hidden bool, from, to string, test func
mon, err := stats.NewMonitor(&config.Config{MaxCpuUtilization: 0.9})
require.NoError(t, err)

bus := psrpc.NewLocalMessageBus()
psrpcClient, err := rpc.NewIOInfoClient(bus)
require.NoError(t, err)

s, err := NewService(&config.Config{
HideInboundPort: hidden,
SIPPort: sipPort,
SIPPortListen: sipPort,
RTPPort: rtcconfig.PortRange{Start: testPortRTPMin, End: testPortRTPMax},
}, mon, logger.GetLogger(), psrpcClient)
}, mon, logger.GetLogger(), nil)
require.NoError(t, err)
require.NotNil(t, s)
t.Cleanup(s.Stop)
Expand Down

0 comments on commit 1b3d68d

Please sign in to comment.