6
6
7
7
import { ConferenceClient } from '../../../../src/sdk/conference/client.js' ;
8
8
import { ConferencePeerConnectionChannel } from '../../../../src/sdk/conference/channel.js' ;
9
- import * as StreamModule from '../../../../src/sdk/base/stream.js' ;
10
9
import * as EventModule from '../../../../src/sdk/base/event.js'
10
+ import * as StreamUtils from '../../../../src/sdk/conference/streamutils.js' ;
11
11
import * as SubscriptionModule from '../../../../src/sdk/conference/subscription.js'
12
- import { TransportSettings , TransportType } from '../../../../src/sdk/base/transport.js' ;
12
+ import { TransportSettings , TransportType } from '../../../../src/sdk/base/transport.js' ;
13
13
14
14
const expect = chai . expect ;
15
15
chai . use ( chaiAsPromised ) ;
16
16
17
17
describe ( 'Unit tests for ConferenceClient' , function ( ) {
18
18
describe ( 'Create a ConferenceClient.' , function ( ) {
19
- it (
20
- 'Create a ConferenceClient with or without configuration should success.' ,
21
- done => {
22
- let confclient = new ConferenceClient ( { } ) ;
23
- expect ( confclient ) . to . be . an . instanceof ( EventModule . EventDispatcher ) ;
24
- confclient = new ConferenceClient ( { } ) ;
25
- expect ( confclient ) . to . be . an . instanceof ( EventModule . EventDispatcher ) ;
26
- done ( ) ;
27
- } ) ;
19
+ it ( 'Create a ConferenceClient with or without configuration should success.' ,
20
+ done => {
21
+ let confclient = new ConferenceClient ( { } ) ;
22
+ expect ( confclient ) . to . be . an . instanceof ( EventModule . EventDispatcher ) ;
23
+ confclient = new ConferenceClient ( { } ) ;
24
+ expect ( confclient ) . to . be . an . instanceof ( EventModule . EventDispatcher ) ;
25
+ done ( ) ;
26
+ } ) ;
28
27
29
28
it ( 'Event should be fired on correct target.' , done => {
30
29
let conf1 = new ConferenceClient ( { } ) ;
@@ -109,4 +108,162 @@ describe('Unit tests for Subscription.', () => {
109
108
'sessionId' , undefined , transportSettings ) ;
110
109
expect ( subscription . transport ) . to . equal ( transportSettings ) ;
111
110
} ) ;
111
+ } ) ;
112
+
113
+ describe ( 'Unit tests for StreamUtils.' , ( ) => {
114
+ it ( 'Convert server messages to subscription capabilities.' , ( ) => {
115
+ const messages = [
116
+ [
117
+ {
118
+ 'tracks' : [
119
+ {
120
+ 'id' : '35951ba82cf14a8cb0348ab64517fb80-2' ,
121
+ 'type' : 'audio' ,
122
+ 'source' : 'mic' ,
123
+ 'format' : { 'channelNum' : 2 , 'sampleRate' : 48000 , 'codec' : 'opus' } ,
124
+ 'optional' : {
125
+ 'format' : [
126
+ { 'sampleRate' : 16000 , 'codec' : 'isac' } ,
127
+ { 'sampleRate' : 32000 , 'codec' : 'isac' } ,
128
+ { 'channelNum' : 1 , 'sampleRate' : 16000 , 'codec' : 'g722' } ,
129
+ { 'codec' : 'pcma' } , { 'codec' : 'pcmu' } ,
130
+ { 'channelNum' : 2 , 'sampleRate' : 48000 , 'codec' : 'aac' } ,
131
+ { 'codec' : 'ac3' } , { 'codec' : 'nellymoser' } , { 'codec' : 'ilbc' }
132
+ ]
133
+ } ,
134
+ 'status' : 'active' ,
135
+ 'mid' : '2'
136
+ } ,
137
+ {
138
+ 'id' : '35951ba82cf14a8cb0348ab64517fb80-3' ,
139
+ 'type' : 'video' ,
140
+ 'source' : 'camera' ,
141
+ 'format' : { 'codec' : 'vp8' } ,
142
+ 'optional' : {
143
+ 'format' : [
144
+ { 'profile' : 'CB' , 'codec' : 'h264' } ,
145
+ { 'profile' : 'B' , 'codec' : 'h264' } , { 'codec' : 'vp9' }
146
+ ] ,
147
+ 'parameters' : {
148
+ 'resolution' : [
149
+ { 'width' : 480 , 'height' : 360 } ,
150
+ { 'width' : 426 , 'height' : 320 } ,
151
+ { 'width' : 320 , 'height' : 240 } ,
152
+ { 'width' : 212 , 'height' : 160 } ,
153
+ { 'width' : 160 , 'height' : 120 } , { 'width' : 352 , 'height' : 288 }
154
+ ] ,
155
+ 'bitrate' : [ 'x0.8' , 'x0.6' , 'x0.4' , 'x0.2' ] ,
156
+ 'framerate' : [ 6 , 12 , 15 , 24 ] ,
157
+ 'keyFrameInterval' : [ 100 , 30 , 5 , 2 , 1 ]
158
+ }
159
+ } ,
160
+ 'status' : 'active' ,
161
+ 'mid' : '3'
162
+ }
163
+ ]
164
+ } ,
165
+ {
166
+ 'audio' : {
167
+ 'codecs' : [
168
+ { 'name' : 'isac' , 'clockRate' : 16000 } ,
169
+ { 'name' : 'isac' , 'clockRate' : 32000 } ,
170
+ { 'name' : 'g722' , 'channelCount' : 1 , 'clockRate' : 16000 } ,
171
+ { 'name' : 'pcma' } , { 'name' : 'pcmu' } ,
172
+ { 'name' : 'aac' , 'channelCount' : 2 , 'clockRate' : 48000 } ,
173
+ { 'name' : 'ac3' } , { 'name' : 'nellymoser' } , { 'name' : 'ilbc' }
174
+ ]
175
+ } ,
176
+ 'video' : {
177
+ 'codecs' : [
178
+ { 'name' : 'h264' , 'profile' : 'CB' } ,
179
+ { 'name' : 'h264' , 'profile' : 'B' } , { 'name' : 'vp9' }
180
+ ] ,
181
+ 'resolutions' : [
182
+ { 'width' : 160 , 'height' : 120 } , { 'width' : 212 , 'height' : 160 } ,
183
+ { 'width' : 320 , 'height' : 240 } , { 'width' : 352 , 'height' : 288 } ,
184
+ { 'width' : 426 , 'height' : 320 } , { 'width' : 480 , 'height' : 360 }
185
+ ] ,
186
+ 'frameRates' : [ 6 , 12 , 15 , 24 ] ,
187
+ 'bitrateMultipliers' : [ 0.2 , 0.4 , 0.6 , 0.8 , 1 ] ,
188
+ 'keyFrameIntervals' : [ 1 , 2 , 5 , 30 , 100 ]
189
+ }
190
+ }
191
+ ] ,
192
+ [
193
+ // Audio only.
194
+ {
195
+ 'tracks' : [ {
196
+ 'id' : '35951ba82cf14a8cb0348ab64517fb80-2' ,
197
+ 'type' : 'audio' ,
198
+ 'source' : 'mic' ,
199
+ 'format' : { 'channelNum' : 2 , 'sampleRate' : 48000 , 'codec' : 'opus' } ,
200
+ 'optional' : {
201
+ 'format' : [
202
+ { 'sampleRate' : 16000 , 'codec' : 'isac' } ,
203
+ { 'sampleRate' : 32000 , 'codec' : 'isac' } ,
204
+ { 'channelNum' : 1 , 'sampleRate' : 16000 , 'codec' : 'g722' } ,
205
+ { 'codec' : 'pcma' } , { 'codec' : 'pcmu' } ,
206
+ { 'channelNum' : 2 , 'sampleRate' : 48000 , 'codec' : 'aac' } ,
207
+ { 'codec' : 'ac3' } , { 'codec' : 'nellymoser' } , { 'codec' : 'ilbc' }
208
+ ]
209
+ } ,
210
+ 'status' : 'active' ,
211
+ 'mid' : '2'
212
+ } ]
213
+ } ,
214
+ {
215
+ 'audio' : {
216
+ 'codecs' : [
217
+ { 'name' : 'isac' , 'clockRate' : 16000 } ,
218
+ { 'name' : 'isac' , 'clockRate' : 32000 } ,
219
+ { 'name' : 'g722' , 'channelCount' : 1 , 'clockRate' : 16000 } ,
220
+ { 'name' : 'pcma' } , { 'name' : 'pcmu' } ,
221
+ { 'name' : 'aac' , 'channelCount' : 2 , 'clockRate' : 48000 } ,
222
+ { 'name' : 'ac3' } , { 'name' : 'nellymoser' } , { 'name' : 'ilbc' }
223
+ ]
224
+ }
225
+ }
226
+ ] ,
227
+ [
228
+ // Transcoding is disabled.
229
+ {
230
+ 'tracks' : [
231
+ {
232
+ 'type' : 'audio' ,
233
+ 'format' : { 'codec' : 'opus' , 'sampleRate' : 48000 , 'channelNum' : 2 } ,
234
+ 'optional' : { } ,
235
+ 'status' : 'active'
236
+ } ,
237
+ {
238
+ 'type' : 'video' ,
239
+ 'format' : { 'codec' : 'vp8' } ,
240
+ 'parameters' : {
241
+ 'resolution' : { 'width' : 640 , 'height' : 480 } ,
242
+ 'framerate' : 24 ,
243
+ 'keyFrameInterval' : 100
244
+ } ,
245
+ 'optional' : { } ,
246
+ 'status' : 'active'
247
+ }
248
+ ]
249
+ } ,
250
+ {
251
+ 'audio' : { 'codecs' : [ ] } ,
252
+ 'video' : {
253
+ 'codecs' : [ ] ,
254
+ 'resolutions' : [ ] ,
255
+ 'frameRates' : [ ] ,
256
+ 'bitrateMultipliers' : [ ] ,
257
+ 'keyFrameIntervals' : [ ]
258
+ }
259
+ }
260
+ ]
261
+ ] ;
262
+ for ( const [ message , capabilities ] of messages ) {
263
+ // Stringify to avoid type comparison.
264
+ expect ( JSON . stringify (
265
+ StreamUtils . convertToSubscriptionCapabilities ( message ) ) )
266
+ . to . equal ( JSON . stringify ( capabilities ) ) ;
267
+ }
268
+ } ) ;
112
269
} ) ;
0 commit comments