-
Notifications
You must be signed in to change notification settings - Fork 43
/
active_speaker_observer_test.go
86 lines (71 loc) · 2.62 KB
/
active_speaker_observer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package mediasoup
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestActiveSpeakerObserver(t *testing.T) {
mediaCodecs := []*RtpCodecCapability{
{
Kind: "audio",
MimeType: "audio/opus",
ClockRate: 48000,
Channels: 2,
Parameters: RtpCodecSpecificParameters{
Useinbandfec: 1,
},
},
}
// before all
worker := CreateTestWorker()
router, _ := worker.CreateRouter(RouterOptions{
MediaCodecs: mediaCodecs,
})
var activeSpeakerObserver IRtpObserver
// after all
defer worker.Close()
t.Run("router.createActiveSpeakerObserver() succeeds", func(t *testing.T) {
onObserverNewRtpObserver := NewMockFunc(t)
router.observer.Once("newrtpobserver", onObserverNewRtpObserver.Fn())
var err error
activeSpeakerObserver, err = router.CreateActiveSpeakerObserver()
require.NoError(t, err)
onObserverNewRtpObserver.ExpectCalled()
onObserverNewRtpObserver.ExpectCalledWith(activeSpeakerObserver)
assert.False(t, activeSpeakerObserver.Closed())
assert.False(t, activeSpeakerObserver.Paused())
})
t.Run("activeSpeakerObserver.pause() and resume() succeed", func(t *testing.T) {
activeSpeakerObserver.Pause()
assert.True(t, activeSpeakerObserver.Paused())
activeSpeakerObserver.Resume()
assert.False(t, activeSpeakerObserver.Paused())
})
t.Run("activeSpeakerObserver.close() succeeds", func(t *testing.T) {
// We need different a ActiveSpeakerObserver instance here.
activeSpeakerObserver2, _ := router.CreateActiveSpeakerObserver()
dump, _ := router.Dump()
assert.Len(t, dump.RtpObserverIds, 2)
activeSpeakerObserver2.Close()
assert.True(t, activeSpeakerObserver2.Closed())
dump, _ = router.Dump()
assert.Len(t, dump.RtpObserverIds, 1)
})
t.Run(`ActiveSpeakerObserver emits "routerclose" if Router is closed`, func(t *testing.T) {
// We need different Router and ActiveSpeakerObserver instances here.
router2, _ := worker.CreateRouter(RouterOptions{MediaCodecs: mediaCodecs})
activeSpeakerObserver2, _ := router2.CreateActiveSpeakerObserver()
onObserverNewRtpObserver := NewMockFunc(t)
activeSpeakerObserver2.On("routerclose", onObserverNewRtpObserver.Fn())
router2.Close()
assert.Equal(t, 1, onObserverNewRtpObserver.CalledTimes())
assert.True(t, activeSpeakerObserver2.Closed())
})
t.Run(`ActiveSpeakerObserver emits "routerclose" if Worker is closed`, func(t *testing.T) {
onObserverNewRtpObserver := NewMockFunc(t)
activeSpeakerObserver.On("routerclose", onObserverNewRtpObserver.Fn())
worker.Close()
assert.Equal(t, 1, onObserverNewRtpObserver.CalledTimes())
assert.True(t, activeSpeakerObserver.Closed())
})
}