Skip to content

Commit

Permalink
fix(ServerAbrStream): validate server response
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Sep 19, 2024
1 parent 48ef9be commit e2e885b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core/ServerAbrStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,17 @@ export class ServerAbrStream extends EventEmitterLike {
const response = await this.fetchFunction(this.serverAbrStreamingUrl, { method: 'POST', body });
const data = await response.arrayBuffer();

if (response.status !== 200 || !data.byteLength)
throw new Error(`Received an invalid response from the server: ${response.status}`);

return this.parseUMPResponse(new Uint8Array(data));
}

/**
* Parses the UMP response data and updates the initialized formats.
* @param data - The UMP response data as a byte array.
* @param response - The UMP response data as a byte array.
*/
public async parseUMPResponse(data: Uint8Array): Promise<ServerAbrResponse> {
public async parseUMPResponse(response: Uint8Array): Promise<ServerAbrResponse> {
this.headerIdToFormatKeyMap.clear();

this.initializedFormats.forEach((format) => {
Expand All @@ -168,7 +171,7 @@ export class ServerAbrStream extends EventEmitterLike {
let sabrRedirect: SabrRedirect | undefined;
let streamProtectionStatus: StreamProtectionStatus | undefined;

const ump = new UMP(new ChunkedDataBuffer([ data ]));
const ump = new UMP(new ChunkedDataBuffer([ response ]));

ump.parse((part) => {
const data = part.data.chunks[0];
Expand Down

0 comments on commit e2e885b

Please sign in to comment.