1
1
import type { IEmeManager , IEmeManagerDependencies , IKeySessionMetadata } from '../types/eme-manager.declarations' ;
2
2
import type { INetworkManager } from '../types/network.declarations' ;
3
3
import type { ILogger } from '../types/logger.declarations' ;
4
- import type { IPlayerSource } from '../types/source.declarations' ;
4
+ import type { IKeySystemConfig , IPlayerSource } from '../types/source.declarations' ;
5
5
import type { IEventEmitter } from '../types/event-emitter.declarations' ;
6
6
import type {
7
7
EventTypeToEventMap ,
@@ -166,7 +166,7 @@ export class EmeManager implements IEmeManager {
166
166
this . privateEventEmitter_ . addEventListener ( PlayerEventType . DashManifestParsed , this . handleParsedManifestEvent_ ) ;
167
167
}
168
168
169
- private getKeySystemConfig_ ( ) : Record < string , MediaKeySystemConfiguration > {
169
+ private getMediaKeySystemConfig_ ( ) : Record < string , MediaKeySystemConfiguration > {
170
170
// TODO: Write logic to get this info from manifests and segment data
171
171
// We will probably need to pass in a list of key systems
172
172
@@ -225,16 +225,35 @@ export class EmeManager implements IEmeManager {
225
225
return mediaKeySystemAccess ;
226
226
}
227
227
228
- // TODO: Sort by priority before this
228
+ // Sort key systems by priority
229
+ const keySystemsArray = Object . keys ( keySystems ) . map ( ( key ) => [ key , keySystems [ key ] ] ) ;
229
230
230
- for ( const keySystem in keySystems ) {
231
- const keySystemConfig = this . getKeySystemConfig_ ( ) ;
231
+ keySystemsArray . sort ( ( a , b ) => {
232
+ const keySystemPriorityA = ( a [ 1 ] as IKeySystemConfig ) . priority ;
233
+ const keySystemPriorityB = ( b [ 1 ] as IKeySystemConfig ) . priority ;
234
+
235
+ if ( ! keySystemPriorityA && ! keySystemPriorityB ) {
236
+ return 0 ;
237
+ } else if ( ! keySystemPriorityA ) {
238
+ return 1 ;
239
+ } else if ( ! keySystemPriorityB ) {
240
+ return - 1 ;
241
+ }
242
+
243
+ return keySystemPriorityA - keySystemPriorityB ;
244
+ } ) ;
245
+
246
+ keySystemsArray . forEach ( async ( keySystemArr ) => {
247
+ const keySystem = keySystemArr [ 0 ] as string ;
248
+ // const keySystemConfig = keySystemArr[1] as IKeySystemConfig;
249
+ // TODO: Pass in key system info
250
+ const mediaKeySystemConfig = this . getMediaKeySystemConfig_ ( ) ;
232
251
233
252
try {
234
253
this . eventEmitter_ . emitEvent ( new KeySystemAccessRequestedEvent ( keySystem ) ) ;
235
254
this . logger_ . debug ( 'EME: Requesting media key system access.' ) ;
236
255
237
- mediaKeySystemAccess = await navigator . requestMediaKeySystemAccess ( keySystem , [ keySystemConfig ] ) ;
256
+ mediaKeySystemAccess = await navigator . requestMediaKeySystemAccess ( keySystem , [ mediaKeySystemConfig ] ) ;
238
257
239
258
return mediaKeySystemAccess ;
240
259
} catch ( error ) {
@@ -243,7 +262,7 @@ export class EmeManager implements IEmeManager {
243
262
`EME: Media key system access request failed. Key System: ${ keySystem } Error: ${ error as Error } `
244
263
) ;
245
264
}
246
- }
265
+ } ) ;
247
266
248
267
return mediaKeySystemAccess ;
249
268
}
0 commit comments