forked from Eyevinn/channel-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
75 lines (66 loc) · 1.99 KB
/
Copy pathserver.js
File metadata and controls
75 lines (66 loc) · 1.99 KB
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
/*
* Reference implementation of Channel Engine library
*/
const ChannelEngine = require('./index.js');
class RefAssetManager {
constructor(opts) {
this.assets = {
'1': [
{ id: 1, title: "Tears of Steel", uri: "https://maitv-vod.lab.eyevinn.technology/tearsofsteel_4k.mov/master.m3u8" },
{ id: 2, title: "VINN", uri: "https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8" }
]
};
this.pos = {
'1': 1
};
}
/**
*
* @param {Object} vodRequest
* {
* sessionId,
* category,
* playlistId
* }
*/
getNextVod(vodRequest) {
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;
}
resolve(vod);
} else {
reject("Invalid channelId provided");
}
});
}
};
class RefChannelManager {
getChannels() {
return [ { id: '1', profile: this._getProfile() }, { id: 'faulty', profile: this._getProfile() } ];
// return [ { id: '1', profile: this._getProfile() } ];
}
_getProfile() {
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 = {
heartbeat: '/',
averageSegmentDuration: 2000,
channelManager: refChannelManager,
defaultSlateUri: "https://maitv-vod.lab.eyevinn.technology/slate-consuo.mp4/master.m3u8",
slateRepetitions: 10,
redisUrl: process.env.REDIS_URL,
};
const engine = new ChannelEngine(refAssetManager, engineOptions);
engine.start();
engine.listen(process.env.port || 8000);