From 95d3aa521c3cc216de4a56bcc2a2ab737e727b02 Mon Sep 17 00:00:00 2001 From: MathieuPoux Date: Wed, 25 Sep 2024 18:23:38 +0200 Subject: [PATCH] fix(StreamMetadata): add 2 checks on attribute to tolerate their absence --- src/metadata/StreamMetadata.ts | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/metadata/StreamMetadata.ts b/src/metadata/StreamMetadata.ts index 29a6735..6922cd6 100644 --- a/src/metadata/StreamMetadata.ts +++ b/src/metadata/StreamMetadata.ts @@ -141,31 +141,33 @@ export class StreamMetadata extends EventEmitter { this._metadata.height = data.height; this._metadata.sources.clear(); - for (const source of data.source) { + for (const source of data.source || []) { this._metadata.sources.set(source.hrn, source); } const tracks = []; this._metadata.tracks.clear(); - for (const [name, track] of Util.objectEntries(data.meta.tracks)) { - track.name = name; - track.type = track.type.toLowerCase(); - switch (track.type) { - case 'audio': - this._metadata.audios.push(track); - continue; - case 'video': - this._metadata.videos.push(track); - continue; - case 'meta': - track.type = MType.DATA; // Fix meta string to explicit DATA type - this._metadata.datas.push(track); - break; - default: - this.log(`Unknown track type ${track.type}`).warn(); + if (data.meta?.tracks) { + for (const [name, track] of Util.objectEntries(data.meta.tracks)) { + track.name = name; + track.type = track.type.toLowerCase(); + switch (track.type) { + case 'audio': + this._metadata.audios.push(track); + continue; + case 'video': + this._metadata.videos.push(track); + continue; + case 'meta': + track.type = MType.DATA; // Fix meta string to explicit DATA type + this._metadata.datas.push(track); + break; + default: + this.log(`Unknown track type ${track.type}`).warn(); + } + tracks.push(track); } - tracks.push(track); } // Sorts audios/videos by descending BPS