starting signaller interface (#3802)
* starting signaller interface * WIP * WIP * WIP * typo * connect response check * WIP * clean up * move signal handling to participant fully * service methods * type assertions for interfaces
This commit is contained in:
+127
-10
@@ -47,6 +47,7 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/metric"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/signalling"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/supervisor"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/transport"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
@@ -280,16 +281,21 @@ type ParticipantImpl struct {
|
||||
version atomic.Uint32
|
||||
|
||||
// callbacks & handlers
|
||||
onTrackPublished func(types.LocalParticipant, types.MediaTrack)
|
||||
onTrackUpdated func(types.LocalParticipant, types.MediaTrack)
|
||||
onTrackUnpublished func(types.LocalParticipant, types.MediaTrack)
|
||||
onStateChange func(p types.LocalParticipant)
|
||||
onSubscriberReady func(p types.LocalParticipant)
|
||||
onMigrateStateChange func(p types.LocalParticipant, migrateState types.MigrateState)
|
||||
onParticipantUpdate func(types.LocalParticipant)
|
||||
onDataPacket func(types.LocalParticipant, livekit.DataPacket_Kind, *livekit.DataPacket)
|
||||
onDataMessage func(types.LocalParticipant, []byte)
|
||||
onMetrics func(types.Participant, *livekit.DataPacket)
|
||||
onTrackPublished func(types.LocalParticipant, types.MediaTrack)
|
||||
onTrackUpdated func(types.LocalParticipant, types.MediaTrack)
|
||||
onTrackUnpublished func(types.LocalParticipant, types.MediaTrack)
|
||||
onStateChange func(p types.LocalParticipant)
|
||||
onSubscriberReady func(p types.LocalParticipant)
|
||||
onMigrateStateChange func(p types.LocalParticipant, migrateState types.MigrateState)
|
||||
onParticipantUpdate func(types.LocalParticipant)
|
||||
onDataPacket func(types.LocalParticipant, livekit.DataPacket_Kind, *livekit.DataPacket)
|
||||
onDataMessage func(types.LocalParticipant, []byte)
|
||||
onMetrics func(types.Participant, *livekit.DataPacket)
|
||||
onUpdateSubscriptions func(types.LocalParticipant, []livekit.TrackID, []*livekit.ParticipantTracks, bool)
|
||||
onUpdateSubscriptionPermission func(types.LocalParticipant, *livekit.SubscriptionPermission) error
|
||||
onSyncState func(types.LocalParticipant, *livekit.SyncState) error
|
||||
onSimulateScenario func(types.LocalParticipant, *livekit.SimulateScenario) error
|
||||
onLeave func(types.LocalParticipant, types.ParticipantCloseReason)
|
||||
|
||||
migrateState atomic.Value // types.MigrateState
|
||||
migratedTracksPublishedFuse core.Fuse
|
||||
@@ -309,6 +315,9 @@ type ParticipantImpl struct {
|
||||
metricsCollector *metric.MetricsCollector
|
||||
metricsReporter *metric.MetricsReporter
|
||||
|
||||
signalling signalling.ParticipantSignalling
|
||||
signaller signalling.ParticipantSignaller
|
||||
|
||||
// loggers for publisher and subscriber
|
||||
pubLogger logger.Logger
|
||||
subLogger logger.Logger
|
||||
@@ -345,6 +354,14 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
joiningMessageLastWrittenSeqs: make(map[livekit.ParticipantID]uint32),
|
||||
},
|
||||
}
|
||||
p.signalling = signalling.NewSignalling(signalling.SignallingParams{
|
||||
Logger: params.Logger,
|
||||
})
|
||||
p.signaller = signalling.NewSignallerAsync(signalling.SignallerAsyncParams{
|
||||
Logger: params.Logger,
|
||||
Participant: p,
|
||||
})
|
||||
|
||||
p.id.Store(params.SID)
|
||||
p.dataChannelStats = telemetry.NewBytesTrackStats(
|
||||
telemetry.BytesTrackIDForParticipantID(telemetry.BytesTrackTypeData, p.ID()),
|
||||
@@ -908,6 +925,66 @@ func (p *ParticipantImpl) getOnMetrics() func(types.Participant, *livekit.DataPa
|
||||
return p.onMetrics
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnUpdateSubscriptions(callback func(types.LocalParticipant, []livekit.TrackID, []*livekit.ParticipantTracks, bool)) {
|
||||
p.lock.Lock()
|
||||
p.onUpdateSubscriptions = callback
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) getOnUpdateSubscriptions() func(types.LocalParticipant, []livekit.TrackID, []*livekit.ParticipantTracks, bool) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return p.onUpdateSubscriptions
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnUpdateSubscriptionPermission(callback func(types.LocalParticipant, *livekit.SubscriptionPermission) error) {
|
||||
p.lock.Lock()
|
||||
p.onUpdateSubscriptionPermission = callback
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) getOnUpdateSubscriptionPermission() func(types.LocalParticipant, *livekit.SubscriptionPermission) error {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return p.onUpdateSubscriptionPermission
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnSyncState(callback func(types.LocalParticipant, *livekit.SyncState) error) {
|
||||
p.lock.Lock()
|
||||
p.onSyncState = callback
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) getOnSyncState() func(types.LocalParticipant, *livekit.SyncState) error {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return p.onSyncState
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnSimulateScenario(callback func(types.LocalParticipant, *livekit.SimulateScenario) error) {
|
||||
p.lock.Lock()
|
||||
p.onSimulateScenario = callback
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) getOnSimulateScenario() func(types.LocalParticipant, *livekit.SimulateScenario) error {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return p.onSimulateScenario
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnLeave(callback func(types.LocalParticipant, types.ParticipantCloseReason)) {
|
||||
p.lock.Lock()
|
||||
p.onLeave = callback
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) getOnLeave() func(types.LocalParticipant, types.ParticipantCloseReason) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return p.onLeave
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnClose(callback func(types.LocalParticipant)) {
|
||||
if p.isClosed.Load() {
|
||||
go callback(p)
|
||||
@@ -3625,3 +3702,43 @@ func (p *ParticipantImpl) GetLastReliableSequence(migrateOut bool) uint32 {
|
||||
}
|
||||
return p.reliableDataInfo.lastPubReliableSeq.Load()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) HandleUpdateSubscriptions(
|
||||
trackIDs []livekit.TrackID,
|
||||
participantTracks []*livekit.ParticipantTracks,
|
||||
subscribe bool,
|
||||
) {
|
||||
if onUpdateSubscriptions := p.getOnUpdateSubscriptions(); onUpdateSubscriptions != nil {
|
||||
onUpdateSubscriptions(p, trackIDs, participantTracks, subscribe)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) HandleUpdateSubscriptionPermission(subscriptionPermission *livekit.SubscriptionPermission) error {
|
||||
if onUpdateSubscriptionPermission := p.getOnUpdateSubscriptionPermission(); onUpdateSubscriptionPermission != nil {
|
||||
return onUpdateSubscriptionPermission(p, subscriptionPermission)
|
||||
}
|
||||
|
||||
return errors.New("no handler")
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) HandleSyncState(syncState *livekit.SyncState) error {
|
||||
if onSyncState := p.getOnSyncState(); onSyncState != nil {
|
||||
return onSyncState(p, syncState)
|
||||
}
|
||||
|
||||
return errors.New("no handler")
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) HandleSimulateScenario(simulateScenario *livekit.SimulateScenario) error {
|
||||
if onSimulateScenario := p.getOnSimulateScenario(); onSimulateScenario != nil {
|
||||
return onSimulateScenario(p, simulateScenario)
|
||||
}
|
||||
|
||||
return errors.New("no handler")
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) HandleLeaveRequest(reason types.ParticipantCloseReason) {
|
||||
if onLeave := p.getOnLeave(); onLeave != nil {
|
||||
onLeave(p, reason)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user