-
Notifications
You must be signed in to change notification settings - Fork 27
/
default.ts
115 lines (103 loc) · 3.11 KB
/
default.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Reference implementation of Channel Engine library
*/
import { ChannelEngine, ChannelEngineOpts,
IAssetManager, IChannelManager,
VodRequest, VodResponse, Channel, ChannelProfile
} from "../index";
let TEST_CHANNELS_COUNT = 1;
if (process.env.TEST_CHANNELS) {
TEST_CHANNELS_COUNT = parseInt(process.env.TEST_CHANNELS, 10);
}
class RefAssetManager implements IAssetManager {
private assets;
private pos;
constructor(opts?) {
this.assets = {};
this.pos = {};
for (let i = 0; i < TEST_CHANNELS_COUNT; i++) {
const channelId = `${i + 1}`;
this.assets[channelId] = [
{
id: 1,
title: "Streaming Tech TV+",
uri: "https://lab.cdn.eyevinn.technology/stswetvplus-promo-2023-5GBm231Mkz.mov/manifest.m3u8",
},
{
id: 2,
title: "Tears of Steel",
uri: "https://maitv-vod.lab.eyevinn.technology/tearsofsteel_4k.mov/master.m3u8",
},
{
id: 3,
title: "VINN",
uri: "https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8",
},
];
this.pos[channelId] = 0;
}
}
/**
*
* @param {Object} vodRequest
* {
* sessionId,
* category,
* playlistId
* }
*/
getNextVod(vodRequest: VodRequest): Promise<VodResponse> {
return new Promise((resolve, reject) => {
const channelId = vodRequest.playlistId;
if (this.assets[channelId]) {
let vod = this.assets[channelId][this.pos[channelId]++];
if (this.pos[channelId] > this.assets[channelId].length - 1) {
this.pos[channelId] = 0;
}
const vodResponse = {
id: vod.id,
title: vod.title,
uri: vod.uri,
};
resolve(vodResponse);
} else {
reject("Invalid channelId provided");
}
});
}
}
class RefChannelManager implements IChannelManager {
private channels;
constructor() {
this.channels = [];
for (let i = 0; i < TEST_CHANNELS_COUNT; i++) {
this.channels.push({ id: `${i + 1}`, profile: this._getProfile() });
}
}
getChannels(): Channel[] {
return this.channels;
}
_getProfile(): ChannelProfile[] {
return [
{ bw: 6134000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [1024, 458] },
{ bw: 2323000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [640, 286] },
{ bw: 1313000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [480, 214] },
];
}
}
const refAssetManager = new RefAssetManager();
const refChannelManager = new RefChannelManager();
const engineOptions: ChannelEngineOpts = {
heartbeat: "/",
averageSegmentDuration: 2000,
channelManager: refChannelManager,
defaultSlateUri:
"https://maitv-vod.lab.eyevinn.technology/slate-consuo.mp4/master.m3u8",
slateRepetitions: 10,
redisUrl: process.env.REDIS_URL,
keepAliveTimeout: process.env.KEEP_ALIVE_TIMEOUT ? parseInt(process.env.KEEP_ALIVE_TIMEOUT) * 1000: undefined,
sessionHealthKey: 'eyevinn'
};
const engine = new ChannelEngine(refAssetManager, engineOptions);
engine.start();
engine.listen(process.env.PORT || 8000);