@@ -1119,23 +1119,9 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) {
11191119 * @private
11201120 */
11211121shaka . media . DrmEngine . prototype . unpackPlayReadyRequest_ = function ( request ) {
1122- // PlayReady CDMs in some clients (e.g. IE11, Edge) wrap the license message
1123- // in UTF-16 encoded XML which can't be directly delivered to a license
1124- // server. However, not all clients exhibit this behaviour. The Tizen
1125- // PlayReady CDM message is UTF-8 encoded and can be passed to the license
1126- // server as-is. Other CDMs do not seem to need this kind of special
1127- // handling.
1128- var xml = String . fromCharCode . apply ( null , new Uint8Array ( request . body ) ) ;
1129-
1130- if ( xml . indexOf ( '<PlayReadyKeyMessage' ) !== 0 ) {
1131- // The message is not wrapped.
1132- request . headers [ 'Content-Type' ] = 'text/xml; charset=utf-8' ;
1133- return ;
1134- }
1135-
1136- // The raw license message is UTF-16-encoded XML. We need to unpack the
1137- // Challenge element (base64-encoded string containing the actual license
1138- // request) and any HttpHeader elements (sent as request headers).
1122+ // On IE and Edge, the raw license message is UTF-16-encoded XML. We need to
1123+ // unpack the Challenge element (base64-encoded string containing the actual
1124+ // license request) and any HttpHeader elements (sent as request headers).
11391125
11401126 // Example XML:
11411127
@@ -1155,8 +1141,18 @@ shaka.media.DrmEngine.prototype.unpackPlayReadyRequest_ = function(request) {
11551141 // </LicenseAcquisition>
11561142 // </PlayReadyKeyMessage>
11571143
1158- xml = shaka . util . StringUtils . fromUTF16 (
1159- request . body , true /* littleEndian */ ) ;
1144+ var xml = shaka . util . StringUtils . fromUTF16 (
1145+ request . body , true /* littleEndian */ , true /* noThrow */ ) ;
1146+ if ( xml . indexOf ( 'PlayReadyKeyMessage' ) == - 1 ) {
1147+ // This does not appear to be a wrapped message as on IE and Edge. Some
1148+ // clients do not need this unwrapping, so we will assume this is one of
1149+ // them. Note that "xml" at this point probably looks like random garbage,
1150+ // since we interpreted UTF-8 as UTF-16.
1151+ shaka . log . debug ( 'PlayReady request is already unwrapped.' ) ;
1152+ request . headers [ 'Content-Type' ] = 'text/xml; charset=utf-8' ;
1153+ return ;
1154+ }
1155+ shaka . log . debug ( 'Unwrapping PlayReady request.' ) ;
11601156 var dom = new DOMParser ( ) . parseFromString ( xml , 'application/xml' ) ;
11611157
11621158 // Set request headers.
0 commit comments