Rpcs for ingress proxy WHIP (#3911)

See https://github.com/livekit/protocol/pull/1194
This commit is contained in:
cnderrauber
2025-09-09 22:49:42 +08:00
committed by GitHub
parent 991a4a4f53
commit 76645fad5e
13 changed files with 189 additions and 76 deletions
+40 -4
View File
@@ -5,6 +5,10 @@ import (
"fmt"
"time"
"github.com/pion/webrtc/v4"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/types/known/emptypb"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
@@ -12,13 +16,23 @@ import (
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/rpc"
"github.com/livekit/psrpc"
"github.com/pion/webrtc/v4"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/types/known/emptypb"
)
type whipService struct {
*RoomManager
ingressRpcCli rpc.IngressHandlerClient
}
func newWhipService(rm *RoomManager) (*whipService, error) {
cli, err := rpc.NewIngressHandlerClient(rm.bus, rpc.WithDefaultClientOptions(logger.GetLogger()))
if err != nil {
return nil, err
}
return &whipService{
RoomManager: rm,
ingressRpcCli: cli,
}, nil
}
func (s whipService) Create(ctx context.Context, req *rpc.WHIPCreateRequest) (*rpc.WHIPCreateResponse, error) {
@@ -97,6 +111,21 @@ func (s whipService) Create(ctx context.Context, req *rpc.WHIPCreateRequest) (*r
return nil, err
}
if req.FromIngress {
lp.AddOnClose(types.ParticipantCloseKeyWHIP, func(lp types.LocalParticipant) {
go func() {
lp.GetLogger().Debugw("whip service: notify participant closed")
_, err := s.ingressRpcCli.WHIPRTCConnectionNotify(context.Background(), string(lp.ID()), &rpc.WHIPRTCConnectionNotifyRequest{
ParticipantId: string(lp.ID()),
Closed: true,
}, psrpc.WithRequestTimeout(rpc.DefaultPSRPCConfig.Timeout))
if err != nil {
lp.GetLogger().Warnw("whip service: could not notify ingress of participant closed", err)
}
}()
})
}
var iceServers []*livekit.ICEServer
apiKey, _, err := s.RoomManager.getFirstKeyPair()
if err != nil {
@@ -185,12 +214,19 @@ func (r whipParticipantService) DeleteSession(ctx context.Context, req *rpc.WHIP
return nil, ErrRoomNotFound
}
reason := types.ParticipantCloseReasonClientRequestLeave
lp := room.GetParticipantByID(livekit.ParticipantID(req.ParticipantId))
if lp == nil && req.FromSweeper && req.ParticipantId == "" {
lp = room.GetParticipant(livekit.ParticipantIdentity(req.ParticipantIdentity))
reason = types.ParticipantCloseReasonStale
}
if lp != nil {
lp.AddOnClose(types.ParticipantCloseKeyWHIP, nil)
room.RemoveParticipant(
lp.Identity(),
lp.ID(),
types.ParticipantCloseReasonClientRequestLeave,
reason,
)
}