@@ -43,10 +43,11 @@ import NeedKey from '../vo/NeedKey.js';
43
43
import DashJSError from '../../vo/DashJSError.js' ;
44
44
import ProtectionErrors from '../errors/ProtectionErrors.js' ;
45
45
import KeyMessage from '../vo/KeyMessage.js' ;
46
- import KeySystemConfiguration from '../vo/KeySystemConfiguration.js' ;
47
- import KeySystemAccess from '../vo/KeySystemAccess.js' ;
48
46
import 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' ;
50
51
51
52
function ProtectionModel_3Feb2014 ( config ) {
52
53
@@ -105,68 +106,82 @@ function ProtectionModel_3Feb2014(config) {
105
106
}
106
107
107
108
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 {
163
115
const errorMessage = 'Key system access denied! -- No valid audio/video content configurations detected!' ;
164
116
eventBus . trigger ( events . KEY_SYSTEM_ACCESS_COMPLETE , { error : errorMessage } ) ;
165
- reject ( { error : errorMessage } ) ;
117
+ throw { error : errorMessage } ;
166
118
}
167
- } )
119
+ } ) ;
168
120
}
169
121
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
+
170
185
function selectKeySystem ( ksAccess ) {
171
186
return new Promise ( ( resolve , reject ) => {
172
187
try {
@@ -301,7 +316,7 @@ function ProtectionModel_3Feb2014(config) {
301
316
case api . needkey :
302
317
if ( event . initData ) {
303
318
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 ) } ) ;
305
320
}
306
321
break ;
307
322
}
0 commit comments