Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pallycon #13

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ the following connectors, readily available to be used by `react-native-theoplay
| EZDRM | ✓ (*) | ✓ (*) | ✓ |
| Verimatrix MultiDRM Core DRM | ✓ | ✓ | ✓ |
| Anvato | ✓ | ✗ | ✓ |
| PallyCon | ✗ | ✗ | ✓ |

(*) No connector is needed for these DRM vendors; it is handled by the player's default DRM flow.
26 changes: 26 additions & 0 deletions src/pallycon/PallyConConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { DRMConfiguration } from 'react-native-theoplayer';

/**
* The identifier of the PallyCon integration.
*/
export type PallyConIntegrationID = 'pallycon';

/**
* Describes the configuration of the PallyCon DRM integration.
*
* ```
* const drmConfiguration = {
* integration : 'pallycon',
* fairplay: {
* certificateURL: 'yourPallyConCertificateUrl',
* licenseAcquisitionURL: 'yourPallyConLicenseAcquisitionURL'
* }
* }
* ```
*/
export interface PallyConDrmConfiguration extends DRMConfiguration {
/**
* The identifier of the DRM integration.
*/
integration: PallyConIntegrationID;
}
41 changes: 41 additions & 0 deletions src/pallycon/PallyConFairplayContentProtectionIntegration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { ContentProtectionIntegration, LicenseRequest, LicenseResponse, MaybeAsync } from 'react-native-theoplayer';
import type { PallyConDrmConfiguration } from './PallyConConfiguration';
import { fromBase64StringToUint8Array, fromStringToUint8Array, fromUint8ArrayToBase64String, fromUint8ArrayToString } from "react-native-theoplayer";

export class PallyConFairplayContentProtectionIntegration implements ContentProtectionIntegration {
static readonly DEFAULT_LICENSE_URL = 'https://license-global.pallycon.com/ri/licenseManager.do';

private readonly contentProtectionConfiguration: PallyConDrmConfiguration;
private contentId: string | undefined = undefined;

constructor(configuration: PallyConDrmConfiguration) {
this.contentProtectionConfiguration = configuration;
}

onLicenseRequest(request: LicenseRequest): MaybeAsync<Partial<LicenseRequest> | BufferSource> {
if (!this.contentProtectionConfiguration.fairplay?.licenseAcquisitionURL) {
throw new Error('The FairPlay PallyCon license url has not been correctly configured.');
}
request.url = this.contentProtectionConfiguration.fairplay?.licenseAcquisitionURL;
request.headers = {
...request.headers,
...this.contentProtectionConfiguration.fairplay?.headers
};
if (!this.contentId) {
throw new Error('The FairPlay PallyCon content ID has not been correctly configured.');
}
const licenseParameters = `spc=${encodeURIComponent(fromUint8ArrayToBase64String(request.body!))}&assetId=${encodeURIComponent(this.contentId)}`;

Check warning on line 27 in src/pallycon/PallyConFairplayContentProtectionIntegration.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion
request.body = fromStringToUint8Array(licenseParameters);
return request;
}

onLicenseResponse?(response: LicenseResponse): MaybeAsync<BufferSource> {
return fromBase64StringToUint8Array(fromUint8ArrayToString(response.body));
}

extractFairplayContentId(skdUrl: string): string {
// drop the 'skd://' part
this.contentId = skdUrl.substring(6, skdUrl.length);
return this.contentId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ContentProtectionIntegration, ContentProtectionIntegrationFactory } from 'react-native-theoplayer';
import type { PallyConDrmConfiguration } from './PallyConConfiguration';
import { PallyConFairplayContentProtectionIntegration } from './PallyConFairplayContentProtectionIntegration';

export class PallyConFairplayContentProtectionIntegrationFactory implements ContentProtectionIntegrationFactory {
build(configuration: PallyConDrmConfiguration): ContentProtectionIntegration {
return new PallyConFairplayContentProtectionIntegration(configuration);
}
}
Loading