@@ -43,10 +43,11 @@ import NeedKey from '../vo/NeedKey.js';
4343import DashJSError from '../../vo/DashJSError.js' ;
4444import ProtectionErrors from '../errors/ProtectionErrors.js' ;
4545import KeyMessage from '../vo/KeyMessage.js' ;
46- import KeySystemConfiguration from '../vo/KeySystemConfiguration.js' ;
47- import KeySystemAccess from '../vo/KeySystemAccess.js' ;
4846import FactoryMaker from '../../../core/FactoryMaker.js' ;
49- import ProtectionConstants from '../../constants/ProtectionConstants.js' ;
47+
48+ // imports from common-media-library
49+ import { getCompatibleKeySystemAccess } from '@svta/common-media-library/drm/key-system/getCompatibleKeySystemAccess.js' ;
50+ import { INITIALIZATION_DATA_TYPE } from '@svta/common-media-library/drm/common/const/INITIALIZATION_DATA_TYPE.js' ;
5051
5152function ProtectionModel_3Feb2014 ( config ) {
5253
@@ -105,68 +106,82 @@ function ProtectionModel_3Feb2014(config) {
105106 }
106107
107108 function requestKeySystemAccess ( ksConfigurations ) {
108- return new Promise ( ( resolve , reject ) => {
109- // Try key systems in order, first one with supported key system configuration
110- // is used
111- let found = false ;
112- for ( let ksIdx = 0 ; ksIdx < ksConfigurations . length ; ksIdx ++ ) {
113- const systemString = ksConfigurations [ ksIdx ] . ks . systemString ;
114- const configs = ksConfigurations [ ksIdx ] . configs ;
115- let supportedAudio = null ;
116- let supportedVideo = null ;
117-
118- // Try key system configs in order, first one with supported audio/video
119- // is used
120- for ( let configIdx = 0 ; configIdx < configs . length ; configIdx ++ ) {
121- const audios = configs [ configIdx ] . audioCapabilities ;
122- const videos = configs [ configIdx ] . videoCapabilities ;
123-
124- // Look for supported audio container/codecs
125- if ( audios && audios . length !== 0 ) {
126- supportedAudio = [ ] ; // Indicates that we have a requested audio config
127- for ( let audioIdx = 0 ; audioIdx < audios . length ; audioIdx ++ ) {
128- if ( window [ api . MediaKeys ] . isTypeSupported ( systemString , audios [ audioIdx ] . contentType ) ) {
129- supportedAudio . push ( audios [ audioIdx ] ) ;
130- }
131- }
132- }
133-
134- // Look for supported video container/codecs
135- if ( videos && videos . length !== 0 ) {
136- supportedVideo = [ ] ; // Indicates that we have a requested video config
137- for ( let videoIdx = 0 ; videoIdx < videos . length ; videoIdx ++ ) {
138- if ( window [ api . MediaKeys ] . isTypeSupported ( systemString , videos [ videoIdx ] . contentType ) ) {
139- supportedVideo . push ( videos [ videoIdx ] ) ;
140- }
141- }
142- }
143-
144- // No supported audio or video in this configuration OR we have
145- // requested audio or video configuration that is not supported
146- if ( ( ! supportedAudio && ! supportedVideo ) ||
147- ( supportedAudio && supportedAudio . length === 0 ) ||
148- ( supportedVideo && supportedVideo . length === 0 ) ) {
149- continue ;
150- }
151-
152- // This configuration is supported
153- found = true ;
154- const ksConfig = new KeySystemConfiguration ( supportedAudio , supportedVideo ) ;
155- const ks = protectionKeyController . getKeySystemBySystemString ( systemString ) ;
156- const keySystemAccess = new KeySystemAccess ( ks , ksConfig ) ;
157- eventBus . trigger ( events . KEY_SYSTEM_ACCESS_COMPLETE , { data : keySystemAccess } ) ;
158- resolve ( { data : keySystemAccess } ) ;
159- break ;
160- }
161- }
162- if ( ! found ) {
109+ return getCompatibleKeySystemAccess ( ksConfigurations ) . then ( ( keySystemAccess ) => {
110+ if ( keySystemAccess ) {
111+ eventBus . trigger ( events . KEY_SYSTEM_ACCESS_COMPLETE , { data : keySystemAccess } ) ;
112+ return { data : keySystemAccess } ;
113+ }
114+ else {
163115 const errorMessage = 'Key system access denied! -- No valid audio/video content configurations detected!' ;
164116 eventBus . trigger ( events . KEY_SYSTEM_ACCESS_COMPLETE , { error : errorMessage } ) ;
165- reject ( { error : errorMessage } ) ;
117+ throw { error : errorMessage } ;
166118 }
167- } )
119+ } ) ;
168120 }
169121
122+ // function requestKeySystemAccess(ksConfigurations) {
123+ // return new Promise((resolve, reject) => {
124+ // // Try key systems in order, first one with supported key system configuration
125+ // // is used
126+ // let found = false;
127+ // for (let ksIdx = 0; ksIdx < ksConfigurations.length; ksIdx++) {
128+ // const systemString = ksConfigurations[ksIdx].ks.systemString;
129+ // const configs = ksConfigurations[ksIdx].configs;
130+ // let supportedAudio = null;
131+ // let supportedVideo = null;
132+
133+ // // Try key system configs in order, first one with supported audio/video
134+ // // is used
135+ // for (let configIdx = 0; configIdx < configs.length; configIdx++) {
136+ // const audios = configs[configIdx].audioCapabilities;
137+ // const videos = configs[configIdx].videoCapabilities;
138+
139+ // // Look for supported audio container/codecs
140+ // if (audios && audios.length !== 0) {
141+ // supportedAudio = []; // Indicates that we have a requested audio config
142+ // for (let audioIdx = 0; audioIdx < audios.length; audioIdx++) {
143+ // if (window[api.MediaKeys].isTypeSupported(systemString, audios[audioIdx].contentType)) {
144+ // supportedAudio.push(audios[audioIdx]);
145+ // }
146+ // }
147+ // }
148+
149+ // // Look for supported video container/codecs
150+ // if (videos && videos.length !== 0) {
151+ // supportedVideo = []; // Indicates that we have a requested video config
152+ // for (let videoIdx = 0; videoIdx < videos.length; videoIdx++) {
153+ // if (window[api.MediaKeys].isTypeSupported(systemString, videos[videoIdx].contentType)) {
154+ // supportedVideo.push(videos[videoIdx]);
155+ // }
156+ // }
157+ // }
158+
159+ // // No supported audio or video in this configuration OR we have
160+ // // requested audio or video configuration that is not supported
161+ // if ((!supportedAudio && !supportedVideo) ||
162+ // (supportedAudio && supportedAudio.length === 0) ||
163+ // (supportedVideo && supportedVideo.length === 0)) {
164+ // continue;
165+ // }
166+
167+ // // This configuration is supported
168+ // found = true;
169+ // const ksConfig = new KeySystemConfiguration(supportedAudio, supportedVideo);
170+ // const ks = protectionKeyController.getKeySystemBySystemString(systemString);
171+ // const keySystemAccess = new KeySystemAccess(ks, ksConfig);
172+ // eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, { data: keySystemAccess });
173+ // resolve({ data: keySystemAccess });
174+ // break;
175+ // }
176+ // }
177+ // if (!found) {
178+ // const errorMessage = 'Key system access denied! -- No valid audio/video content configurations detected!';
179+ // eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, { error: errorMessage });
180+ // reject({ error: errorMessage });
181+ // }
182+ // })
183+ // }
184+
170185 function selectKeySystem ( ksAccess ) {
171186 return new Promise ( ( resolve , reject ) => {
172187 try {
@@ -301,7 +316,7 @@ function ProtectionModel_3Feb2014(config) {
301316 case api . needkey :
302317 if ( event . initData ) {
303318 const initData = ArrayBuffer . isView ( event . initData ) ? event . initData . buffer : event . initData ;
304- eventBus . trigger ( events . NEED_KEY , { key : new NeedKey ( initData , ProtectionConstants . INITIALIZATION_DATA_TYPE_CENC ) } ) ;
319+ eventBus . trigger ( events . NEED_KEY , { key : new NeedKey ( initData , INITIALIZATION_DATA_TYPE . CENC ) } ) ;
305320 }
306321 break ;
307322 }
0 commit comments