Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
illuspas committed Dec 3, 2024
1 parent 74cae53 commit 6dc3c1a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 31 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:lts-alpine

WORKDIR /node-media-server

COPY . .

RUN npm install

EXPOSE 1935 8000 8443

CMD ["node", "bin/app.js"]
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Node-Media-Server v4

## Introduction
Node-Media-Server is a high-performance open-source live broadcast server developed based on Nodejs.
Node-Media-Server is a high-performance/low-latency/open-source Live Streaming Server developed based on Nodejs.
v4 is design to implement enhanced RTMP FLV v1 support for native HEVC, VP9, AV1.
v4 is no longer compatible with the cn_cdn extension id flv_265 standard.
v4 is no longer compatible with the cn_cdn extension id flv_265 standard.
v4 is no longer compatible with flashplayer's rtmp protocol.

## Installation
```
Expand All @@ -25,8 +26,9 @@ npx node-media-server
* HTTP-API
* Authentication
* Notification
* WebManager
* Relay
* Record and Playback
* GOP cache
* Rtmp Proxy

## Usage
* obs_29.1 or above is required
Expand Down
2 changes: 1 addition & 1 deletion bin/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"rtmp": {
"bind":"0.0.0.0",
"bind": "0.0.0.0",
"port": 1935
},
"http": {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"bin": "bin/app.js",
"main": "src/index.js",
"scripts": {
"dev": "npx eslint;node bin/app.js"
"dev": "npx eslint;node bin/app.js",
"start": "node bin/app.js"
},
"keywords": [
"rtmp",
Expand All @@ -28,4 +29,4 @@
"http2-express-bridge": "^1.0.7",
"nanoid": "^5.0.9"
}
}
}
2 changes: 0 additions & 2 deletions src/core/avpacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export default class AVPacket {
this.dts = 0;
this.size = 0;
this.offset = 0;

/**@type {Buffer} */
this.data = Buffer.alloc(0);
}
}
35 changes: 19 additions & 16 deletions src/protocol/amf.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function amf0decDate(buf) {

/**
* AMF0 Encode Date
* @param ts
* @param {number} ts
* @returns {Buffer}
*/
function amf0encDate(ts) {
Expand Down Expand Up @@ -225,7 +225,7 @@ function amf0encObject(o) {

/**
* AMF0 Decode Reference
* @param buf
* @param {Buffer} buf
* @returns {{len: number, value: string}}
*/
function amf0decRef(buf) {
Expand All @@ -235,7 +235,7 @@ function amf0decRef(buf) {

/**
* AMF0 Encode Reference
* @param index
* @param {number} index
* @returns {Buffer}
*/
function amf0encRef(index) {
Expand Down Expand Up @@ -279,7 +279,7 @@ function amf0encUString(str) {

/**
* AMF0 Encode String
* @param str
* @param {string} str
* @returns {Buffer}
*/
function amf0encString(str) {
Expand All @@ -301,7 +301,7 @@ function amf0decLongString(buf) {

/**
* AMF0 Encode Long String
* @param str
* @param {string} str
* @returns {Buffer}
*/
function amf0encLongString(str) {
Expand All @@ -324,7 +324,8 @@ function amf0decArray(buf) {

/**
* AMF0 Encode Array
* @param a
* @param {Array} a
* @returns {Buffer}
*/
function amf0encArray(a) {
let l = 0;
Expand All @@ -334,12 +335,12 @@ function amf0encArray(a) {
buf.writeUInt8(8, 0);
buf.writeUInt32BE(l, 1);
let data = amf0encObject(a);
return Buffer.concat([buf, data.slice(1)]);
return Buffer.concat([buf, data.subarray(1)]);
}

/**
* AMF0 Encode Binary Array into binary Object
* @param aData
* @param {Buffer} aData
* @returns {Buffer}
*/
function amf0cnletray2Object(aData) {
Expand Down Expand Up @@ -373,7 +374,7 @@ function amf0decXmlDoc(buf) {

/**
* AMF0 Encode XMLDoc
* @param str
* @param {string} str
* @returns {Buffer}
*/
function amf0encXmlDoc(str) { // Essentially it is the same as string
Expand Down Expand Up @@ -419,7 +420,8 @@ function amf0encSArray(a) {

/**
*
* @param a
* @param {Array} a
* @returns {Array}
*/
function amf0markSArray(a) {
Object.defineProperty(a, "sarray", { value: true });
Expand Down Expand Up @@ -448,7 +450,7 @@ function amf0encTypedObj() {

/**
* Decode one value from the Buffer according to the applied rules
* @param rules
* @param {Array} rules
* @param {Buffer} buffer
* @returns {*}
*/
Expand All @@ -472,7 +474,7 @@ function amf0DecodeOne(buffer) {

/**
* Decode a whole buffer of AMF values according to rules and return in array
* @param rules
* @param {Array} rules
* @param {Buffer} buffer
* @returns {Array}
*/
Expand All @@ -499,8 +501,8 @@ function amf0Decode(buffer) {

/**
* Encode one AMF value according to rules
* @param rules
* @param o
* @param {Array} rules
* @param {object} o
* @returns {*}
*/
function amfXEncodeOne(rules, o) {
Expand All @@ -512,7 +514,7 @@ function amfXEncodeOne(rules, o) {

/**
* Encode one AMF0 value
* @param o
* @param {object} o
* @returns {*}
*/
function amf0EncodeOne(o) {
Expand All @@ -521,7 +523,7 @@ function amf0EncodeOne(o) {

/**
* Encode an array of values into a buffer
* @param a
* @param {Array} a
* @returns {Buffer}
*/
function amf0Encode(a) {
Expand Down Expand Up @@ -649,6 +651,7 @@ function encodeAmf0Cmd(opt) {
/**
*
* @param {object} opt
* @returns {Buffer}
*/
function encodeAmf0Data(opt) {
let data = amf0EncodeOne(opt.cmd);
Expand Down
8 changes: 4 additions & 4 deletions src/session/flv_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class FlvSession extends BaseSession {
this.ctx = ctx;
this.req = req;
this.res = res;
this.ip = req.ip ?? "0.0.0.0";
this.ip = req.socket.remoteAddress + ":" + req.socket.remotePort;
this.flv = new Flv();
this.protocol = "flv";
this.streamHost = req.hostname;
Expand All @@ -40,13 +40,13 @@ export default class FlvSession extends BaseSession {
this.ctx.broadcasts.set(this.streamPath, this.broadcast);
}

run = ()=> {
run = () => {
this.req.on("data", this.onData);
this.req.on("error", this.onError);
this.req.socket.on("close", this.onClose);
if(this.req.method === "GET") {
if (this.req.method === "GET") {
this.onPlay();
}else if(this.req.method === "POST") {
} else if (this.req.method === "POST") {
this.onPush();
}
};
Expand Down
9 changes: 7 additions & 2 deletions src/session/rtmp_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class RtmpSession extends BaseSession {
super();
this.ctx = ctx;
this.socket = socket;
this.ip = socket.remoteAddress + ":" + socket.remotePort;
this.protocol = "rtmp";
this.rtmp = new Rtmp();
this.broadcast = new BroadcastServer();
Expand All @@ -48,7 +49,7 @@ export default class RtmpSession extends BaseSession {
* @param {string} streamApp
* @param {string} streamName
*/
onConnect = (streamApp, streamName) =>{
onConnect = (streamApp, streamName) => {
this.streamApp = streamApp;
this.streamName = streamName;
this.streamPath = "/" + streamApp + "/" + streamName;
Expand Down Expand Up @@ -110,8 +111,12 @@ export default class RtmpSession extends BaseSession {
}
};

/**
*
* @param {Error} error
*/
onError = (error) => {

logger.info(`RTMP session ${this.id} socket error, ${error.name}: ${error.message}`);
};

/**
Expand Down

0 comments on commit 6dc3c1a

Please sign in to comment.