Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set rtmp/http server host parameter #445

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
18 changes: 11 additions & 7 deletions src/node_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const bodyParser = require('body-parser');
const basicAuth = require('basic-auth-connect');
const NodeFlvSession = require('./node_flv_session');
const HTTP_PORT = 80;
const HTTP_HOST = '0.0.0.0';
const HTTPS_PORT = 443;
const HTTPS_HOST = '0.0.0.0';
const HTTP_MEDIAROOT = './media';
const Logger = require('./node_core_logger');
const context = require('./node_core_ctx');
Expand All @@ -28,6 +30,7 @@ const relayRoute = require('./api/routes/relay');
class NodeHttpServer {
constructor(config) {
this.port = config.http.port || HTTP_PORT;
this.host = config.http.host || HTTP_HOST;
this.mediaroot = config.http.mediaroot || HTTP_MEDIAROOT;
this.config = config;

Expand Down Expand Up @@ -82,13 +85,14 @@ class NodeHttpServer {
Object.assign(options, { passphrase: this.config.https.passphrase });
}
this.sport = config.https.port ? config.https.port : HTTPS_PORT;
this.httpsServer = Http2.createSecureServer(options, app);
this.shost = config.https.host ? config.https.host : HTTPS_HOST;
this.httpsServer = Https2.createServer(options, app);
}
}

run() {
this.httpServer.listen(this.port, () => {
Logger.log(`Node Media Http Server started on port: ${this.port}`);
this.httpServer.listen(this.port, this.host, () => {
Logger.log(`Node Media Http Server started on: ${this.host}:${this.port}`);
});

this.httpServer.on('error', (e) => {
Expand All @@ -107,15 +111,15 @@ class NodeHttpServer {
});

this.wsServer.on('listening', () => {
Logger.log(`Node Media WebSocket Server started on port: ${this.port}`);
Logger.log(`Node Media WebSocket Server started on: ${this.host}:${this.port}`);
});
this.wsServer.on('error', (e) => {
Logger.error(`Node Media WebSocket Server ${e}`);
});

if (this.httpsServer) {
this.httpsServer.listen(this.sport, () => {
Logger.log(`Node Media Https Server started on port: ${this.sport}`);
this.httpsServer.listen(this.sport, this.shost, () => {
Logger.log(`Node Media Https Server started on: ${this.shost}:${this.sport}`);
});

this.httpsServer.on('error', (e) => {
Expand All @@ -134,7 +138,7 @@ class NodeHttpServer {
});

this.wssServer.on('listening', () => {
Logger.log(`Node Media WebSocketSecure Server started on port: ${this.sport}`);
Logger.log(`Node Media WebSocketSecure Server started on: ${this.shost}:${this.sport}`);
});
this.wssServer.on('error', (e) => {
Logger.error(`Node Media WebSocketSecure Server ${e}`);
Expand Down
12 changes: 8 additions & 4 deletions src/node_rtmp_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ const NodeRtmpSession = require('./node_rtmp_session');
const context = require('./node_core_ctx');

const RTMP_PORT = 1935;
const RTMP_HOST = '0.0.0.0';
const RTMPS_PORT = 443;
const RTMPS_HOST = '0.0.0.0';

class NodeRtmpServer {
constructor(config) {
config.rtmp.port = this.port = config.rtmp.port ? config.rtmp.port : RTMP_PORT;
config.rtmp.host = this.host = config.rtmp.host ? config.rtmp.host : RTMP_HOST;
this.tcpServer = Net.createServer((socket) => {
let session = new NodeRtmpSession(config, socket);
session.run();
});

if (config.rtmp.ssl){
config.rtmp.ssl.port = this.sslPort = config.rtmp.ssl.port ? config.rtmp.ssl.port : RTMPS_PORT;
config.rtmp.ssl.host = this.sslHost = config.rtmp.ssl.host ? config.rtmp.ssl.host : RTMPS_HOST;
try {
const options = {
key: Fs.readFileSync(config.rtmp.ssl.key),
Expand All @@ -41,8 +45,8 @@ class NodeRtmpServer {
}

run() {
this.tcpServer.listen(this.port, () => {
Logger.log(`Node Media Rtmp Server started on port: ${this.port}`);
this.tcpServer.listen(this.port, this.host, () => {
Logger.log(`Node Media Rtmp Server started on: ${this.host}:${this.port}`);
});

this.tcpServer.on('error', (e) => {
Expand All @@ -54,8 +58,8 @@ class NodeRtmpServer {
});

if (this.tlsServer) {
this.tlsServer.listen(this.sslPort, () => {
Logger.log(`Node Media Rtmps Server started on port: ${this.sslPort}`);
this.tlsServer.listen(this.sslPort, this.sslHost, () => {
Logger.log(`Node Media Rtmps Server started on: ${this.sslHost}:${this.sslPort}`);
});

this.tlsServer.on('error', (e) => {
Expand Down