rx-player
Version:
Canal+ HTML5 Video Player
98 lines (97 loc) • 3.57 kB
JavaScript
;
/**
* Copyright 2015 CANAL+ Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = parseProtectionNode;
var base64_1 = require("../../../utils/base64");
var byte_parsing_1 = require("../../../utils/byte_parsing");
var string_parsing_1 = require("../../../utils/string_parsing");
var isobmff_1 = require("../../containers/isobmff");
/**
* @param {Uint8Array} keyIdBytes
* @returns {Array.<Object>}
*/
function createWidevineKeySystem(keyIdBytes) {
return [
{
systemId: "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed", // Widevine
privateData: (0, byte_parsing_1.concat)([0x08, 0x01, 0x12, 0x10], keyIdBytes),
},
];
}
/**
* Parse "Protection" Node, which contains DRM information
* @param {Object} protectionNode
* @returns {Object}
*/
function parseProtectionNode(protectionNode, keySystemCreator) {
var e_1, _a;
var _b;
if (keySystemCreator === void 0) { keySystemCreator = createWidevineKeySystem; }
var header;
try {
for (var _c = __values(protectionNode.children), _d = _c.next(); !_d.done; _d = _c.next()) {
var subNode = _d.value;
if (typeof subNode === "string") {
continue;
}
if (subNode.tagName === "ProtectionHeader") {
header = subNode;
break;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
if (header === undefined) {
throw new Error("Protection should have ProtectionHeader child");
}
var privateData = (0, base64_1.base64ToBytes)(typeof header.children[0] === "string" ? header.children[0] : "");
var keyIdHex = (0, isobmff_1.getPlayReadyKIDFromPrivateData)(privateData);
var keyIdBytes = (0, string_parsing_1.hexToBytes)(keyIdHex);
// remove possible braces
var systemIdAttr = (_b = header.attributes.SystemID) !== null && _b !== void 0 ? _b : null;
var systemId = (systemIdAttr !== null ? systemIdAttr : "")
.toLowerCase()
.replace(/\{|\}/g, "");
var supplementaryKeySystems = keySystemCreator(keyIdBytes);
return {
keyId: keyIdBytes,
keySystems: [
{
systemId: systemId,
privateData: privateData,
/* keyIds: [keyIdBytes], */
},
].concat(supplementaryKeySystems),
};
}