Use participant and room specific loggers (#252)
This commit is contained in:
@@ -265,8 +265,8 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
|||||||
}
|
}
|
||||||
t.params.Logger.Debugw("removing peerconnection track",
|
t.params.Logger.Debugw("removing peerconnection track",
|
||||||
"track", t.ID(),
|
"track", t.ID(),
|
||||||
"pIDs", []string{t.params.ParticipantID, sub.ID()},
|
"subscriber", sub.Identity(),
|
||||||
"participant", sub.Identity(),
|
"subscriberID", sub.ID(),
|
||||||
"kind", t.Kind(),
|
"kind", t.Kind(),
|
||||||
)
|
)
|
||||||
if err := sub.SubscriberPC().RemoveTrack(sender); err != nil {
|
if err := sub.SubscriberPC().RemoveTrack(sender); err != nil {
|
||||||
@@ -279,7 +279,9 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
|||||||
// been set to Inactive
|
// been set to Inactive
|
||||||
t.params.Logger.Debugw("could not remove remoteTrack from forwarder",
|
t.params.Logger.Debugw("could not remove remoteTrack from forwarder",
|
||||||
"error", err,
|
"error", err,
|
||||||
"participant", sub.Identity(), "pID", sub.ID())
|
"subscriber", sub.Identity(),
|
||||||
|
"subscriberID", sub.ID(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,8 +329,6 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
|||||||
buff, rtcpReader := t.params.BufferFactory.GetBufferPair(uint32(track.SSRC()))
|
buff, rtcpReader := t.params.BufferFactory.GetBufferPair(uint32(track.SSRC()))
|
||||||
if buff == nil || rtcpReader == nil {
|
if buff == nil || rtcpReader == nil {
|
||||||
logger.Errorw("could not retrieve buffer pair", nil,
|
logger.Errorw("could not retrieve buffer pair", nil,
|
||||||
"participant", t.params.ParticipantIdentity,
|
|
||||||
"participantID", t.params.ParticipantID,
|
|
||||||
"track", t.ID())
|
"track", t.ID())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-49
@@ -36,6 +36,7 @@ const (
|
|||||||
|
|
||||||
type ParticipantParams struct {
|
type ParticipantParams struct {
|
||||||
Identity string
|
Identity string
|
||||||
|
SID string
|
||||||
Config *WebRTCConfig
|
Config *WebRTCConfig
|
||||||
Sink routing.MessageSink
|
Sink routing.MessageSink
|
||||||
AudioConfig config.AudioConfig
|
AudioConfig config.AudioConfig
|
||||||
@@ -50,7 +51,6 @@ type ParticipantParams struct {
|
|||||||
|
|
||||||
type ParticipantImpl struct {
|
type ParticipantImpl struct {
|
||||||
params ParticipantParams
|
params ParticipantParams
|
||||||
id string
|
|
||||||
publisher *PCTransport
|
publisher *PCTransport
|
||||||
subscriber *PCTransport
|
subscriber *PCTransport
|
||||||
isClosed utils.AtomicFlag
|
isClosed utils.AtomicFlag
|
||||||
@@ -102,7 +102,6 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
|
|
||||||
p := &ParticipantImpl{
|
p := &ParticipantImpl{
|
||||||
params: params,
|
params: params,
|
||||||
id: utils.NewGuid(utils.ParticipantPrefix),
|
|
||||||
rtcpCh: make(chan []rtcp.Packet, 50),
|
rtcpCh: make(chan []rtcp.Packet, 50),
|
||||||
pliThrottle: newPLIThrottle(params.ThrottleConfig),
|
pliThrottle: newPLIThrottle(params.ThrottleConfig),
|
||||||
subscribedTracks: make(map[string]types.SubscribedTrack),
|
subscribedTracks: make(map[string]types.SubscribedTrack),
|
||||||
@@ -118,7 +117,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.publisher, err = NewPCTransport(TransportParams{
|
p.publisher, err = NewPCTransport(TransportParams{
|
||||||
ParticipantID: p.id,
|
ParticipantID: p.params.SID,
|
||||||
ParticipantIdentity: p.params.Identity,
|
ParticipantIdentity: p.params.Identity,
|
||||||
Target: livekit.SignalTarget_PUBLISHER,
|
Target: livekit.SignalTarget_PUBLISHER,
|
||||||
Config: params.Config,
|
Config: params.Config,
|
||||||
@@ -130,7 +129,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.subscriber, err = NewPCTransport(TransportParams{
|
p.subscriber, err = NewPCTransport(TransportParams{
|
||||||
ParticipantID: p.id,
|
ParticipantID: p.params.SID,
|
||||||
ParticipantIdentity: p.params.Identity,
|
ParticipantIdentity: p.params.Identity,
|
||||||
Target: livekit.SignalTarget_SUBSCRIBER,
|
Target: livekit.SignalTarget_SUBSCRIBER,
|
||||||
Config: params.Config,
|
Config: params.Config,
|
||||||
@@ -188,7 +187,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) ID() string {
|
func (p *ParticipantImpl) ID() string {
|
||||||
return p.id
|
return p.params.SID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) Identity() string {
|
func (p *ParticipantImpl) Identity() string {
|
||||||
@@ -231,7 +230,7 @@ func (p *ParticipantImpl) RTCPChan() chan []rtcp.Packet {
|
|||||||
|
|
||||||
func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo {
|
func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo {
|
||||||
info := &livekit.ParticipantInfo{
|
info := &livekit.ParticipantInfo{
|
||||||
Sid: p.id,
|
Sid: p.params.SID,
|
||||||
Identity: p.params.Identity,
|
Identity: p.params.Identity,
|
||||||
Metadata: p.metadata,
|
Metadata: p.metadata,
|
||||||
State: p.State(),
|
State: p.State(),
|
||||||
@@ -288,8 +287,8 @@ func (p *ParticipantImpl) OnClose(callback func(types.Participant)) {
|
|||||||
|
|
||||||
// HandleOffer an offer from remote participant, used when clients make the initial connection
|
// HandleOffer an offer from remote participant, used when clients make the initial connection
|
||||||
func (p *ParticipantImpl) HandleOffer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error) {
|
func (p *ParticipantImpl) HandleOffer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error) {
|
||||||
p.params.Logger.Debugw("answering pub offer", "state", p.State().String(),
|
p.params.Logger.Debugw("answering pub offer",
|
||||||
"participant", p.Identity(), "pID", p.ID(),
|
"state", p.State().String(),
|
||||||
//"sdp", sdp.SDP,
|
//"sdp", sdp.SDP,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -313,10 +312,8 @@ func (p *ParticipantImpl) HandleOffer(sdp webrtc.SessionDescription) (answer web
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.params.Logger.Debugw("sending answer to client",
|
p.params.Logger.Debugw("sending answer to client")
|
||||||
"participant", p.Identity(), "pID", p.ID(),
|
|
||||||
//"answer sdp", answer.SDP,
|
|
||||||
)
|
|
||||||
err = p.writeMessage(&livekit.SignalResponse{
|
err = p.writeMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_Answer{
|
Message: &livekit.SignalResponse_Answer{
|
||||||
Answer: ToProtoSessionDescription(answer),
|
Answer: ToProtoSessionDescription(answer),
|
||||||
@@ -351,8 +348,7 @@ func (p *ParticipantImpl) AddTrack(req *livekit.AddTrackRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !p.CanPublish() {
|
if !p.CanPublish() {
|
||||||
p.params.Logger.Warnw("no permission to publish track", nil,
|
p.params.Logger.Warnw("no permission to publish track", nil)
|
||||||
"participant", p.Identity(), "pID", p.ID())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,10 +381,7 @@ func (p *ParticipantImpl) HandleAnswer(sdp webrtc.SessionDescription) error {
|
|||||||
if sdp.Type != webrtc.SDPTypeAnswer {
|
if sdp.Type != webrtc.SDPTypeAnswer {
|
||||||
return ErrUnexpectedOffer
|
return ErrUnexpectedOffer
|
||||||
}
|
}
|
||||||
p.params.Logger.Debugw("setting subPC answer",
|
p.params.Logger.Debugw("setting subPC answer")
|
||||||
"participant", p.Identity(), "pID", p.ID(),
|
|
||||||
//"sdp", sdp.SDP,
|
|
||||||
)
|
|
||||||
|
|
||||||
if err := p.subscriber.SetRemoteDescription(sdp); err != nil {
|
if err := p.subscriber.SetRemoteDescription(sdp); err != nil {
|
||||||
return errors.Wrap(err, "could not set remote description")
|
return errors.Wrap(err, "could not set remote description")
|
||||||
@@ -485,8 +478,8 @@ func (p *ParticipantImpl) AddSubscriber(op types.Participant) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.params.Logger.Debugw("subscribing new participant to tracks",
|
p.params.Logger.Debugw("subscribing new participant to tracks",
|
||||||
"participants", []string{p.Identity(), op.Identity()},
|
"subscriber", op.Identity(),
|
||||||
"pIDs", []string{p.ID(), op.ID()},
|
"subscriberID", op.ID(),
|
||||||
"numTracks", len(tracks))
|
"numTracks", len(tracks))
|
||||||
|
|
||||||
n := 0
|
n := 0
|
||||||
@@ -646,8 +639,6 @@ func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool, fromAdmin bo
|
|||||||
|
|
||||||
if currentMuted != track.IsMuted() && p.onTrackUpdated != nil {
|
if currentMuted != track.IsMuted() && p.onTrackUpdated != nil {
|
||||||
p.params.Logger.Debugw("mute status changed",
|
p.params.Logger.Debugw("mute status changed",
|
||||||
"participant", p.Identity(),
|
|
||||||
"pID", p.ID(),
|
|
||||||
"track", trackId,
|
"track", trackId,
|
||||||
"muted", track.IsMuted())
|
"muted", track.IsMuted())
|
||||||
p.onTrackUpdated(p, track)
|
p.onTrackUpdated(p, track)
|
||||||
@@ -799,8 +790,9 @@ func (p *ParticipantImpl) GetSubscribedTracks() []types.SubscribedTrack {
|
|||||||
|
|
||||||
// AddSubscribedTrack adds a track to the participant's subscribed list
|
// AddSubscribedTrack adds a track to the participant's subscribed list
|
||||||
func (p *ParticipantImpl) AddSubscribedTrack(subTrack types.SubscribedTrack) {
|
func (p *ParticipantImpl) AddSubscribedTrack(subTrack types.SubscribedTrack) {
|
||||||
p.params.Logger.Debugw("added subscribedTrack", "publisher", subTrack.PublisherIdentity(),
|
p.params.Logger.Debugw("added subscribedTrack",
|
||||||
"participant", p.Identity(), "track", subTrack.ID())
|
"publisher", subTrack.PublisherIdentity(),
|
||||||
|
"track", subTrack.ID())
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
p.subscribedTracks[subTrack.ID()] = subTrack
|
p.subscribedTracks[subTrack.ID()] = subTrack
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
@@ -812,7 +804,7 @@ func (p *ParticipantImpl) AddSubscribedTrack(subTrack types.SubscribedTrack) {
|
|||||||
// RemoveSubscribedTrack removes a track to the participant's subscribed list
|
// RemoveSubscribedTrack removes a track to the participant's subscribed list
|
||||||
func (p *ParticipantImpl) RemoveSubscribedTrack(subTrack types.SubscribedTrack) {
|
func (p *ParticipantImpl) RemoveSubscribedTrack(subTrack types.SubscribedTrack) {
|
||||||
p.params.Logger.Debugw("removed subscribedTrack", "publisher", subTrack.PublisherIdentity(),
|
p.params.Logger.Debugw("removed subscribedTrack", "publisher", subTrack.PublisherIdentity(),
|
||||||
"participant", p.Identity(), "track", subTrack.ID(), "kind", subTrack.DownTrack().Kind())
|
"track", subTrack.ID(), "kind", subTrack.DownTrack().Kind())
|
||||||
|
|
||||||
p.subscriber.RemoveTrack(subTrack)
|
p.subscriber.RemoveTrack(subTrack)
|
||||||
|
|
||||||
@@ -836,8 +828,6 @@ func (p *ParticipantImpl) sendIceCandidate(c *webrtc.ICECandidate, target liveki
|
|||||||
|
|
||||||
// write candidate
|
// write candidate
|
||||||
p.params.Logger.Debugw("sending ice candidates",
|
p.params.Logger.Debugw("sending ice candidates",
|
||||||
"participant", p.Identity(),
|
|
||||||
"pID", p.ID(),
|
|
||||||
"candidate", c.String())
|
"candidate", c.String())
|
||||||
trickle := ToProtoTrickle(ci)
|
trickle := ToProtoTrickle(ci)
|
||||||
trickle.Target = target
|
trickle.Target = target
|
||||||
@@ -854,7 +844,7 @@ func (p *ParticipantImpl) updateState(state livekit.ParticipantInfo_State) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.state.Store(state)
|
p.state.Store(state)
|
||||||
p.params.Logger.Debugw("updating participant state", "state", state.String(), "participant", p.Identity(), "pID", p.ID())
|
p.params.Logger.Debugw("updating participant state", "state", state.String())
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
onStateChange := p.onStateChange
|
onStateChange := p.onStateChange
|
||||||
p.lock.RUnlock()
|
p.lock.RUnlock()
|
||||||
@@ -877,8 +867,6 @@ func (p *ParticipantImpl) writeMessage(msg *livekit.SignalResponse) error {
|
|||||||
err := sink.WriteMessage(msg)
|
err := sink.WriteMessage(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.params.Logger.Warnw("could not send message to participant", err,
|
p.params.Logger.Warnw("could not send message to participant", err,
|
||||||
"pID", p.ID(),
|
|
||||||
"participant", p.Identity(),
|
|
||||||
"message", fmt.Sprintf("%T", msg.Message))
|
"message", fmt.Sprintf("%T", msg.Message))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -888,15 +876,11 @@ func (p *ParticipantImpl) writeMessage(msg *livekit.SignalResponse) error {
|
|||||||
// when the server has an offer for participant
|
// when the server has an offer for participant
|
||||||
func (p *ParticipantImpl) onOffer(offer webrtc.SessionDescription) {
|
func (p *ParticipantImpl) onOffer(offer webrtc.SessionDescription) {
|
||||||
if p.State() == livekit.ParticipantInfo_DISCONNECTED {
|
if p.State() == livekit.ParticipantInfo_DISCONNECTED {
|
||||||
p.params.Logger.Debugw("skipping server offer", "participant", p.Identity(), "pID", p.ID())
|
|
||||||
// skip when disconnected
|
// skip when disconnected
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.params.Logger.Debugw("sending server offer to participant",
|
p.params.Logger.Debugw("sending server offer to participant")
|
||||||
"participant", p.Identity(), "pID", p.ID(),
|
|
||||||
//"sdp", offer.SDP,
|
|
||||||
)
|
|
||||||
|
|
||||||
err := p.writeMessage(&livekit.SignalResponse{
|
err := p.writeMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_Offer{
|
Message: &livekit.SignalResponse_Offer{
|
||||||
@@ -918,15 +902,12 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
|
|||||||
|
|
||||||
p.params.Logger.Debugw("mediaTrack added",
|
p.params.Logger.Debugw("mediaTrack added",
|
||||||
"kind", track.Kind().String(),
|
"kind", track.Kind().String(),
|
||||||
"participant", p.Identity(),
|
|
||||||
"pID", p.ID(),
|
|
||||||
"track", track.ID(),
|
"track", track.ID(),
|
||||||
"rid", track.RID(),
|
"rid", track.RID(),
|
||||||
"SSRC", track.SSRC())
|
"SSRC", track.SSRC())
|
||||||
|
|
||||||
if !p.CanPublish() {
|
if !p.CanPublish() {
|
||||||
p.params.Logger.Warnw("no permission to publish mediaTrack", nil,
|
p.params.Logger.Warnw("no permission to publish mediaTrack", nil)
|
||||||
"participant", p.Identity(), "pID", p.ID())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -946,7 +927,7 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
|
|||||||
TrackInfo: ti,
|
TrackInfo: ti,
|
||||||
SignalCid: signalCid,
|
SignalCid: signalCid,
|
||||||
SdpCid: track.ID(),
|
SdpCid: track.ID(),
|
||||||
ParticipantID: p.id,
|
ParticipantID: p.params.SID,
|
||||||
ParticipantIdentity: p.Identity(),
|
ParticipantIdentity: p.Identity(),
|
||||||
RTCPChan: p.rtcpCh,
|
RTCPChan: p.rtcpCh,
|
||||||
BufferFactory: p.params.Config.BufferFactory,
|
BufferFactory: p.params.Config.BufferFactory,
|
||||||
@@ -996,7 +977,7 @@ func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) {
|
|||||||
p.handleDataMessage(livekit.DataPacket_LOSSY, msg.Data)
|
p.handleDataMessage(livekit.DataPacket_LOSSY, msg.Data)
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
p.params.Logger.Warnw("unsupported datachannel added", nil, "participant", p.Identity(), "pID", p.ID(), "label", dc.Label())
|
p.params.Logger.Warnw("unsupported datachannel added", nil, "label", dc.Label())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1060,7 +1041,7 @@ func (p *ParticipantImpl) handleDataMessage(kind livekit.DataPacket_Kind, data [
|
|||||||
switch payload := dp.Value.(type) {
|
switch payload := dp.Value.(type) {
|
||||||
case *livekit.DataPacket_User:
|
case *livekit.DataPacket_User:
|
||||||
if p.onDataPacket != nil {
|
if p.onDataPacket != nil {
|
||||||
payload.User.ParticipantSid = p.id
|
payload.User.ParticipantSid = p.params.SID
|
||||||
p.onDataPacket(p, &dp)
|
p.onDataPacket(p, &dp)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -1092,8 +1073,6 @@ func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) handlePrimaryICEStateChange(state webrtc.ICEConnectionState) {
|
func (p *ParticipantImpl) handlePrimaryICEStateChange(state webrtc.ICEConnectionState) {
|
||||||
// p.params.Logger.Debugw("ICE connection state changed", "state", state.String(),
|
|
||||||
// "participant", p.identity, "pID", p.ID())
|
|
||||||
if state == webrtc.ICEConnectionStateConnected {
|
if state == webrtc.ICEConnectionStateConnected {
|
||||||
prometheus.ServiceOperationCounter.WithLabelValues("ice_connection", "success", "").Add(1)
|
prometheus.ServiceOperationCounter.WithLabelValues("ice_connection", "success", "").Add(1)
|
||||||
p.updateState(livekit.ParticipantInfo_ACTIVE)
|
p.updateState(livekit.ParticipantInfo_ACTIVE)
|
||||||
@@ -1160,8 +1139,7 @@ func (p *ParticipantImpl) downTracksRTCPWorker() {
|
|||||||
if err == io.EOF || err == io.ErrClosedPipe {
|
if err == io.EOF || err == io.ErrClosedPipe {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Errorw("could not send downtrack reports", err,
|
logger.Errorw("could not send downtrack reports", err)
|
||||||
"participant", p.Identity(), "pID", p.ID())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1200,8 +1178,7 @@ func (p *ParticipantImpl) rtcpSendWorker() {
|
|||||||
|
|
||||||
if len(fwdPkts) > 0 {
|
if len(fwdPkts) > 0 {
|
||||||
if err := p.publisher.pc.WriteRTCP(fwdPkts); err != nil {
|
if err := p.publisher.pc.WriteRTCP(fwdPkts); err != nil {
|
||||||
p.params.Logger.Errorw("could not write RTCP to participant", err,
|
p.params.Logger.Errorw("could not write RTCP to participant", err)
|
||||||
"participant", p.Identity(), "pID", p.ID())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1336,7 +1313,7 @@ func (p *ParticipantImpl) onStreamStateChange(update *sfu.StreamStateUpdate) err
|
|||||||
|
|
||||||
func (p *ParticipantImpl) DebugInfo() map[string]interface{} {
|
func (p *ParticipantImpl) DebugInfo() map[string]interface{} {
|
||||||
info := map[string]interface{}{
|
info := map[string]interface{}{
|
||||||
"ID": p.id,
|
"ID": p.params.SID,
|
||||||
"State": p.State().String(),
|
"State": p.State().String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -60,7 +60,7 @@ type ParticipantOptions struct {
|
|||||||
func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioConfig, telemetry telemetry.TelemetryService) *Room {
|
func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioConfig, telemetry telemetry.TelemetryService) *Room {
|
||||||
r := &Room{
|
r := &Room{
|
||||||
Room: proto.Clone(room).(*livekit.Room),
|
Room: proto.Clone(room).(*livekit.Room),
|
||||||
Logger: logger.Logger(logger.GetLogger().WithValues("room", room.Name)),
|
Logger: LoggerWithRoom(logger.Logger(logger.GetLogger()), room.Name),
|
||||||
config: config,
|
config: config,
|
||||||
audioConfig: audioConfig,
|
audioConfig: audioConfig,
|
||||||
telemetry: telemetry,
|
telemetry: telemetry,
|
||||||
@@ -172,7 +172,10 @@ func (r *Room) Join(participant types.Participant, opts *ParticipantOptions, ice
|
|||||||
// it's important to set this before connection, we don't want to miss out on any publishedTracks
|
// it's important to set this before connection, we don't want to miss out on any publishedTracks
|
||||||
participant.OnTrackPublished(r.onTrackPublished)
|
participant.OnTrackPublished(r.onTrackPublished)
|
||||||
participant.OnStateChange(func(p types.Participant, oldState livekit.ParticipantInfo_State) {
|
participant.OnStateChange(func(p types.Participant, oldState livekit.ParticipantInfo_State) {
|
||||||
r.Logger.Debugw("participant state changed", "state", p.State(), "participant", p.Identity(), "pID", p.ID(),
|
r.Logger.Debugw("participant state changed",
|
||||||
|
"state", p.State(),
|
||||||
|
"participant", p.Identity(),
|
||||||
|
"pID", p.ID(),
|
||||||
"oldState", oldState)
|
"oldState", oldState)
|
||||||
if r.onParticipantChanged != nil {
|
if r.onParticipantChanged != nil {
|
||||||
r.onParticipantChanged(participant)
|
r.onParticipantChanged(participant)
|
||||||
|
|||||||
+10
-40
@@ -6,53 +6,32 @@ import (
|
|||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleParticipantSignal(room types.Room, participant types.Participant, req *livekit.SignalRequest) error {
|
func HandleParticipantSignal(room types.Room, participant types.Participant, req *livekit.SignalRequest, pLogger logger.Logger) error {
|
||||||
switch msg := req.Message.(type) {
|
switch msg := req.Message.(type) {
|
||||||
case *livekit.SignalRequest_Offer:
|
case *livekit.SignalRequest_Offer:
|
||||||
_, err := participant.HandleOffer(FromProtoSessionDescription(msg.Offer))
|
_, err := participant.HandleOffer(FromProtoSessionDescription(msg.Offer))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorw("could not handle offer", err,
|
pLogger.Errorw("could not handle offer", err)
|
||||||
"room", room.Name(),
|
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case *livekit.SignalRequest_AddTrack:
|
case *livekit.SignalRequest_AddTrack:
|
||||||
logger.Debugw("add track request",
|
pLogger.Debugw("add track request", "track", msg.AddTrack.Cid)
|
||||||
"room", room.Name(),
|
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
"track", msg.AddTrack.Cid)
|
|
||||||
participant.AddTrack(msg.AddTrack)
|
participant.AddTrack(msg.AddTrack)
|
||||||
case *livekit.SignalRequest_Answer:
|
case *livekit.SignalRequest_Answer:
|
||||||
sd := FromProtoSessionDescription(msg.Answer)
|
sd := FromProtoSessionDescription(msg.Answer)
|
||||||
if err := participant.HandleAnswer(sd); err != nil {
|
if err := participant.HandleAnswer(sd); err != nil {
|
||||||
logger.Errorw("could not handle answer", err,
|
pLogger.Errorw("could not handle answer", err)
|
||||||
"room", room.Name(),
|
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
)
|
|
||||||
// connection cannot be successful if we can't answer
|
// connection cannot be successful if we can't answer
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case *livekit.SignalRequest_Trickle:
|
case *livekit.SignalRequest_Trickle:
|
||||||
candidateInit, err := FromProtoTrickle(msg.Trickle)
|
candidateInit, err := FromProtoTrickle(msg.Trickle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnw("could not decode trickle", err,
|
pLogger.Warnw("could not decode trickle", err)
|
||||||
"room", room.Name(),
|
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// logger.Debugw("adding peer candidate", "participant", participant.Identity())
|
|
||||||
if err := participant.AddICECandidate(candidateInit, msg.Trickle.Target); err != nil {
|
if err := participant.AddICECandidate(candidateInit, msg.Trickle.Target); err != nil {
|
||||||
logger.Warnw("could not handle trickle", err,
|
pLogger.Warnw("could not handle trickle", err)
|
||||||
"room", room.Name(),
|
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case *livekit.SignalRequest_Mute:
|
case *livekit.SignalRequest_Mute:
|
||||||
participant.SetTrackMuted(msg.Mute.Sid, msg.Mute.Muted, false)
|
participant.SetTrackMuted(msg.Mute.Sid, msg.Mute.Muted, false)
|
||||||
@@ -67,10 +46,7 @@ func HandleParticipantSignal(room types.Room, participant types.Participant, req
|
|||||||
err = ErrCannotSubscribe
|
err = ErrCannotSubscribe
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnw("could not update subscription", err,
|
pLogger.Warnw("could not update subscription", err,
|
||||||
"room", room.Name(),
|
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
"tracks", msg.Subscription.TrackSids,
|
"tracks", msg.Subscription.TrackSids,
|
||||||
"subscribe", msg.Subscription.Subscribe)
|
"subscribe", msg.Subscription.Subscribe)
|
||||||
}
|
}
|
||||||
@@ -78,26 +54,20 @@ func HandleParticipantSignal(room types.Room, participant types.Participant, req
|
|||||||
for _, sid := range msg.TrackSetting.TrackSids {
|
for _, sid := range msg.TrackSetting.TrackSids {
|
||||||
subTrack := participant.GetSubscribedTrack(sid)
|
subTrack := participant.GetSubscribedTrack(sid)
|
||||||
if subTrack == nil {
|
if subTrack == nil {
|
||||||
logger.Warnw("unable to find SubscribedTrack", nil,
|
pLogger.Warnw("unable to find SubscribedTrack", nil,
|
||||||
"room", room.Name(),
|
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
"track", sid)
|
"track", sid)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// find quality for published track
|
// find quality for published track
|
||||||
logger.Debugw("updating track settings",
|
pLogger.Debugw("updating track settings",
|
||||||
"room", room.Name(),
|
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
"settings", msg.TrackSetting)
|
"settings", msg.TrackSetting)
|
||||||
subTrack.UpdateSubscriberSettings(msg.TrackSetting)
|
subTrack.UpdateSubscriberSettings(msg.TrackSetting)
|
||||||
}
|
}
|
||||||
case *livekit.SignalRequest_UpdateLayers:
|
case *livekit.SignalRequest_UpdateLayers:
|
||||||
track := participant.GetPublishedTrack(msg.UpdateLayers.TrackSid)
|
track := participant.GetPublishedTrack(msg.UpdateLayers.TrackSid)
|
||||||
if track == nil {
|
if track == nil {
|
||||||
logger.Warnw("could not find published track", nil,
|
pLogger.Warnw("could not find published track", nil,
|
||||||
"track", msg.UpdateLayers.TrackSid)
|
"track", msg.UpdateLayers.TrackSid)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bep/debounce"
|
"github.com/bep/debounce"
|
||||||
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
livekit "github.com/livekit/protocol/livekit"
|
|
||||||
"github.com/pion/interceptor"
|
"github.com/pion/interceptor"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
|
||||||
@@ -100,8 +100,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
}
|
}
|
||||||
if params.Target == livekit.SignalTarget_SUBSCRIBER {
|
if params.Target == livekit.SignalTarget_SUBSCRIBER {
|
||||||
t.streamAllocator = sfu.NewStreamAllocator(sfu.StreamAllocatorParams{
|
t.streamAllocator = sfu.NewStreamAllocator(sfu.StreamAllocatorParams{
|
||||||
ParticipantID: params.ParticipantID,
|
Logger: params.Logger,
|
||||||
Logger: params.Logger,
|
|
||||||
})
|
})
|
||||||
t.streamAllocator.Start()
|
t.streamAllocator.Start()
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-1
@@ -6,8 +6,9 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-logr/logr"
|
||||||
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
livekit "github.com/livekit/protocol/livekit"
|
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||||
@@ -130,3 +131,24 @@ func Recover() {
|
|||||||
logger.GetLogger().Error(err, "recovered panic", "panic", r)
|
logger.GetLogger().Error(err, "recovered panic", "panic", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// logger helpers
|
||||||
|
func LoggerWithParticipant(l logger.Logger, identity, sid string) logger.Logger {
|
||||||
|
lr := logr.Logger(l)
|
||||||
|
if identity != "" {
|
||||||
|
lr = lr.WithValues("participant", identity)
|
||||||
|
}
|
||||||
|
if sid != "" {
|
||||||
|
lr = lr.WithValues("pID", sid)
|
||||||
|
}
|
||||||
|
return logger.Logger(lr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoggerWithRoom(l logger.Logger, name string) logger.Logger {
|
||||||
|
lr := logr.Logger(l)
|
||||||
|
return logger.Logger(
|
||||||
|
lr.WithValues(
|
||||||
|
"room", name,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
+27
-15
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
|
"github.com/livekit/protocol/utils"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/routing"
|
"github.com/livekit/livekit-server/pkg/routing"
|
||||||
@@ -225,8 +226,11 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
|||||||
pv := types.ProtocolVersion(pi.Client.Protocol)
|
pv := types.ProtocolVersion(pi.Client.Protocol)
|
||||||
rtcConf := *r.rtcConfig
|
rtcConf := *r.rtcConfig
|
||||||
rtcConf.SetBufferFactory(room.GetBufferFactor())
|
rtcConf.SetBufferFactory(room.GetBufferFactor())
|
||||||
|
sid := utils.NewGuid(utils.ParticipantPrefix)
|
||||||
|
pLogger := rtc.LoggerWithParticipant(room.Logger, pi.Identity, sid)
|
||||||
participant, err = rtc.NewParticipant(rtc.ParticipantParams{
|
participant, err = rtc.NewParticipant(rtc.ParticipantParams{
|
||||||
Identity: pi.Identity,
|
Identity: pi.Identity,
|
||||||
|
SID: sid,
|
||||||
Config: &rtcConf,
|
Config: &rtcConf,
|
||||||
Sink: responseSink,
|
Sink: responseSink,
|
||||||
AudioConfig: r.config.Audio,
|
AudioConfig: r.config.Audio,
|
||||||
@@ -235,7 +239,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
|||||||
ThrottleConfig: r.config.RTC.PLIThrottle,
|
ThrottleConfig: r.config.RTC.PLIThrottle,
|
||||||
EnabledCodecs: room.Room.EnabledCodecs,
|
EnabledCodecs: room.Room.EnabledCodecs,
|
||||||
Hidden: pi.Hidden,
|
Hidden: pi.Hidden,
|
||||||
Logger: room.Logger,
|
Logger: pLogger,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorw("could not create participant", err)
|
logger.Errorw("could not create participant", err)
|
||||||
@@ -254,11 +258,11 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
|||||||
AutoSubscribe: pi.AutoSubscribe,
|
AutoSubscribe: pi.AutoSubscribe,
|
||||||
}
|
}
|
||||||
if err = room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
|
if err = room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
|
||||||
logger.Errorw("could not join room", err)
|
pLogger.Errorw("could not join room", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = r.roomStore.StoreParticipant(ctx, roomName, participant.ToProto()); err != nil {
|
if err = r.roomStore.StoreParticipant(ctx, roomName, participant.ToProto()); err != nil {
|
||||||
logger.Errorw("could not store participant", err)
|
pLogger.Errorw("could not store participant", err)
|
||||||
}
|
}
|
||||||
// update roomstore with new numParticipants
|
// update roomstore with new numParticipants
|
||||||
if !participant.Hidden() {
|
if !participant.Hidden() {
|
||||||
@@ -271,7 +275,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
|||||||
r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto())
|
r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto())
|
||||||
participant.OnClose(func(p types.Participant) {
|
participant.OnClose(func(p types.Participant) {
|
||||||
if err := r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()); err != nil {
|
if err := r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()); err != nil {
|
||||||
logger.Errorw("could not delete participant", err)
|
pLogger.Errorw("could not delete participant", err)
|
||||||
}
|
}
|
||||||
// update roomstore with new numParticipants
|
// update roomstore with new numParticipants
|
||||||
if !participant.Hidden() {
|
if !participant.Hidden() {
|
||||||
@@ -346,6 +350,11 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
|||||||
}()
|
}()
|
||||||
defer rtc.Recover()
|
defer rtc.Recover()
|
||||||
|
|
||||||
|
pLogger := rtc.LoggerWithParticipant(
|
||||||
|
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), room.Name()),
|
||||||
|
participant.Identity(), participant.ID(),
|
||||||
|
)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Millisecond * 50):
|
case <-time.After(time.Millisecond * 50):
|
||||||
@@ -361,7 +370,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := obj.(*livekit.SignalRequest)
|
req := obj.(*livekit.SignalRequest)
|
||||||
if err := rtc.HandleParticipantSignal(room, participant, req); err != nil {
|
if err := rtc.HandleParticipantSignal(room, participant, req, pLogger); err != nil {
|
||||||
// more specific errors are already logged
|
// more specific errors are already logged
|
||||||
// treat errors returned as fatal
|
// treat errors returned as fatal
|
||||||
return
|
return
|
||||||
@@ -382,22 +391,27 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
|
|||||||
}
|
}
|
||||||
|
|
||||||
participant := room.GetParticipant(identity)
|
participant := room.GetParticipant(identity)
|
||||||
|
pLogger := rtc.LoggerWithParticipant(
|
||||||
|
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName),
|
||||||
|
identity,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
switch rm := msg.Message.(type) {
|
switch rm := msg.Message.(type) {
|
||||||
case *livekit.RTCNodeMessage_RemoveParticipant:
|
case *livekit.RTCNodeMessage_RemoveParticipant:
|
||||||
if participant == nil {
|
if participant == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Infow("removing participant", "room", roomName, "participant", identity)
|
pLogger.Infow("removing participant")
|
||||||
room.RemoveParticipant(identity)
|
room.RemoveParticipant(identity)
|
||||||
case *livekit.RTCNodeMessage_MuteTrack:
|
case *livekit.RTCNodeMessage_MuteTrack:
|
||||||
if participant == nil {
|
if participant == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Debugw("setting track muted", "room", roomName, "participant", identity,
|
pLogger.Debugw("setting track muted",
|
||||||
"track", rm.MuteTrack.TrackSid, "muted", rm.MuteTrack.Muted)
|
"track", rm.MuteTrack.TrackSid, "muted", rm.MuteTrack.Muted)
|
||||||
if !rm.MuteTrack.Muted && !r.config.Room.EnableRemoteUnmute {
|
if !rm.MuteTrack.Muted && !r.config.Room.EnableRemoteUnmute {
|
||||||
logger.Errorw("cannot unmute track, remote unmute is disabled", nil)
|
pLogger.Errorw("cannot unmute track, remote unmute is disabled", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted, true)
|
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted, true)
|
||||||
@@ -405,7 +419,7 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
|
|||||||
if participant == nil {
|
if participant == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Debugw("updating participant", "room", roomName, "participant", identity)
|
pLogger.Debugw("updating participant")
|
||||||
if rm.UpdateParticipant.Metadata != "" {
|
if rm.UpdateParticipant.Metadata != "" {
|
||||||
participant.SetMetadata(rm.UpdateParticipant.Metadata)
|
participant.SetMetadata(rm.UpdateParticipant.Metadata)
|
||||||
}
|
}
|
||||||
@@ -421,23 +435,21 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
|
|||||||
if participant == nil {
|
if participant == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Debugw("updating participant subscriptions", "room", roomName, "participant", identity)
|
pLogger.Debugw("updating participant subscriptions")
|
||||||
if err := room.UpdateSubscriptions(participant, rm.UpdateSubscriptions.TrackSids, rm.UpdateSubscriptions.Subscribe); err != nil {
|
if err := room.UpdateSubscriptions(participant, rm.UpdateSubscriptions.TrackSids, rm.UpdateSubscriptions.Subscribe); err != nil {
|
||||||
logger.Warnw("could not update subscription", err,
|
pLogger.Warnw("could not update subscription", err,
|
||||||
"participant", participant.Identity(),
|
|
||||||
"pID", participant.ID(),
|
|
||||||
"tracks", rm.UpdateSubscriptions.TrackSids,
|
"tracks", rm.UpdateSubscriptions.TrackSids,
|
||||||
"subscribe", rm.UpdateSubscriptions.Subscribe)
|
"subscribe", rm.UpdateSubscriptions.Subscribe)
|
||||||
}
|
}
|
||||||
case *livekit.RTCNodeMessage_SendData:
|
case *livekit.RTCNodeMessage_SendData:
|
||||||
logger.Debugw("SendData", "message", rm)
|
pLogger.Debugw("SendData", "size", len(rm.SendData.Data))
|
||||||
up := &livekit.UserPacket{
|
up := &livekit.UserPacket{
|
||||||
Payload: rm.SendData.Data,
|
Payload: rm.SendData.Data,
|
||||||
DestinationSids: rm.SendData.DestinationSids,
|
DestinationSids: rm.SendData.DestinationSids,
|
||||||
}
|
}
|
||||||
room.SendDataPacket(up, rm.SendData.Kind)
|
room.SendDataPacket(up, rm.SendData.Kind)
|
||||||
case *livekit.RTCNodeMessage_UpdateRoomMetadata:
|
case *livekit.RTCNodeMessage_UpdateRoomMetadata:
|
||||||
logger.Debugw("updating room", "room", roomName)
|
pLogger.Debugw("updating room")
|
||||||
room.SetMetadata(rm.UpdateRoomMetadata.Metadata)
|
room.SetMetadata(rm.UpdateRoomMetadata.Metadata)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-14
@@ -9,8 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
livekit "github.com/livekit/protocol/livekit"
|
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/routing"
|
"github.com/livekit/livekit-server/pkg/routing"
|
||||||
@@ -144,10 +144,14 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pLogger := rtc.LoggerWithParticipant(
|
||||||
|
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName),
|
||||||
|
pi.Identity, "",
|
||||||
|
)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
// function exits when websocket terminates, it'll close the event reading off of response sink as well
|
// function exits when websocket terminates, it'll close the event reading off of response sink as well
|
||||||
defer func() {
|
defer func() {
|
||||||
logger.Infow("server closing WS connection", "participant", pi.Identity, "connID", connId)
|
pLogger.Infow("server closing WS connection", "connID", connId)
|
||||||
reqSink.Close()
|
reqSink.Close()
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
@@ -156,7 +160,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
conn, err := s.upgrader.Upgrade(w, r, nil)
|
conn, err := s.upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "error", "upgrade").Add(1)
|
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "error", "upgrade").Add(1)
|
||||||
logger.Warnw("could not upgrade to WS", err)
|
pLogger.Warnw("could not upgrade to WS", err)
|
||||||
handleError(w, http.StatusInternalServerError, err.Error())
|
handleError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -166,11 +170,9 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "success", "").Add(1)
|
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "success", "").Add(1)
|
||||||
logger.Infow("new client WS connected",
|
pLogger.Infow("new client WS connected",
|
||||||
"connID", connId,
|
"connID", connId,
|
||||||
"roomID", rm.Sid,
|
"roomID", rm.Sid,
|
||||||
"room", rm.Name,
|
|
||||||
"participant", pi.Identity,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// handle responses
|
// handle responses
|
||||||
@@ -187,22 +189,20 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
case msg := <-resSource.ReadChan():
|
case msg := <-resSource.ReadChan():
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
logger.Infow("source closed connection",
|
pLogger.Infow("source closed connection",
|
||||||
"participant", pi.Identity,
|
|
||||||
"connID", connId)
|
"connID", connId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res, ok := msg.(*livekit.SignalResponse)
|
res, ok := msg.(*livekit.SignalResponse)
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Errorw("unexpected message type", nil,
|
pLogger.Errorw("unexpected message type", nil,
|
||||||
"type", fmt.Sprintf("%T", msg),
|
"type", fmt.Sprintf("%T", msg),
|
||||||
"participant", pi.Identity,
|
|
||||||
"connID", connId)
|
"connID", connId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = sigConn.WriteResponse(res); err != nil {
|
if err = sigConn.WriteResponse(res); err != nil {
|
||||||
logger.Warnw("error writing to websocket", err)
|
pLogger.Warnw("error writing to websocket", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,13 +218,12 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
websocket.IsCloseError(err, websocket.CloseAbnormalClosure, websocket.CloseGoingAway, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
|
websocket.IsCloseError(err, websocket.CloseAbnormalClosure, websocket.CloseGoingAway, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
logger.Errorw("error reading from websocket", err)
|
pLogger.Errorw("error reading from websocket", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := reqSink.WriteMessage(req); err != nil {
|
if err := reqSink.WriteMessage(req); err != nil {
|
||||||
logger.Warnw("error writing to request sink", err,
|
pLogger.Warnw("error writing to request sink", err,
|
||||||
"participant", pi.Identity,
|
|
||||||
"connID", connId)
|
"connID", connId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-9
@@ -117,13 +117,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ProberParams struct {
|
type ProberParams struct {
|
||||||
ParticipantID string
|
Logger logger.Logger
|
||||||
Logger logger.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Prober struct {
|
type Prober struct {
|
||||||
participantID string
|
logger logger.Logger
|
||||||
logger logger.Logger
|
|
||||||
|
|
||||||
clustersMu sync.RWMutex
|
clustersMu sync.RWMutex
|
||||||
clusters deque.Deque
|
clusters deque.Deque
|
||||||
@@ -134,8 +132,7 @@ type Prober struct {
|
|||||||
|
|
||||||
func NewProber(params ProberParams) *Prober {
|
func NewProber(params ProberParams) *Prober {
|
||||||
p := &Prober{
|
p := &Prober{
|
||||||
participantID: params.ParticipantID,
|
logger: params.Logger,
|
||||||
logger: params.Logger,
|
|
||||||
}
|
}
|
||||||
p.clusters.SetMinCapacity(2)
|
p.clusters.SetMinCapacity(2)
|
||||||
return p
|
return p
|
||||||
@@ -153,7 +150,7 @@ func (p *Prober) Reset() {
|
|||||||
defer p.clustersMu.Unlock()
|
defer p.clustersMu.Unlock()
|
||||||
|
|
||||||
if p.activeCluster != nil {
|
if p.activeCluster != nil {
|
||||||
p.logger.Debugw("resetting active cluster", "participant", p.participantID, "cluster", p.activeCluster.String())
|
p.logger.Debugw("resetting active cluster", "cluster", p.activeCluster.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
p.clusters.Clear()
|
p.clusters.Clear()
|
||||||
@@ -170,7 +167,7 @@ func (p *Prober) AddCluster(desiredRateBps int, expectedRateBps int, minDuration
|
|||||||
}
|
}
|
||||||
|
|
||||||
cluster := NewCluster(desiredRateBps, expectedRateBps, minDuration, maxDuration)
|
cluster := NewCluster(desiredRateBps, expectedRateBps, minDuration, maxDuration)
|
||||||
p.logger.Debugw("cluster added", "participant", p.participantID, "cluster", cluster.String())
|
p.logger.Debugw("cluster added", "cluster", cluster.String())
|
||||||
|
|
||||||
p.pushBackClusterAndMaybeStart(cluster)
|
p.pushBackClusterAndMaybeStart(cluster)
|
||||||
}
|
}
|
||||||
@@ -258,7 +255,7 @@ func (p *Prober) run() {
|
|||||||
cluster.Process(p)
|
cluster.Process(p)
|
||||||
|
|
||||||
if cluster.IsFinished() {
|
if cluster.IsFinished() {
|
||||||
p.logger.Debugw("cluster finished", "participant", p.participantID, "cluster", cluster.String())
|
p.logger.Debugw("cluster finished", "cluster", cluster.String())
|
||||||
p.popFrontCluster(cluster)
|
p.popFrontCluster(cluster)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-16
@@ -192,13 +192,11 @@ func (s Signal) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StreamAllocatorParams struct {
|
type StreamAllocatorParams struct {
|
||||||
ParticipantID string
|
Logger logger.Logger
|
||||||
Logger logger.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type StreamAllocator struct {
|
type StreamAllocator struct {
|
||||||
participantID string
|
logger logger.Logger
|
||||||
logger logger.Logger
|
|
||||||
|
|
||||||
onStreamStateChange func(update *StreamStateUpdate) error
|
onStreamStateChange func(update *StreamStateUpdate) error
|
||||||
|
|
||||||
@@ -234,13 +232,11 @@ type Event struct {
|
|||||||
|
|
||||||
func NewStreamAllocator(params StreamAllocatorParams) *StreamAllocator {
|
func NewStreamAllocator(params StreamAllocatorParams) *StreamAllocator {
|
||||||
s := &StreamAllocator{
|
s := &StreamAllocator{
|
||||||
participantID: params.ParticipantID,
|
logger: params.Logger,
|
||||||
logger: params.Logger,
|
audioTracks: make(map[string]*Track),
|
||||||
audioTracks: make(map[string]*Track),
|
videoTracks: make(map[string]*Track),
|
||||||
videoTracks: make(map[string]*Track),
|
|
||||||
prober: NewProber(ProberParams{
|
prober: NewProber(ProberParams{
|
||||||
ParticipantID: params.ParticipantID,
|
Logger: params.Logger,
|
||||||
Logger: params.Logger,
|
|
||||||
}),
|
}),
|
||||||
eventCh: make(chan Event, 20),
|
eventCh: make(chan Event, 20),
|
||||||
runningCh: make(chan struct{}),
|
runningCh: make(chan struct{}),
|
||||||
@@ -517,7 +513,7 @@ func (s *StreamAllocator) handleSignalEstimate(event *Event) {
|
|||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
if len(remb.SSRCs) == 0 {
|
if len(remb.SSRCs) == 0 {
|
||||||
s.logger.Warnw("no SSRC to track REMB", nil, "participant", s.participantID)
|
s.logger.Warnw("no SSRC to track REMB", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,7 +538,10 @@ func (s *StreamAllocator) handleSignalEstimate(event *Event) {
|
|||||||
s.prevReceivedEstimate = s.receivedEstimate
|
s.prevReceivedEstimate = s.receivedEstimate
|
||||||
s.receivedEstimate = int64(remb.Bitrate)
|
s.receivedEstimate = int64(remb.Bitrate)
|
||||||
if s.prevReceivedEstimate != s.receivedEstimate {
|
if s.prevReceivedEstimate != s.receivedEstimate {
|
||||||
s.logger.Debugw("received new estimate", "participant", s.participantID, "old(bps)", s.prevReceivedEstimate, "new(bps)", s.receivedEstimate)
|
s.logger.Debugw("received new estimate",
|
||||||
|
"old(bps)", s.prevReceivedEstimate,
|
||||||
|
"new(bps)", s.receivedEstimate,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.maybeCommitEstimate() {
|
if s.maybeCommitEstimate() {
|
||||||
@@ -647,7 +646,7 @@ func (s *StreamAllocator) handleSignalSendProbe(event *Event) {
|
|||||||
|
|
||||||
func (s *StreamAllocator) setState(state State) {
|
func (s *StreamAllocator) setState(state State) {
|
||||||
if s.state != state {
|
if s.state != state {
|
||||||
s.logger.Infow("state change", "participant", s.participantID, "from", s.state, "to", state)
|
s.logger.Infow("state change", "from", s.state, "to", state)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.state = state
|
s.state = state
|
||||||
@@ -700,7 +699,7 @@ func (s *StreamAllocator) maybeCommitEstimate() (isDecreasing bool) {
|
|||||||
s.committedChannelCapacity = s.receivedEstimate
|
s.committedChannelCapacity = s.receivedEstimate
|
||||||
s.lastCommitTime = time.Now()
|
s.lastCommitTime = time.Now()
|
||||||
|
|
||||||
s.logger.Debugw("committing channel capacity", "participant", s.participantID, "capacity(bps)", s.committedChannelCapacity)
|
s.logger.Debugw("committing channel capacity", "capacity(bps)", s.committedChannelCapacity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,11 +873,11 @@ func (s *StreamAllocator) maybeSendUpdate(update *StreamStateUpdate) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.logger.Debugw("streamed tracks changed", "participant", s.participantID, "update", update)
|
s.logger.Debugw("streamed tracks changed", "update", update)
|
||||||
if s.onStreamStateChange != nil {
|
if s.onStreamStateChange != nil {
|
||||||
err := s.onStreamStateChange(update)
|
err := s.onStreamStateChange(update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Errorw("could not send streamed tracks update", err, "participant", s.participantID)
|
s.logger.Errorw("could not send streamed tracks update", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user