Skip to content

Commit 842cf17

Browse files
ceyhun-otvanlaerhoven
authored andcommitted
Handle fetching a persistent license on FairPlay for caching
1 parent 0483ad0 commit 842cf17

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

drm/src/castlabs/CastLabsFairplayContentProtectionIntegration.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,29 @@ export class CastLabsFairplayContentProtectionIntegration implements ContentProt
3636
}
3737

3838
onLicenseRequest(request: LicenseRequest): MaybeAsync<Partial<LicenseRequest> | BufferSource> {
39-
request.url =
39+
const isOffline = this.contentProtectionConfiguration.fairplay?.licenseType === 'persistent';
40+
41+
let licenseUrl =
4042
this.contentProtectionConfiguration.fairplay?.licenseAcquisitionURL ?? CastLabsFairplayContentProtectionIntegration.DEFAULT_LICENSE_URL;
43+
44+
// Add offline parameter for persistent license / caching support
45+
if (isOffline) {
46+
const urlSeparator = licenseUrl.includes('?') ? '&' : '?';
47+
licenseUrl = `${licenseUrl}${urlSeparator}offline=true`;
48+
}
49+
50+
request.url = licenseUrl;
4151
request.headers = {
4252
...request.headers,
4353
'x-dt-custom-data': this.customData!,
4454
'x-dt-auth-token': this.contentProtectionConfiguration.integrationParameters.token ?? '',
4555
'content-type': 'application/x-www-form-urlencoded',
4656
};
47-
const body = `spc=${encodeURIComponent(fromUint8ArrayToBase64String(request.body!))}&${encodeURIComponent(this.contentId!)}`;
57+
const spcEncoded = encodeURIComponent(fromUint8ArrayToBase64String(request.body!));
58+
let body = `spc=${spcEncoded}&${encodeURIComponent(this.contentId!)}`;
59+
if (isOffline) {
60+
body += '&offline=true';
61+
}
4862
request.body = fromStringToUint8Array(body);
4963

5064
return request;

0 commit comments

Comments
 (0)