-
Notifications
You must be signed in to change notification settings - Fork 43
/
audio_level_observer_test.go
86 lines (71 loc) · 2.54 KB
/
audio_level_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 TestAudioLevelObserver(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 AudioLevelObserver IRtpObserver
// after all
defer worker.Close()
t.Run("router.createAudioLevelObserver() succeeds", func(t *testing.T) {
onObserverNewRtpObserver := NewMockFunc(t)
router.observer.Once("newrtpobserver", onObserverNewRtpObserver.Fn())
var err error
AudioLevelObserver, err = router.CreateAudioLevelObserver()
require.NoError(t, err)
onObserverNewRtpObserver.ExpectCalled()
onObserverNewRtpObserver.ExpectCalledWith(AudioLevelObserver)
assert.False(t, AudioLevelObserver.Closed())
assert.False(t, AudioLevelObserver.Paused())
})
t.Run("AudioLevelObserver.pause() and resume() succeed", func(t *testing.T) {
AudioLevelObserver.Pause()
assert.True(t, AudioLevelObserver.Paused())
AudioLevelObserver.Resume()
assert.False(t, AudioLevelObserver.Paused())
})
t.Run("AudioLevelObserver.close() succeeds", func(t *testing.T) {
// We need different a AudioLevelObserver instance here.
AudioLevelObserver2, _ := router.CreateAudioLevelObserver()
dump, _ := router.Dump()
assert.Len(t, dump.RtpObserverIds, 2)
AudioLevelObserver2.Close()
assert.True(t, AudioLevelObserver2.Closed())
dump, _ = router.Dump()
assert.Len(t, dump.RtpObserverIds, 1)
})
t.Run(`AudioLevelObserver emits "routerclose" if Router is closed`, func(t *testing.T) {
// We need different Router and AudioLevelObserver instances here.
router2, _ := worker.CreateRouter(RouterOptions{MediaCodecs: mediaCodecs})
AudioLevelObserver2, _ := router2.CreateAudioLevelObserver()
onObserverNewRtpObserver := NewMockFunc(t)
AudioLevelObserver2.On("routerclose", onObserverNewRtpObserver.Fn())
router2.Close()
assert.Equal(t, 1, onObserverNewRtpObserver.CalledTimes())
assert.True(t, AudioLevelObserver2.Closed())
})
t.Run(`AudioLevelObserver emits "routerclose" if Worker is closed`, func(t *testing.T) {
onObserverNewRtpObserver := NewMockFunc(t)
AudioLevelObserver.On("routerclose", onObserverNewRtpObserver.Fn())
worker.Close()
assert.Equal(t, 1, onObserverNewRtpObserver.CalledTimes())
assert.True(t, AudioLevelObserver.Closed())
})
}