Skip to content

Commit

Permalink
chore: move eme errors (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
wseymour15 committed Apr 23, 2024
1 parent cddc25e commit 1a000bc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
14 changes: 14 additions & 0 deletions src/consts/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Error = {
EMEFailedToRequestMediaKeySystemAccess: 'eme-failed-request-media-key-system-access',
EMEFailedToCreateMediaKeys: 'eme-failed-create-media-keys',
EMEFailedToAttachMediaKeysToVideoElement: 'eme-failed-attach-media-keys-to-video',
EMEFailedToCreateMediaKeySession: 'eme-failed-create-media-key-session',
EMEFailedToSetServerCertificate: 'eme-failed-set-server-certificate',
EMEFailedToGenerateLicenseRequest: 'eme-failed-generate-license-request',
EMEFailedToUpdateSessionWithReceivedLicenseKeys: 'eme-failed-update-session',
EMEFailedToCloseSession: 'eme-failed-close-session',
EMEFailedToRemoveKeysFromSession: 'eme-failed-remove-keys',
EMEFailedToLoadSessionBySessionId: 'eme-failed-load-session'
};

export default Error;
17 changes: 9 additions & 8 deletions src/eme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
defaultGetLicense as defaultFairplayGetLicense,
defaultGetContentId as defaultFairplayGetContentId
} from './fairplay';
import EmeError from './consts/errors';

const isFairplayKeySystem = (str) => str.startsWith('com.apple.fps');

Expand Down Expand Up @@ -122,7 +123,7 @@ export const makeNewRequest = (player, requestOptions) => {
});
}).catch((error) => {
const metadata = {
errorType: videojs.Error.EMEFailedToCloseSession,
errorType: EmeError.EMEFailedToCloseSession,
keySystem
};

Expand Down Expand Up @@ -150,7 +151,7 @@ export const makeNewRequest = (player, requestOptions) => {
});
}).catch((error) => {
const metadata = {
errorType: videojs.Error.EMEFailedToUpdateSessionWithReceivedLicenseKeys,
errorType: EmeError.EMEFailedToUpdateSessionWithReceivedLicenseKeys,
keySystem
};

Expand Down Expand Up @@ -217,7 +218,7 @@ export const makeNewRequest = (player, requestOptions) => {
makeNewRequest(player, requestOptions);
}).catch((error) => {
const metadata = {
errorType: videojs.Error.EMEFailedToCloseSession,
errorType: EmeError.EMEFailedToCloseSession,
keySystem
};

Expand All @@ -228,7 +229,7 @@ export const makeNewRequest = (player, requestOptions) => {

keySession.generateRequest(initDataType, initData).catch((error) => {
const metadata = {
errorType: videojs.Error.EMEFailedToGenerateLicenseRequest,
errorType: EmeError.EMEFailedToGenerateLicenseRequest,
keySystem
};

Expand All @@ -239,7 +240,7 @@ export const makeNewRequest = (player, requestOptions) => {

} catch (error) {
const metadata = {
errorType: videojs.Error.EMEFailedToCreateMediaKeySession,
errorType: EmeError.EMEFailedToCreateMediaKeySession,
keySystem
};

Expand Down Expand Up @@ -342,7 +343,7 @@ export const addPendingSessions = ({
if (certificate) {
promises.push(createdMediaKeys.setServerCertificate(certificate).catch((error) => {
const metadata = {
errorType: videojs.Error.EMEFailedToSetServerCertificate,
errorType: EmeError.EMEFailedToSetServerCertificate,
keySystem: video.keySystem
};

Expand Down Expand Up @@ -371,7 +372,7 @@ export const addPendingSessions = ({

promises.push(video.setMediaKeys(createdMediaKeys).catch((error) => {
const metadata = {
errorType: videojs.Error.EMEFailedToAttachMediaKeysToVideoElement,
errorType: EmeError.EMEFailedToAttachMediaKeysToVideoElement,
keySystem: video.keySystem
};

Expand Down Expand Up @@ -538,7 +539,7 @@ export const standard5July2016 = ({
});
}).catch((err) => {
const metadata = {
errorType: videojs.Error.EMEFailedToCreateMediaKeys,
errorType: EmeError.EMEFailedToCreateMediaKeys,
keySystem
};

Expand Down
11 changes: 6 additions & 5 deletions src/fairplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import videojs from 'video.js';
import window from 'global/window';
import {stringToUint16Array, uint16ArrayToString, getHostnameFromUri, mergeAndRemoveNull} from './utils';
import {httpResponseHandler} from './http-handler.js';
import EmeError from './consts/errors';

export const LEGACY_FAIRPLAY_KEY_SYSTEM = 'com.apple.fps.1_0';

Expand Down Expand Up @@ -56,7 +57,7 @@ const addKey = ({video, contentId, initData, cert, options, getLicense, eventBus
video.webkitSetMediaKeys(new window.WebKitMediaKeys(LEGACY_FAIRPLAY_KEY_SYSTEM));
} catch (error) {
const metadata = {
errorType: videojs.Error.EMEFailedToCreateMediaKeys,
errorType: EmeError.EMEFailedToCreateMediaKeys,
keySystem: LEGACY_FAIRPLAY_KEY_SYSTEM
};

Expand All @@ -75,7 +76,7 @@ const addKey = ({video, contentId, initData, cert, options, getLicense, eventBus
);
} catch (error) {
const metadata = {
errorType: videojs.Error.EMEFailedToCreateMediaKeySession,
errorType: EmeError.EMEFailedToCreateMediaKeySession,
keySystem: LEGACY_FAIRPLAY_KEY_SYSTEM
};

Expand All @@ -102,7 +103,7 @@ const addKey = ({video, contentId, initData, cert, options, getLicense, eventBus
}
if (err) {
const metadata = {
errortype: videojs.Error.EMEFailedToGenerateLicenseRequest,
errortype: EmeError.EMEFailedToGenerateLicenseRequest,
keySystem: LEGACY_FAIRPLAY_KEY_SYSTEM
};

Expand All @@ -128,7 +129,7 @@ const addKey = ({video, contentId, initData, cert, options, getLicense, eventBus
keySession.addEventListener('webkitkeyerror', () => {
const error = keySession.error;
const metadata = {
errorType: videojs.Error.EMEFailedToUpdateSessionWithReceivedLicenseKeys,
errorType: EmeError.EMEFailedToUpdateSessionWithReceivedLicenseKeys,
keySystem: LEGACY_FAIRPLAY_KEY_SYSTEM
};

Expand Down Expand Up @@ -199,7 +200,7 @@ const fairplay = ({video, initData, options, eventBus, emeError}) => {
getCertificate(options, (err, cert) => {
if (err) {
const metadata = {
errorType: videojs.Error.EMEFailedToSetServerCertificate,
errorType: EmeError.EMEFailedToSetServerCertificate,
keySystem: LEGACY_FAIRPLAY_KEY_SYSTEM
};

Expand Down
12 changes: 6 additions & 6 deletions src/ms-prefixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
import window from 'global/window';
import { requestPlayreadyLicense } from './playready';
import videojs from 'video.js';
import { getMediaKeySystemConfigurations } from './utils';
import EmeError from './consts/errors';

export const PLAYREADY_KEY_SYSTEM = 'com.microsoft.playready';

Expand All @@ -20,7 +20,7 @@ export const addKeyToSession = (options, session, event, eventBus, emeError) =>
playreadyOptions.getKey(options, event.destinationURL, event.message.buffer, (err, key) => {
if (err) {
const metadata = {
errorType: videojs.Error.EMEFailedToRequestMediaKeySystemAccess,
errorType: EmeError.EMEFailedToRequestMediaKeySystemAccess,
config: getMediaKeySystemConfigurations(options.keySystems)
};

Expand Down Expand Up @@ -60,7 +60,7 @@ export const addKeyToSession = (options, session, event, eventBus, emeError) =>

if (err) {
const metadata = {
errorType: videojs.Error.EMEFailedToGenerateLicenseRequest,
errorType: EmeError.EMEFailedToGenerateLicenseRequest,
keySystem: PLAYREADY_KEY_SYSTEM
};

Expand Down Expand Up @@ -90,7 +90,7 @@ export const createSession = (video, initData, options, eventBus, emeError) => {
if (!session) {
const error = new Error('Could not create key session.');
const metadata = {
errorType: videojs.Error.EMEFailedToCreateMediaKeySession,
errorType: EmeError.EMEFailedToCreateMediaKeySession,
keySystem: PLAYREADY_KEY_SYSTEM
};

Expand Down Expand Up @@ -122,7 +122,7 @@ export const createSession = (video, initData, options, eventBus, emeError) => {

session.addEventListener('mskeyerror', (event) => {
const metadata = {
errorType: videojs.Error.EMEFailedToCreateMediaKeySession,
errorType: EmeError.EMEFailedToCreateMediaKeySession,
keySystem: PLAYREADY_KEY_SYSTEM
};

Expand Down Expand Up @@ -157,7 +157,7 @@ export default ({video, initData, options, eventBus, emeError}) => {
video.msSetMediaKeys(new window.MSMediaKeys(PLAYREADY_KEY_SYSTEM));
} catch (e) {
const metadata = {
errorType: videojs.Error.EMEFailedToCreateMediaKeys,
errorType: EmeError.EMEFailedToCreateMediaKeys,
keySystem: PLAYREADY_KEY_SYSTEM
};

Expand Down
6 changes: 5 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {detectSupportedCDMs } from './cdm.js';
import { arrayBuffersEqual, arrayBufferFrom, merge, getMediaKeySystemConfigurations } from './utils';
import {version as VERSION} from '../package.json';
import EmeError from './consts/errors';

export const hasSession = (sessions, initData) => {
for (let i = 0; i < sessions.length; i++) {
Expand Down Expand Up @@ -102,7 +103,7 @@ export const handleEncryptedEvent = (player, event, options, sessions, eventBus,
});
}).catch((error) => {
const metadata = {
errorType: videojs.Error.EMEFailedToRequestMediaKeySystemAccess,
errorType: EmeError.EMEFailedToRequestMediaKeySystemAccess,
config: getMediaKeySystemConfigurations(options.keySystems)
};

Expand Down Expand Up @@ -436,6 +437,9 @@ const eme = function(options = {}) {
// Register the plugin with video.js.
videojs.registerPlugin('eme', eme);

// contrib-eme specific error const
eme.Error = EmeError;

// Include the version number.
eme.VERSION = VERSION;

Expand Down

0 comments on commit 1a000bc

Please sign in to comment.