Skip to content

Commit

Permalink
Add the RTMPS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
illuspas committed Dec 6, 2024
1 parent 66b6d42 commit 8f946b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ npx node-media-server

## Features
* HTTP/HTTP2-flv Push/Play
* RTMP Push/Play
* RTMP/RTMPS Push/Play
* GOP cache

## Roadmap
Expand Down
8 changes: 8 additions & 0 deletions bin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const path = require("path");
const config = require("./config.json");
const NodeMediaServer = require("..");

if (!fs.existsSync(config.rtmps.key)) {
config.rtmps.key = path.join(__dirname, config.rtmps.key);

}
if (!fs.existsSync(config.rtmps.cert)) {
config.rtmps.cert = path.join(__dirname, config.rtmps.cert);
}

if (!fs.existsSync(config.https.key)) {
config.https.key = path.join(__dirname, config.https.key);

Expand Down
6 changes: 6 additions & 0 deletions bin/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"bind": "0.0.0.0",
"port": 1935
},
"rtmps": {
"bind": "0.0.0.0",
"port": 1936,
"key": "./key.pem",
"cert": "./cert.pem"
},
"http": {
"bind": "0.0.0.0",
"port": 8000
Expand Down
14 changes: 12 additions & 2 deletions src/server/rtmp_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
// Copyright (c) 2023 Nodemedia. All rights reserved.
//

const Context = require("../core/context.js");
const fs = require("fs");
const net = require("net");
const tls = require('tls');
const logger = require("../core/logger.js");
const Context = require("../core/context.js");
const RtmpSession = require("../session/rtmp_session.js");

class NodeRtmpServer {
Expand All @@ -16,14 +18,22 @@ class NodeRtmpServer {
*/
constructor(ctx) {
this.ctx = ctx;
const opt = {
key: fs.readFileSync(ctx.config.rtmps.key),
cert: fs.readFileSync(ctx.config.rtmps.cert),
};

this.tcpServer = net.createServer(this.handleRequest);
this.tlsServer = tls.createServer(opt, this.handleRequest);
}

run = () => {
this.tcpServer.listen(this.ctx.config.rtmp.port, this.ctx.config.rtmp.bind, () => {
logger.log(`Rtmp Server listening on port ${this.ctx.config.rtmp.bind}:${this.ctx.config.rtmp.port}`);
});

this.tlsServer.listen(this.ctx.config.rtmps.port, this.ctx.config.rtmps.bind, () => {
logger.log(`Rtmps Server listening on port ${this.ctx.config.rtmps.bind}:${this.ctx.config.rtmps.port}`);
});
};

/**
Expand Down

0 comments on commit 8f946b8

Please sign in to comment.