move CanPublishData check to DataTrack (#490)
* move CanPublishData check to DataTrack * fix test
This commit is contained in:
@@ -1099,11 +1099,17 @@ func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) {
|
||||
case reliableDataChannel:
|
||||
p.reliableDC = dc
|
||||
dc.OnMessage(func(msg webrtc.DataChannelMessage) {
|
||||
if !p.CanPublishData() {
|
||||
return
|
||||
}
|
||||
p.dataTrack.Write(label, msg.Data)
|
||||
})
|
||||
case lossyDataChannel:
|
||||
p.lossyDC = dc
|
||||
dc.OnMessage(func(msg webrtc.DataChannelMessage) {
|
||||
if !p.CanPublishData() {
|
||||
return
|
||||
}
|
||||
p.dataTrack.Write(label, msg.Data)
|
||||
})
|
||||
default:
|
||||
|
||||
@@ -642,10 +642,6 @@ func (r *Room) onParticipantMetadataUpdate(p types.LocalParticipant) {
|
||||
}
|
||||
|
||||
func (r *Room) onDataPacket(source types.LocalParticipant, dp *livekit.DataPacket) {
|
||||
// don't forward if source isn't allowed to publish data
|
||||
if source != nil && !source.CanPublishData() {
|
||||
return
|
||||
}
|
||||
dest := dp.GetUser().GetDestinationSids()
|
||||
|
||||
for _, op := range r.GetParticipants() {
|
||||
|
||||
@@ -485,7 +485,9 @@ func TestDataChannel(t *testing.T) {
|
||||
}
|
||||
dataTrack := &typesfakes.FakeDataTrack{}
|
||||
p.OnDataTrackPublishedArgsForCall(0)(p, dataTrack)
|
||||
dataTrack.OnDataPacketArgsForCall(0)(&packet)
|
||||
if p.CanPublishData() {
|
||||
dataTrack.OnDataPacketArgsForCall(0)(&packet)
|
||||
}
|
||||
|
||||
// no one should've been sent packet
|
||||
for _, op := range participants {
|
||||
|
||||
Reference in New Issue
Block a user