|
@@ -0,0 +1,134 @@
|
|
1
|
+import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
|
|
2
|
+import Listenable from '../util/Listenable';
|
|
3
|
+import MediaSessionEvents from '../xmpp/MediaSessionEvents';
|
|
4
|
+
|
|
5
|
+import { QualityController } from './QualityController';
|
|
6
|
+
|
|
7
|
+// JSDocs disabled for Mock classes to avoid duplication - check on the original classes for info.
|
|
8
|
+/* eslint-disable require-jsdoc */
|
|
9
|
+/**
|
|
10
|
+ * A mock JingleSessionPC impl that fit the needs of the QualityController module.
|
|
11
|
+ * Should a generic, shared one exist in the future this test file should switch to use it too.
|
|
12
|
+ */
|
|
13
|
+class MockJingleSessionPC extends Listenable {
|
|
14
|
+ constructor() {
|
|
15
|
+ super();
|
|
16
|
+ this._remoteRecvMaxFrameHeight = undefined;
|
|
17
|
+ this.senderVideoConstraint = undefined;
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ getRemoteRecvMaxFrameHeight() {
|
|
21
|
+ return this._remoteRecvMaxFrameHeight;
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ // eslint-disable-next-line no-empty-function
|
|
25
|
+ setSenderVideoDegradationPreference() {
|
|
26
|
+
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ // eslint-disable-next-line no-empty-function
|
|
30
|
+ setSenderMaxBitrates() {
|
|
31
|
+
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ setSenderVideoConstraint(senderVideoConstraint) {
|
|
35
|
+ this.senderVideoConstraint = senderVideoConstraint;
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ setRemoteRecvMaxFrameHeight(remoteRecvMaxFrameHeight) {
|
|
39
|
+ this._remoteRecvMaxFrameHeight = remoteRecvMaxFrameHeight;
|
|
40
|
+ this.eventEmitter.emit(
|
|
41
|
+ MediaSessionEvents.REMOTE_VIDEO_CONSTRAINTS_CHANGED,
|
|
42
|
+ this);
|
|
43
|
+ }
|
|
44
|
+}
|
|
45
|
+
|
|
46
|
+/**
|
|
47
|
+ * Mock conference for the purpose of this test file.
|
|
48
|
+ */
|
|
49
|
+class MockConference extends Listenable {
|
|
50
|
+ /**
|
|
51
|
+ * A constructor...
|
|
52
|
+ */
|
|
53
|
+ constructor() {
|
|
54
|
+ super();
|
|
55
|
+ this.options = {
|
|
56
|
+ config: { }
|
|
57
|
+ };
|
|
58
|
+ this.activeMediaSession = undefined;
|
|
59
|
+ this.mediaSessions = [];
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ addMediaSession(mediaSession) {
|
|
63
|
+ this.mediaSessions.push(mediaSession);
|
|
64
|
+
|
|
65
|
+ this.eventEmitter.emit(JitsiConferenceEvents._MEDIA_SESSION_STARTED, mediaSession);
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ setActiveMediaSession(mediaSession) {
|
|
69
|
+ if (this.mediaSessions.indexOf(mediaSession) === -1) {
|
|
70
|
+ throw new Error('Given session is not part of this conference');
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ this.activeMediaSession = mediaSession;
|
|
74
|
+
|
|
75
|
+ this.eventEmitter.emit(JitsiConferenceEvents._MEDIA_SESSION_ACTIVE_CHANGED, this.activeMediaSession);
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ _getActiveMediaSession() {
|
|
79
|
+ return this.activeMediaSession;
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ _getMediaSessions() {
|
|
83
|
+ return this.mediaSessions;
|
|
84
|
+ }
|
|
85
|
+}
|
|
86
|
+/* eslint-enable require-jsdoc */
|
|
87
|
+
|
|
88
|
+describe('QualityController', () => {
|
|
89
|
+ let conference;
|
|
90
|
+ let qualityController;
|
|
91
|
+ let jvbConnection;
|
|
92
|
+ let p2pConnection;
|
|
93
|
+
|
|
94
|
+ beforeEach(() => {
|
|
95
|
+ conference = new MockConference();
|
|
96
|
+ qualityController = new QualityController(conference);
|
|
97
|
+ jvbConnection = new MockJingleSessionPC();
|
|
98
|
+ p2pConnection = new MockJingleSessionPC();
|
|
99
|
+
|
|
100
|
+ conference.addMediaSession(jvbConnection);
|
|
101
|
+ conference.addMediaSession(p2pConnection);
|
|
102
|
+ });
|
|
103
|
+ describe('handles 0 as receiver/sender video constraint', () => {
|
|
104
|
+ it('0 if it\'s the active sessions\'s remote recv constraint', () => {
|
|
105
|
+ jvbConnection.setRemoteRecvMaxFrameHeight(0);
|
|
106
|
+ p2pConnection.setRemoteRecvMaxFrameHeight(720);
|
|
107
|
+
|
|
108
|
+ conference.setActiveMediaSession(jvbConnection);
|
|
109
|
+
|
|
110
|
+ expect(jvbConnection.senderVideoConstraint).toBe(0);
|
|
111
|
+ expect(p2pConnection.senderVideoConstraint).toBe(0);
|
|
112
|
+ });
|
|
113
|
+ it('720 if 0 is set on the non-active session', () => {
|
|
114
|
+ jvbConnection.setRemoteRecvMaxFrameHeight(0);
|
|
115
|
+ p2pConnection.setRemoteRecvMaxFrameHeight(720);
|
|
116
|
+
|
|
117
|
+ conference.setActiveMediaSession(p2pConnection);
|
|
118
|
+
|
|
119
|
+ expect(jvbConnection.senderVideoConstraint).toBe(720);
|
|
120
|
+ expect(p2pConnection.senderVideoConstraint).toBe(720);
|
|
121
|
+ });
|
|
122
|
+ it('0 if it\'s the local send preference while remote are 720', () => {
|
|
123
|
+ conference.setActiveMediaSession(p2pConnection);
|
|
124
|
+
|
|
125
|
+ jvbConnection.setRemoteRecvMaxFrameHeight(720);
|
|
126
|
+ p2pConnection.setRemoteRecvMaxFrameHeight(720);
|
|
127
|
+
|
|
128
|
+ qualityController.setPreferredSendMaxFrameHeight(0);
|
|
129
|
+
|
|
130
|
+ expect(jvbConnection.senderVideoConstraint).toBe(0);
|
|
131
|
+ expect(p2pConnection.senderVideoConstraint).toBe(0);
|
|
132
|
+ });
|
|
133
|
+ });
|
|
134
|
+});
|