Delete v2 signalling (#3835)
* Delete v2 signalling * deps * mage generate * deelte unused file
This commit is contained in:
@@ -34,7 +34,6 @@ import (
|
||||
"github.com/livekit/protocol/observability"
|
||||
"github.com/livekit/protocol/observability/roomobs"
|
||||
"github.com/livekit/protocol/rpc"
|
||||
"github.com/livekit/protocol/signalling"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/livekit/protocol/utils/guid"
|
||||
"github.com/livekit/protocol/utils/must"
|
||||
@@ -566,241 +565,6 @@ func (r *RoomManager) StartSession(
|
||||
return nil
|
||||
}
|
||||
|
||||
// SIGNALLING-V2-TODO: consolidate common parts beteen this and `StartSession`
|
||||
func (r *RoomManager) HandleConnect(
|
||||
ctx context.Context,
|
||||
grants *auth.ClaimGrants,
|
||||
createRoom *livekit.CreateRoomRequest,
|
||||
wireMessage *livekit.Signalv2WireMessage, // contains livekit.ConnectRequest
|
||||
) (*livekit.Signalv2WireMessage, error) {
|
||||
sessionStartTime := time.Now()
|
||||
|
||||
// find connect request in wire message
|
||||
connectRequest := signalling.GetConnectRequest(wireMessage)
|
||||
if connectRequest == nil {
|
||||
return nil, ErrNoConnectRequest
|
||||
}
|
||||
|
||||
room, err := r.getOrCreateRoom(ctx, createRoom)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer room.Release()
|
||||
|
||||
protoRoom, roomInternal := room.ToProto(), room.Internal()
|
||||
|
||||
participantIdentity := livekit.ParticipantIdentity(grants.Identity)
|
||||
|
||||
// should not error out, error is logged in iceServersForParticipant even if it fails
|
||||
// since this is used for TURN server credentials, we don't want to fail the request even if there's no TURN for the session
|
||||
apiKey, _, _ := r.getFirstKeyPair()
|
||||
|
||||
/* SIGNALLING-V2-TODO - v2 should not have ICERestart, but leaving reminder here (similar location as `StartSession` code check on this path */
|
||||
|
||||
sid := livekit.ParticipantID(guid.New(utils.ParticipantPrefix))
|
||||
pLogger := rtc.LoggerWithParticipant(
|
||||
rtc.LoggerWithRoom(logger.GetLogger(), room.Name(), room.ID()),
|
||||
participantIdentity,
|
||||
sid,
|
||||
false,
|
||||
)
|
||||
pLogger.Infow(
|
||||
"starting RTC session",
|
||||
"room", room.Name(),
|
||||
"nodeID", r.currentNode.NodeID(),
|
||||
"numParticipants", room.GetParticipantCount(),
|
||||
"grants", grants,
|
||||
"createRoom", logger.Proto(createRoom),
|
||||
"wireMessage", logger.Proto(wireMessage),
|
||||
)
|
||||
|
||||
clientInfo := connectRequest.ClientInfo
|
||||
clientConf := r.clientConfManager.GetConfiguration(clientInfo)
|
||||
|
||||
rtcConf := *r.rtcConfig
|
||||
rtcConf.SetBufferFactory(room.GetBufferFactory())
|
||||
if connectRequest.ConnectionSettings.DisableIceLite {
|
||||
rtcConf.SettingEngine.SetLite(false)
|
||||
}
|
||||
|
||||
// default allow forceTCP
|
||||
allowFallback := true
|
||||
if r.config.RTC.AllowTCPFallback != nil {
|
||||
allowFallback = *r.config.RTC.AllowTCPFallback
|
||||
}
|
||||
|
||||
// default do not force full reconnect on a publication error
|
||||
reconnectOnPublicationError := false
|
||||
if r.config.RTC.ReconnectOnPublicationError != nil {
|
||||
reconnectOnPublicationError = *r.config.RTC.ReconnectOnPublicationError
|
||||
}
|
||||
|
||||
// default do not force full reconnect on a subscription error
|
||||
reconnectOnSubscriptionError := false
|
||||
if r.config.RTC.ReconnectOnSubscriptionError != nil {
|
||||
reconnectOnSubscriptionError = *r.config.RTC.ReconnectOnSubscriptionError
|
||||
}
|
||||
|
||||
// default do not force full reconnect on a data channel error
|
||||
reconnectOnDataChannelError := false
|
||||
if r.config.RTC.ReconnectOnDataChannelError != nil {
|
||||
reconnectOnDataChannelError = *r.config.RTC.ReconnectOnDataChannelError
|
||||
}
|
||||
|
||||
subscriberAllowPause := r.config.RTC.CongestionControl.AllowPause
|
||||
if connectRequest.ConnectionSettings.SubscriberAllowPause != nil {
|
||||
subscriberAllowPause = *connectRequest.ConnectionSettings.SubscriberAllowPause
|
||||
}
|
||||
|
||||
participant, err := rtc.NewParticipant(rtc.ParticipantParams{
|
||||
Identity: participantIdentity,
|
||||
Name: livekit.ParticipantName(grants.Name),
|
||||
SID: sid,
|
||||
Config: &rtcConf,
|
||||
AudioConfig: r.config.Audio,
|
||||
VideoConfig: r.config.Video,
|
||||
LimitConfig: r.config.Limit,
|
||||
ProtocolVersion: types.ProtocolVersion(clientInfo.Protocol),
|
||||
SessionStartTime: sessionStartTime,
|
||||
Telemetry: r.telemetry,
|
||||
Trailer: room.Trailer(),
|
||||
PLIThrottleConfig: r.config.RTC.PLIThrottle,
|
||||
CongestionControlConfig: r.config.RTC.CongestionControl,
|
||||
PublishEnabledCodecs: protoRoom.EnabledCodecs,
|
||||
SubscribeEnabledCodecs: protoRoom.EnabledCodecs,
|
||||
Grants: grants,
|
||||
Logger: pLogger,
|
||||
Reporter: roomobs.NewNoopParticipantSessionReporter(),
|
||||
ClientConf: clientConf,
|
||||
ClientInfo: rtc.ClientInfo{ClientInfo: clientInfo},
|
||||
// SIGNALLING-V@-TODO Region: pi.Region,
|
||||
AdaptiveStream: connectRequest.ConnectionSettings.AdaptiveStream,
|
||||
AllowTCPFallback: allowFallback,
|
||||
TURNSEnabled: r.config.IsTURNSEnabled(),
|
||||
ParticipantHelper: &roomManagerParticipantHelper{
|
||||
room: room,
|
||||
codecRegressionThreshold: r.config.Video.CodecRegressionThreshold,
|
||||
},
|
||||
ReconnectOnPublicationError: reconnectOnPublicationError,
|
||||
ReconnectOnSubscriptionError: reconnectOnSubscriptionError,
|
||||
ReconnectOnDataChannelError: reconnectOnDataChannelError,
|
||||
VersionGenerator: r.versionGenerator,
|
||||
SubscriberAllowPause: subscriberAllowPause,
|
||||
SubscriptionLimitAudio: r.config.Limit.SubscriptionLimitAudio,
|
||||
SubscriptionLimitVideo: r.config.Limit.SubscriptionLimitVideo,
|
||||
PlayoutDelay: roomInternal.GetPlayoutDelay(),
|
||||
SyncStreams: roomInternal.GetSyncStreams(),
|
||||
ForwardStats: r.forwardStats,
|
||||
MetricConfig: r.config.Metric,
|
||||
DataChannelMaxBufferedAmount: r.config.RTC.DataChannelMaxBufferedAmount,
|
||||
DatachannelSlowThreshold: r.config.RTC.DatachannelSlowThreshold,
|
||||
FireOnTrackBySdp: true,
|
||||
SynchronousLocalCandidatesMode: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iceConfig := r.setIceConfig(room.Name(), participant)
|
||||
|
||||
// join room
|
||||
opts := rtc.ParticipantOptions{
|
||||
AutoSubscribe: connectRequest.ConnectionSettings.AutoSubscribe,
|
||||
}
|
||||
iceServers := r.iceServersForParticipant(
|
||||
apiKey,
|
||||
participant,
|
||||
iceConfig.PreferenceSubscriber == livekit.ICECandidateType_ICT_TLS,
|
||||
)
|
||||
if err := room.Joinv2(participant, &opts, iceServers); err != nil {
|
||||
pLogger.Errorw("could not join room", err)
|
||||
_ = participant.Close(true, types.ParticipantCloseReasonJoinFailed, false)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// SIGNALLING-V2-TODO: process messages other than ConnecRequest in envelope.
|
||||
|
||||
var wireMessageResponse *livekit.Signalv2WireMessage
|
||||
if pending := participant.SignalPendingMessages(); pending != nil {
|
||||
var ok bool
|
||||
if wireMessageResponse, ok = pending.(*livekit.Signalv2WireMessage); !ok {
|
||||
pLogger.Errorw("could not join room", ErrInvalidMessageType)
|
||||
_ = participant.Close(true, types.ParticipantCloseReasonJoinFailed, false)
|
||||
return nil, ErrInvalidMessageType
|
||||
}
|
||||
}
|
||||
if signalling.GetConnectResponse(wireMessageResponse) == nil {
|
||||
pLogger.Errorw("could not join room", ErrNoConnectResponse)
|
||||
_ = participant.Close(true, types.ParticipantCloseReasonJoinFailed, false)
|
||||
return nil, ErrNoConnectResponse
|
||||
}
|
||||
|
||||
var participantServerClosers utils.Closers
|
||||
participantTopic := rpc.FormatParticipantTopic(room.Name(), participant.Identity())
|
||||
participantServer := must.Get(rpc.NewTypedParticipantServer(r, r.bus))
|
||||
participantServerClosers = append(participantServerClosers, utils.CloseFunc(r.participantServers.Replace(participantTopic, participantServer)))
|
||||
if err := participantServer.RegisterAllParticipantTopics(participantTopic); err != nil {
|
||||
participantServerClosers.Close()
|
||||
pLogger.Errorw("could not join register participant topic", err)
|
||||
_ = participant.Close(true, types.ParticipantCloseReasonMessageBusFailed, false)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
httpSignalParticipantServer := must.Get(rpc.NewTypedSignalv2ParticipantServer(signalv2ParticipantService{r}, r.bus))
|
||||
participantServerClosers = append(
|
||||
participantServerClosers,
|
||||
utils.CloseFunc(r.httpSignalParticipantServers.Replace(participantTopic, httpSignalParticipantServer)),
|
||||
)
|
||||
if err := httpSignalParticipantServer.RegisterAllCommonTopics(participantTopic); err != nil {
|
||||
participantServerClosers.Close()
|
||||
pLogger.Errorw("could not join register participant topic for http signalling", err)
|
||||
_ = participant.Close(true, types.ParticipantCloseReasonMessageBusFailed, false)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = r.roomStore.StoreParticipant(ctx, room.Name(), participant.ToProto()); err != nil {
|
||||
pLogger.Errorw("could not store participant", err)
|
||||
}
|
||||
|
||||
persistRoomForParticipantCount := func(proto *livekit.Room) {
|
||||
if !participant.Hidden() && !room.IsClosed() {
|
||||
err = r.roomStore.StoreRoom(ctx, proto, room.Internal())
|
||||
if err != nil {
|
||||
logger.Errorw("could not store room", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update room store with new numParticipants
|
||||
persistRoomForParticipantCount(room.ToProto())
|
||||
|
||||
clientMeta := &livekit.AnalyticsClientMeta{
|
||||
Region: r.currentNode.Region(),
|
||||
Node: string(r.currentNode.NodeID()),
|
||||
}
|
||||
r.telemetry.ParticipantJoined(ctx, protoRoom, participant.ToProto(), clientInfo, clientMeta, true)
|
||||
participant.OnClose(func(p types.LocalParticipant) {
|
||||
if err := r.roomStore.DeleteParticipant(ctx, room.Name(), p.Identity()); err != nil {
|
||||
pLogger.Errorw("could not delete participant", err)
|
||||
}
|
||||
|
||||
// update room store with new numParticipants
|
||||
proto := room.ToProto()
|
||||
persistRoomForParticipantCount(proto)
|
||||
r.telemetry.ParticipantLeft(ctx, proto, p.ToProto(), true)
|
||||
})
|
||||
participant.OnClaimsChanged(func(participant types.LocalParticipant) {
|
||||
pLogger.Debugw("refreshing client token after claims change")
|
||||
if err := r.refreshToken(participant); err != nil {
|
||||
pLogger.Errorw("could not refresh token", err)
|
||||
}
|
||||
})
|
||||
participant.OnICEConfigChanged(func(participant types.LocalParticipant, iceConfig *livekit.ICEConfig) {
|
||||
r.iceConfigCache.Put(iceConfigCacheKey{room.Name(), participant.Identity()}, iceConfig)
|
||||
})
|
||||
|
||||
return wireMessageResponse, nil
|
||||
}
|
||||
|
||||
// create the actual room object, to be used on RTC node
|
||||
func (r *RoomManager) getOrCreateRoom(ctx context.Context, createRoom *livekit.CreateRoomRequest) (*rtc.Room, error) {
|
||||
roomName := livekit.RoomName(createRoom.Name)
|
||||
|
||||
Reference in New Issue
Block a user