-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_app.js
More file actions
35 lines (28 loc) · 1013 Bytes
/
example_app.js
File metadata and controls
35 lines (28 loc) · 1013 Bytes
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
'use strict';
const cache = require("./simplefastvideostreamcache.js").generateVideoCache;
const getVidType = require("./simplefastvideostreamcache.js").getVidType;
const videoTypes = require("./simplefastvideostreamcache.js").videoTypes;
const chunkSize = 1024*64; // it was 1M
const numCachedChunks = 300;
const chunkExpireSeconds = 100;
const perfCountObj={};
// setInterval(function(){console.log(perfCountObj);},1000);
const video = cache(chunkSize,numCachedChunks,chunkExpireSeconds, perfCountObj)
const http = require('http');
const options = {};
options.agent = new http.Agent({ keepAlive: true });
const server = http.createServer(options,async (req, res) => {
if(req.url==="" || req.url==="/")
{
res.writeHead(200);
res.end(JSON.stringify(perfCountObj));
}
else
{
let vidType = getVidType(req.url);
video.stream(req,res,vidType);
}
});
server.listen( process.env.PORT || 3000, "0.0.0.0", () => {
console.log("Server running");
});