-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (44 loc) · 1.49 KB
/
server.js
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
require("v8-compile-cache");
(function () {
var Bits, StreamServer, config, logger, streamServer, url;
url = require("url");
config = require("./config");
StreamServer = require("./stream_server");
Bits = require("./bits");
logger = require("./logger");
Bits.set_warning_fatal(true);
logger.setLevel(logger[config.logLevel]);
streamServer = new StreamServer();
// Uncomment this block if you use Basic auth for RTSP
//streamServer.setAuthenticator (username, password, callback) ->
// # If isAuthenticated is true, access is allowed
// isAuthenticated = false
// # Replace here
// if (username is 'user1') and (password is 'password1')
// isAuthenticated = true
// callback null, isAuthenticated
streamServer.setLivePathConsumer(function (uri, callback) {
var isAuthorized, pathname, ref;
pathname = (ref = url.parse(uri).pathname) != null ? ref.slice(1) : void 0;
isAuthorized = true;
if (isAuthorized) {
return callback(null); // Accept access
} else {
return callback(new Error("Unauthorized access")); // Deny access
}
});
if (config.recordedDir != null) {
streamServer.attachRecordedDir(config.recordedDir);
}
process.on("SIGINT", () => {
logger.log("Got SIGINT");
return streamServer.stop(function () {
return process.kill(process.pid, "SIGTERM");
});
});
process.on("uncaughtException", function (err) {
streamServer.stop();
throw err;
});
streamServer.start();
}.call(this));