Skip to content

Commit

Permalink
Merge pull request #11 from THEOplayer/optimize-read-stream
Browse files Browse the repository at this point in the history
Optimize readStreamAsArrayBuffer
  • Loading branch information
tvanlaerhoven authored Oct 4, 2023
2 parents def90a0 + a89fb2f commit d07a3ae
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"rules": {
"max-len": ["error", { "code": 150, "ignoreComments": true, "ignoreStrings": true, "ignoreTemplateLiterals": true }],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-ts-comment": "off"
"@typescript-eslint/ban-ts-comment": "off",
"no-constant-condition": "warn"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AnvatoDrmFairplayContentProtectionIntegration implements ContentPro
return request;
}

onLicenseResponse?(response: LicenseResponse): MaybeAsync<BufferSource> {
onLicenseResponse(response: LicenseResponse): MaybeAsync<BufferSource> {
const responseObject = fromUint8ArrayToObject(response.body);
return fromBase64StringToUint8Array(responseObject.ckc);
}
Expand Down
10 changes: 3 additions & 7 deletions src/anvato/AnvatoDrmFairplayContentProtectionIntegration.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class AnvatoDrmFairplayContentProtectionIntegration implements ContentPro
}
}

onLicenseResponse?(response: LicenseResponse): MaybeAsync<BufferSource> {
onLicenseResponse(response: LicenseResponse): MaybeAsync<BufferSource> {
throw new AnvatoError('Error during FairPlay license request', 'Response already processed', response.url);
}

Expand All @@ -106,16 +106,12 @@ async function readStreamAsArrayBuffer(readable: ReadableStream<Uint8Array>): Pr
const chunks: Uint8Array[] = [];
let totalLength = 0;

async function readNextChunk() {
while (true) {

Check warning on line 109 in src/anvato/AnvatoDrmFairplayContentProtectionIntegration.web.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected constant condition
const { done, value } = await reader.read();
if (done) return;
if (done) break;
chunks.push(value);
totalLength += value.length;

// Read the next chunk
await readNextChunk();
}
await readNextChunk();

// Concatenate all chunks into a single Uint8Array
const result = new Uint8Array(totalLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AnvatoDrmWidevineContentProtectionIntegration implements ContentPro
return request;
}

onLicenseResponse?(response: LicenseResponse): MaybeAsync<BufferSource> {
onLicenseResponse(response: LicenseResponse): MaybeAsync<BufferSource> {
const responseObject = fromUint8ArrayToObject(response.body);
return fromBase64StringToUint8Array(responseObject.ckc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class VerimatrixCoreDrmFairplayContentProtectionIntegration implements Co
return request;
}

onLicenseResponse?(response: LicenseResponse): MaybeAsync<BufferSource> {
onLicenseResponse(response: LicenseResponse): MaybeAsync<BufferSource> {
const responseObject = fromUint8ArrayToObject(response.body);
return fromBase64StringToUint8Array(responseObject.ckc);
}
Expand Down

0 comments on commit d07a3ae

Please sign in to comment.