Revamp data channels (#32)

* support for built-in data channels. active speaker updates via data channel

* fixed tests

* update to Pion 3.0.27
This commit is contained in:
David Zhao
2021-04-27 22:02:59 -07:00
committed by GitHub
parent 84ac0a718d
commit 6b63cd5b31
15 changed files with 634 additions and 135 deletions
+1 -1
View File
@@ -8,5 +8,5 @@ var (
ErrMaxParticipantsExceeded = errors.New("room has exceeded its max participants")
ErrAlreadyJoined = errors.New("a participant with the same identity is already in the room")
ErrUnexpectedOffer = errors.New("expected answer SDP, received offer")
ErrUnexpectedNegotiation = errors.New("client negotiation has not been granted")
ErrDataChannelUnavailable = errors.New("data channel is not available")
)
+2 -1
View File
@@ -7,11 +7,12 @@ import (
"github.com/livekit/protocol/utils"
)
func newMockParticipant(identity string) *typesfakes.FakeParticipant {
func newMockParticipant(identity string, protocol types.ProtocolVersion) *typesfakes.FakeParticipant {
p := &typesfakes.FakeParticipant{}
p.IDReturns(utils.NewGuid(utils.ParticipantPrefix))
p.IdentityReturns(identity)
p.StateReturns(livekit.ParticipantInfo_JOINED)
p.ProtocolVersionReturns(protocol)
p.SetMetadataStub = func(m string) {
var f func(participant types.Participant)
+95 -26
View File
@@ -11,6 +11,7 @@ import (
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
@@ -22,8 +23,10 @@ import (
)
const (
placeholderDataChannel = "_private"
sdBatchSize = 15
lossyDataChannel = "_lossy"
reliableDataChannel = "_reliable"
privateDataChannel = "_private"
sdBatchSize = 15
)
type ParticipantImpl struct {
@@ -39,6 +42,9 @@ type ParticipantImpl struct {
state atomic.Value // livekit.ParticipantInfo_State
rtcpCh chan []rtcp.Packet
protocolVersion types.ProtocolVersion
// reliable and unreliable data channels
reliableDC *webrtc.DataChannel
lossyDC *webrtc.DataChannel
// when first connected
connectedAt time.Time
@@ -64,6 +70,7 @@ type ParticipantImpl struct {
onTrackUpdated func(types.Participant, types.PublishedTrack)
onStateChange func(p types.Participant, oldState livekit.ParticipantInfo_State)
onMetadataUpdate func(types.Participant)
onDataPacket func(types.Participant, *livekit.DataPacket)
onClose func(types.Participant)
}
@@ -110,9 +117,9 @@ func NewParticipant(identity string, conf *WebRTCConfig, rs routing.MessageSink,
})
p.publisher.pc.OnICEConnectionStateChange(p.handlePublisherICEStateChange)
p.publisher.pc.OnTrack(p.onMediaTrack)
p.subscriber.pc.OnDataChannel(p.onDataChannel)
p.publisher.pc.OnDataChannel(p.onDataChannel)
p.subscriber.OnOffer(p.onOffer)
return p, nil
@@ -206,6 +213,10 @@ func (p *ParticipantImpl) OnMetadataUpdate(callback func(types.Participant)) {
p.onMetadataUpdate = callback
}
func (p *ParticipantImpl) OnDataPacket(callback func(types.Participant, *livekit.DataPacket)) {
p.onDataPacket = callback
}
func (p *ParticipantImpl) OnClose(callback func(types.Participant)) {
p.onClose = callback
}
@@ -285,8 +296,8 @@ func (p *ParticipantImpl) GetPublishedTracks() []types.PublishedTrack {
return tracks
}
// handles a client answer response, with subscriber PC, server initiates the offer
// and client answers
// HandleAnswer handles a client answer response, with subscriber PC, server initiates the
// offer and client answers
func (p *ParticipantImpl) HandleAnswer(sdp webrtc.SessionDescription) error {
if sdp.Type != webrtc.SDPTypeAnswer {
return ErrUnexpectedOffer
@@ -454,6 +465,30 @@ func (p *ParticipantImpl) SendActiveSpeakers(speakers []*livekit.SpeakerInfo) er
})
}
func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket) error {
if p.State() != livekit.ParticipantInfo_ACTIVE {
return ErrDataChannelUnavailable
}
data, err := proto.Marshal(dp)
if err != nil {
return err
}
if dp.Kind == livekit.DataPacket_RELIABLE {
if p.reliableDC == nil {
return ErrDataChannelUnavailable
}
logger.Debugw("sending reliable packet", "participant", p.Identity())
return p.reliableDC.Send(data)
} else {
if p.lossyDC == nil {
return ErrDataChannelUnavailable
}
logger.Debugw("sending lossy packet", "participant", p.Identity())
return p.lossyDC.Send(data)
}
}
func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool) {
p.lock.RLock()
defer p.lock.RUnlock()
@@ -659,27 +694,39 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
}
func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) {
if dc.Label() == placeholderDataChannel {
return
switch dc.Label() {
case reliableDataChannel:
p.reliableDC = dc
dc.OnMessage(func(msg webrtc.DataChannelMessage) {
p.handleDataMessage(livekit.DataPacket_RELIABLE, msg.Data)
})
case lossyDataChannel:
p.lossyDC = dc
dc.OnMessage(func(msg webrtc.DataChannelMessage) {
p.handleDataMessage(livekit.DataPacket_LOSSY, msg.Data)
})
case privateDataChannel:
// ignore
default:
logger.Debugw("dataChannel added", "participant", p.Identity(), "label", dc.Label())
if !p.CanPublish() {
logger.Warnw("no permission to publish dataTrack",
"participant", p.Identity())
return
}
// data channels have numeric ids, so we use its label to identify
ti := p.getPendingTrack(dc.Label(), livekit.TrackType_DATA, true)
if ti == nil {
return
}
dt := NewDataTrack(ti.Sid, p.id, dc)
dt.name = ti.Name
p.handleTrackPublished(dt)
}
logger.Debugw("dataChannel added", "participant", p.Identity(), "label", dc.Label())
if !p.CanPublish() {
logger.Warnw("no permission to publish dataTrack",
"participant", p.Identity())
return
}
// data channels have numeric ids, so we use its label to identify
ti := p.getPendingTrack(dc.Label(), livekit.TrackType_DATA, true)
if ti == nil {
return
}
dt := NewDataTrack(ti.Sid, p.id, dc)
dt.name = ti.Name
p.handleTrackPublished(dt)
}
func (p *ParticipantImpl) getPendingTrack(clientId string, kind livekit.TrackType, deleteAfter bool) *livekit.TrackInfo {
@@ -708,6 +755,28 @@ func (p *ParticipantImpl) getPendingTrack(clientId string, kind livekit.TrackTyp
return ti
}
func (p *ParticipantImpl) handleDataMessage(kind livekit.DataPacket_Kind, data []byte) {
dp := livekit.DataPacket{}
if err := proto.Unmarshal(data, &dp); err != nil {
logger.Warnw("could not parse data packet", "error", err)
return
}
// trust the channel that it came in as the source of truth
dp.Kind = kind
// only forward on user payloads
switch payload := dp.Value.(type) {
case *livekit.DataPacket_User:
if p.onDataPacket != nil {
payload.User.ParticipantSid = p.id
p.onDataPacket(p, &dp)
}
default:
logger.Warnw("received unsupported data packet", "payload", payload)
}
}
func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) {
// fill in
p.lock.Lock()
+30 -2
View File
@@ -153,6 +153,7 @@ func (r *Room) Join(participant types.Participant) error {
})
participant.OnTrackUpdated(r.onTrackUpdated)
participant.OnMetadataUpdate(r.onParticipantMetadataUpdate)
participant.OnDataPacket(r.onDataPacket)
logger.Infow("new participant joined",
"id", participant.ID(),
"identity", participant.Identity(),
@@ -192,9 +193,11 @@ func (r *Room) RemoveParticipant(identity string) {
p.OnTrackUpdated(nil)
p.OnTrackPublished(nil)
p.OnStateChange(nil)
p.OnMetadataUpdate(nil)
p.OnDataPacket(nil)
// close participant as well
p.Close()
_ = p.Close()
if len(r.participants) == 0 {
r.leftAt.Store(time.Now().Unix())
@@ -328,6 +331,18 @@ func (r *Room) onParticipantMetadataUpdate(p types.Participant) {
}
}
func (r *Room) onDataPacket(source types.Participant, dp *livekit.DataPacket) {
for _, op := range r.GetParticipants() {
if op.State() != livekit.ParticipantInfo_ACTIVE {
continue
}
if op.ID() == source.ID() {
continue
}
_ = op.SendDataPacket(dp)
}
}
func (r *Room) subscribeToExistingTracks(p types.Participant) {
tracksAdded := 0
for _, op := range r.GetParticipants() {
@@ -369,8 +384,21 @@ func (r *Room) broadcastParticipantState(p types.Participant, skipSource bool) {
}
func (r *Room) sendSpeakerUpdates(speakers []*livekit.SpeakerInfo) {
dp := &livekit.DataPacket{
Kind: livekit.DataPacket_LOSSY,
Value: &livekit.DataPacket_Speaker{
Speaker: &livekit.ActiveSpeakerUpdate{
Speakers: speakers,
},
},
}
for _, p := range r.GetParticipants() {
_ = p.SendActiveSpeakers(speakers)
if p.ProtocolVersion().HandlesDataPackets() {
_ = p.SendDataPacket(dp)
} else {
_ = p.SendActiveSpeakers(speakers)
}
}
}
+53 -30
View File
@@ -27,20 +27,20 @@ func init() {
func TestJoinedState(t *testing.T) {
t.Run("new room should return joinedAt 0", func(t *testing.T) {
rm := newRoomWithParticipants(t, 0)
rm := newRoomWithParticipants(t, testRoomOpts{num: 0})
assert.Equal(t, int64(0), rm.FirstJoinedAt())
assert.Equal(t, int64(0), rm.LastLeftAt())
})
t.Run("should be current time when a participant joins", func(t *testing.T) {
s := time.Now().Unix()
rm := newRoomWithParticipants(t, 1)
rm := newRoomWithParticipants(t, testRoomOpts{num: 1})
assert.Equal(t, s, rm.FirstJoinedAt())
assert.Equal(t, int64(0), rm.LastLeftAt())
})
t.Run("should be set when a participant leaves", func(t *testing.T) {
rm := newRoomWithParticipants(t, 1)
rm := newRoomWithParticipants(t, testRoomOpts{num: 1})
p0 := rm.GetParticipants()[0]
s := time.Now().Unix()
rm.RemoveParticipant(p0.Identity())
@@ -48,7 +48,7 @@ func TestJoinedState(t *testing.T) {
})
t.Run("LastLeftAt should not be set when there are still participants in the room", func(t *testing.T) {
rm := newRoomWithParticipants(t, 2)
rm := newRoomWithParticipants(t, testRoomOpts{num: 2})
p0 := rm.GetParticipants()[0]
rm.RemoveParticipant(p0.Identity())
assert.EqualValues(t, 0, rm.LastLeftAt())
@@ -57,8 +57,8 @@ func TestJoinedState(t *testing.T) {
func TestRoomJoin(t *testing.T) {
t.Run("joining returns existing participant data", func(t *testing.T) {
rm := newRoomWithParticipants(t, numParticipants)
pNew := newMockParticipant("new")
rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants})
pNew := newMockParticipant("new", types.DefaultProtocol)
rm.Join(pNew)
@@ -72,8 +72,8 @@ func TestRoomJoin(t *testing.T) {
t.Run("subscribe to existing channels upon join", func(t *testing.T) {
numExisting := 3
rm := newRoomWithParticipants(t, numExisting)
p := newMockParticipant("new")
rm := newRoomWithParticipants(t, testRoomOpts{num: numExisting})
p := newMockParticipant("new", types.DefaultProtocol)
err := rm.Join(p)
assert.NoError(t, err)
@@ -96,7 +96,7 @@ func TestRoomJoin(t *testing.T) {
})
t.Run("participant state change is broadcasted to others", func(t *testing.T) {
rm := newRoomWithParticipants(t, numParticipants)
rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants})
var changedParticipant types.Participant
rm.OnParticipantChanged(func(participant types.Participant) {
changedParticipant = participant
@@ -125,9 +125,9 @@ func TestRoomJoin(t *testing.T) {
})
t.Run("cannot exceed max participants", func(t *testing.T) {
rm := newRoomWithParticipants(t, 1)
rm := newRoomWithParticipants(t, testRoomOpts{num: 1})
rm.MaxParticipants = 1
p := newMockParticipant("second")
p := newMockParticipant("second", types.ProtocolVersion(0))
err := rm.Join(p)
assert.Equal(t, rtc.ErrMaxParticipantsExceeded, err)
@@ -166,7 +166,7 @@ func TestParticipantUpdate(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rm := newRoomWithParticipants(t, 3)
rm := newRoomWithParticipants(t, testRoomOpts{num: 3})
// remember how many times send has been called for each
callCounts := make(map[string]int)
for _, p := range rm.GetParticipants() {
@@ -192,7 +192,7 @@ func TestParticipantUpdate(t *testing.T) {
func TestRoomClosure(t *testing.T) {
t.Run("room closes after participant leaves", func(t *testing.T) {
rm := newRoomWithParticipants(t, 1)
rm := newRoomWithParticipants(t, testRoomOpts{num: 1})
isClosed := false
rm.OnClose(func() {
isClosed = true
@@ -212,7 +212,7 @@ func TestRoomClosure(t *testing.T) {
})
t.Run("room does not close before empty timeout", func(t *testing.T) {
rm := newRoomWithParticipants(t, 0)
rm := newRoomWithParticipants(t, testRoomOpts{num: 0})
isClosed := false
rm.OnClose(func() {
isClosed = true
@@ -223,7 +223,7 @@ func TestRoomClosure(t *testing.T) {
})
t.Run("room closes after empty timeout", func(t *testing.T) {
rm := newRoomWithParticipants(t, 0)
rm := newRoomWithParticipants(t, testRoomOpts{num: 0})
isClosed := false
rm.OnClose(func() {
isClosed = true
@@ -238,7 +238,7 @@ func TestRoomClosure(t *testing.T) {
func TestNewTrack(t *testing.T) {
t.Run("new track should be added to ready participants", func(t *testing.T) {
rm := newRoomWithParticipants(t, 3)
rm := newRoomWithParticipants(t, testRoomOpts{num: 3})
participants := rm.GetParticipants()
p0 := participants[0].(*typesfakes.FakeParticipant)
p0.StateReturns(livekit.ParticipantInfo_JOINED)
@@ -260,19 +260,33 @@ func TestNewTrack(t *testing.T) {
func TestActiveSpeakers(t *testing.T) {
t.Parallel()
getActiveSpeakerUpdates := func(p *typesfakes.FakeParticipant) []*livekit.ActiveSpeakerUpdate {
var updates []*livekit.ActiveSpeakerUpdate
numCalls := p.SendDataPacketCallCount()
for i := 0; i < numCalls; i++ {
dp := p.SendDataPacketArgsForCall(i)
switch val := dp.Value.(type) {
case *livekit.DataPacket_Speaker:
updates = append(updates, val.Speaker)
}
}
return updates
}
audioUpdateDuration := (audioUpdateInterval + 2) * time.Millisecond
t.Run("participant should not be getting audio updates", func(t *testing.T) {
rm := newRoomWithParticipants(t, 1)
t.Run("participant should not be getting audio updates (protocol 2)", func(t *testing.T) {
rm := newRoomWithParticipants(t, testRoomOpts{num: 1, protocol: types.DefaultProtocol})
p := rm.GetParticipants()[0].(*typesfakes.FakeParticipant)
assert.Empty(t, rm.GetActiveSpeakers())
time.Sleep(audioUpdateDuration)
assert.Zero(t, p.SendActiveSpeakersCallCount())
updates := getActiveSpeakerUpdates(p)
assert.Empty(t, updates)
})
t.Run("speakers should be sorted by loudness", func(t *testing.T) {
rm := newRoomWithParticipants(t, 2)
t.Run("speakers should be sorted by loudness (protocol 0)", func(t *testing.T) {
rm := newRoomWithParticipants(t, testRoomOpts{num: 2})
participants := rm.GetParticipants()
p := participants[0].(*typesfakes.FakeParticipant)
p2 := participants[1].(*typesfakes.FakeParticipant)
@@ -285,8 +299,8 @@ func TestActiveSpeakers(t *testing.T) {
assert.Equal(t, p2.ID(), speakers[1].Sid)
})
t.Run("participants are getting audio updates", func(t *testing.T) {
rm := newRoomWithParticipants(t, 2)
t.Run("participants are getting audio updates (protocol 2)", func(t *testing.T) {
rm := newRoomWithParticipants(t, testRoomOpts{num: 2, protocol: types.DefaultProtocol})
participants := rm.GetParticipants()
p := participants[0].(*typesfakes.FakeParticipant)
time.Sleep(time.Millisecond) // let the first update cycle run
@@ -301,25 +315,33 @@ func TestActiveSpeakers(t *testing.T) {
// everyone should've received updates
for _, op := range participants {
op := op.(*typesfakes.FakeParticipant)
require.Equal(t, 1, op.SendActiveSpeakersCallCount())
updates := getActiveSpeakerUpdates(op)
require.Len(t, updates, 1)
}
// after another cycle, we are not getting any new updates since unchanged
time.Sleep(audioUpdateDuration)
for _, op := range participants {
op := op.(*typesfakes.FakeParticipant)
require.Equal(t, 1, op.SendActiveSpeakersCallCount())
updates := getActiveSpeakerUpdates(op)
require.Len(t, updates, 1)
}
// no longer speaking, send update with empty items
p.GetAudioLevelReturns(127, false)
time.Sleep(audioUpdateDuration)
require.Equal(t, 2, p.SendActiveSpeakersCallCount())
require.Empty(t, p.SendActiveSpeakersArgsForCall(1))
updates := getActiveSpeakerUpdates(p)
require.Len(t, updates, 2)
require.Empty(t, updates[1].Speakers)
})
}
func newRoomWithParticipants(t *testing.T, num int) *rtc.Room {
type testRoomOpts struct {
num int
protocol types.ProtocolVersion
}
func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *rtc.Room {
rm := rtc.NewRoom(
&livekit.Room{Name: "room"},
rtc.WebRTCConfig{},
@@ -332,10 +354,11 @@ func newRoomWithParticipants(t *testing.T, num int) *rtc.Room {
},
audioUpdateInterval,
)
for i := 0; i < num; i++ {
for i := 0; i < opts.num; i++ {
identity := fmt.Sprintf("p%d", i)
participant := newMockParticipant(identity)
participant := newMockParticipant(identity, opts.protocol)
err := rm.Join(participant)
participant.StateReturns(livekit.ParticipantInfo_ACTIVE)
assert.NoError(t, err)
}
return rm
+2
View File
@@ -49,6 +49,7 @@ type Participant interface {
SendJoinResponse(info *livekit.Room, otherParticipants []Participant, iceServers []*livekit.ICEServer) error
SendParticipantUpdate(participants []*livekit.ParticipantInfo) error
SendActiveSpeakers(speakers []*livekit.SpeakerInfo) error
SendDataPacket(packet *livekit.DataPacket) error
SetTrackMuted(trackId string, muted bool)
GetAudioLevel() (level uint8, noisy bool)
@@ -66,6 +67,7 @@ type Participant interface {
// OnTrackUpdated - one of its publishedTracks changed in status
OnTrackUpdated(callback func(Participant, PublishedTrack))
OnMetadataUpdate(callback func(Participant))
OnDataPacket(callback func(Participant, *livekit.DataPacket))
OnClose(func(Participant))
// package methods
+6
View File
@@ -2,6 +2,12 @@ package types
type ProtocolVersion int
const DefaultProtocol = 2
func (v ProtocolVersion) SupportsPackedStreamId() bool {
return v > 0
}
func (v ProtocolVersion) HandlesDataPackets() bool {
return v > 1
}
@@ -206,6 +206,11 @@ type FakeParticipant struct {
onCloseArgsForCall []struct {
arg1 func(types.Participant)
}
OnDataPacketStub func(func(types.Participant, *livekit.DataPacket))
onDataPacketMutex sync.RWMutex
onDataPacketArgsForCall []struct {
arg1 func(types.Participant, *livekit.DataPacket)
}
OnMetadataUpdateStub func(func(types.Participant))
onMetadataUpdateMutex sync.RWMutex
onMetadataUpdateArgsForCall []struct {
@@ -268,6 +273,17 @@ type FakeParticipant struct {
sendActiveSpeakersReturnsOnCall map[int]struct {
result1 error
}
SendDataPacketStub func(*livekit.DataPacket) error
sendDataPacketMutex sync.RWMutex
sendDataPacketArgsForCall []struct {
arg1 *livekit.DataPacket
}
sendDataPacketReturns struct {
result1 error
}
sendDataPacketReturnsOnCall map[int]struct {
result1 error
}
SendJoinResponseStub func(*livekit.Room, []types.Participant, []*livekit.ICEServer) error
sendJoinResponseMutex sync.RWMutex
sendJoinResponseArgsForCall []struct {
@@ -1374,6 +1390,38 @@ func (fake *FakeParticipant) OnCloseArgsForCall(i int) func(types.Participant) {
return argsForCall.arg1
}
func (fake *FakeParticipant) OnDataPacket(arg1 func(types.Participant, *livekit.DataPacket)) {
fake.onDataPacketMutex.Lock()
fake.onDataPacketArgsForCall = append(fake.onDataPacketArgsForCall, struct {
arg1 func(types.Participant, *livekit.DataPacket)
}{arg1})
stub := fake.OnDataPacketStub
fake.recordInvocation("OnDataPacket", []interface{}{arg1})
fake.onDataPacketMutex.Unlock()
if stub != nil {
fake.OnDataPacketStub(arg1)
}
}
func (fake *FakeParticipant) OnDataPacketCallCount() int {
fake.onDataPacketMutex.RLock()
defer fake.onDataPacketMutex.RUnlock()
return len(fake.onDataPacketArgsForCall)
}
func (fake *FakeParticipant) OnDataPacketCalls(stub func(func(types.Participant, *livekit.DataPacket))) {
fake.onDataPacketMutex.Lock()
defer fake.onDataPacketMutex.Unlock()
fake.OnDataPacketStub = stub
}
func (fake *FakeParticipant) OnDataPacketArgsForCall(i int) func(types.Participant, *livekit.DataPacket) {
fake.onDataPacketMutex.RLock()
defer fake.onDataPacketMutex.RUnlock()
argsForCall := fake.onDataPacketArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeParticipant) OnMetadataUpdate(arg1 func(types.Participant)) {
fake.onMetadataUpdateMutex.Lock()
fake.onMetadataUpdateArgsForCall = append(fake.onMetadataUpdateArgsForCall, struct {
@@ -1739,6 +1787,67 @@ func (fake *FakeParticipant) SendActiveSpeakersReturnsOnCall(i int, result1 erro
}{result1}
}
func (fake *FakeParticipant) SendDataPacket(arg1 *livekit.DataPacket) error {
fake.sendDataPacketMutex.Lock()
ret, specificReturn := fake.sendDataPacketReturnsOnCall[len(fake.sendDataPacketArgsForCall)]
fake.sendDataPacketArgsForCall = append(fake.sendDataPacketArgsForCall, struct {
arg1 *livekit.DataPacket
}{arg1})
stub := fake.SendDataPacketStub
fakeReturns := fake.sendDataPacketReturns
fake.recordInvocation("SendDataPacket", []interface{}{arg1})
fake.sendDataPacketMutex.Unlock()
if stub != nil {
return stub(arg1)
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *FakeParticipant) SendDataPacketCallCount() int {
fake.sendDataPacketMutex.RLock()
defer fake.sendDataPacketMutex.RUnlock()
return len(fake.sendDataPacketArgsForCall)
}
func (fake *FakeParticipant) SendDataPacketCalls(stub func(*livekit.DataPacket) error) {
fake.sendDataPacketMutex.Lock()
defer fake.sendDataPacketMutex.Unlock()
fake.SendDataPacketStub = stub
}
func (fake *FakeParticipant) SendDataPacketArgsForCall(i int) *livekit.DataPacket {
fake.sendDataPacketMutex.RLock()
defer fake.sendDataPacketMutex.RUnlock()
argsForCall := fake.sendDataPacketArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeParticipant) SendDataPacketReturns(result1 error) {
fake.sendDataPacketMutex.Lock()
defer fake.sendDataPacketMutex.Unlock()
fake.SendDataPacketStub = nil
fake.sendDataPacketReturns = struct {
result1 error
}{result1}
}
func (fake *FakeParticipant) SendDataPacketReturnsOnCall(i int, result1 error) {
fake.sendDataPacketMutex.Lock()
defer fake.sendDataPacketMutex.Unlock()
fake.SendDataPacketStub = nil
if fake.sendDataPacketReturnsOnCall == nil {
fake.sendDataPacketReturnsOnCall = make(map[int]struct {
result1 error
})
}
fake.sendDataPacketReturnsOnCall[i] = struct {
result1 error
}{result1}
}
func (fake *FakeParticipant) SendJoinResponse(arg1 *livekit.Room, arg2 []types.Participant, arg3 []*livekit.ICEServer) error {
var arg2Copy []types.Participant
if arg2 != nil {
@@ -2286,6 +2395,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
defer fake.negotiateMutex.RUnlock()
fake.onCloseMutex.RLock()
defer fake.onCloseMutex.RUnlock()
fake.onDataPacketMutex.RLock()
defer fake.onDataPacketMutex.RUnlock()
fake.onMetadataUpdateMutex.RLock()
defer fake.onMetadataUpdateMutex.RUnlock()
fake.onStateChangeMutex.RLock()
@@ -2304,6 +2415,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
defer fake.removeSubscriberMutex.RUnlock()
fake.sendActiveSpeakersMutex.RLock()
defer fake.sendActiveSpeakersMutex.RUnlock()
fake.sendDataPacketMutex.RLock()
defer fake.sendDataPacketMutex.RUnlock()
fake.sendJoinResponseMutex.RLock()
defer fake.sendJoinResponseMutex.RUnlock()
fake.sendParticipantUpdateMutex.RLock()
+1 -1
View File
@@ -17,7 +17,7 @@ const (
trackIdSeparator = "|"
)
func UnpackStreamID(packed string) (peerId string, trackId string) {
func UnpackStreamID(packed string) (participantId string, trackId string) {
parts := strings.Split(packed, trackIdSeparator)
if len(parts) > 1 {
return parts[0], packed[len(parts[0])+1:]