Skip to content
Draft
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
40 changes: 30 additions & 10 deletions engine/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export class ChannelEngine {
try {
await Promise.all(channels.map(channel => getSwitchStatusAndPerformSwitch(channel)));
} catch (err) {
debug('Problem occured when updating streamSwitchers');
debug('Problem occurred when updating streamSwitchers');
throw new Error (err);
}

Expand Down Expand Up @@ -474,13 +474,15 @@ export class ChannelEngine {
useDemuxedAudio: options.useDemuxedAudio,
dummySubtitleEndpoint: this.dummySubtitleEndpoint,
subtitleSliceEndpoint: this.subtitleSliceEndpoint,
useVTTSubtitles: this.useVTTSubtitles,
useVTTSubtitles: false,
cloudWatchMetrics: this.logCloudWatchMetrics,
profile: channel.profile,
audioTracks: channel.audioTracks
}, this.sessionLiveStore);

sessionSwitchers[channel.id] = new StreamSwitcher({
sessionId: channel.id,
useDemuxedAudio: options.useDemuxedAudio,
streamSwitchManager: this.streamSwitchManager ? this.streamSwitchManager : null
});

Expand Down Expand Up @@ -751,15 +753,31 @@ export class ChannelEngine {
}

async _handleAudioManifest(req, res, next) {
debug(`req.url=${req.url}`);
debug(`x-playback-session-id=${req.headers["x-playback-session-id"]} req.url=${req.url}`);
debug(req.params);
const session = sessions[req.params[2]];
if (session) {
const sessionLive = sessionsLive[req.params[2]];
if (session && sessionLive) {
try {
const body = await session.getCurrentAudioManifestAsync(
req.params[0],
req.params[1],
req.headers["x-playback-session-id"]
);
let body = null;
if (!this.streamSwitchManager) {
debug(`[${req.params[1]}]: Responding with VOD2Live manifest`);
body = await session.getCurrentAudioManifestAsync(req.params[0], req.params[1], req.headers["x-playback-session-id"]);
} else {
while (switcherStatus[req.params[2]] === null || switcherStatus[req.params[2]] === undefined) {
debug(`[${req.params[1]}]: (${switcherStatus[req.params[1]]}) Waiting for streamSwitcher to respond`);
await timer(500);
}
debug(`switcherStatus[${req.params[1]}]=[${switcherStatus[req.params[2]]}]`);
if (switcherStatus[req.params[2]]) {
debug(`[${req.params[2]}]: Responding with Live-stream manifest`);
body = await sessionLive.getCurrentAudioManifestAsync(req.params[0], req.params[1]);
} else {
debug(`[${req.params[2]}]: Responding with VOD2Live manifest`);
body = await session.getCurrentAudioManifestAsync(req.params[0], req.params[1], req.headers["x-playback-session-id"]);
}
}

res.sendRaw(200, Buffer.from(body, 'utf8'), {
"Content-Type": "application/vnd.apple.mpegurl",
"Access-Control-Allow-Origin": "*",
Expand All @@ -771,7 +789,7 @@ export class ChannelEngine {
next(this._gracefulErrorHandler(err));
}
} else {
const err = new errs.NotFoundError('Invalid session');
const err = new errs.NotFoundError('Invalid session(s)');
next(err);
}
}
Expand Down Expand Up @@ -852,13 +870,15 @@ export class ChannelEngine {
await timer(500);
}
debug(`switcherStatus[${req.params[1]}]=[${switcherStatus[req.params[1]]}]`);
let ts1 = Date.now();
if (switcherStatus[req.params[1]]) {
debug(`[${req.params[1]}]: Responding with Live-stream manifest`);
body = await sessionLive.getCurrentMediaManifestAsync(req.params[0]);
} else {
debug(`[${req.params[1]}]: Responding with VOD2Live manifest`);
body = await session.getCurrentMediaManifestAsync(req.params[0], req.headers["x-playback-session-id"]);
}
debug(`[${req.params[1]}]: Manifest Request Took (${Date.now() - ts1})ms`);
}

//verbose(`[${session.sessionId}] body=`);
Expand Down
Loading