-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic http-flv streaming and playback
- Loading branch information
Showing
23 changed files
with
2,390 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// 使用 IntelliSense 了解相关属性。 | ||
// 悬停以查看现有属性的描述。 | ||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "启动程序", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/bin/app.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"eslint.format.enable": true, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "always" | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# Node-Media-Server v4 | ||
# Node-Media-Server v4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import NodeMediaServer from "../src/index.js"; | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const config = require("./config.json"); | ||
let nms = new NodeMediaServer(config); | ||
nms.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDCTCCAfGgAwIBAgIUDuhBPFAjE21AWnSXtyZMrJlHD9MwDQYJKoZIhvcNAQEL | ||
BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIzMTEzMDEyMzkwMFoXDTIzMTIz | ||
MDEyMzkwMFowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF | ||
AAOCAQ8AMIIBCgKCAQEAvJtnosjxzqRAF6rkYAryTpKtQHAv635epaL24yGT/eVu | ||
WT/ivatXbRM6diPhYNqv/IeyoFhF/0FxnLrgtwmfOOjRj1nV+vg1R+aXgdSh9Uvz | ||
GKrWz3Vmg9C+r+C9JI5UFDPWe16jWhFIRHyXNLRzO08XW2ony1SBumlXVLcupLk6 | ||
IKF859DEk+XHFyeiG1BBfy03nT1n1VB57N/IM2CbyAUVlgqafopGI5LuaSWbsjy2 | ||
sCjLKsDUvVtKTqKvRp1gr2nD6kizXIQBCntnYOCZhSlFya+B88ohFpMvMYkeObzo | ||
w76nULR0swMlynTspa1W593hj8nbk9poSj+u1oohuQIDAQABo1MwUTAdBgNVHQ4E | ||
FgQURLU/ybQERbsNtyGijJl7SaGSfXkwHwYDVR0jBBgwFoAURLU/ybQERbsNtyGi | ||
jJl7SaGSfXkwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAHdfn | ||
qlg9YP3P93K7oOVhE9O9gpA+YC6jG7n6bBv4ZjDeWeryZR//mSEVeL66C5Pql/h0 | ||
xl1QwxMl8xY/BFhGzqX8v45gMw7RQqk0uWiwjwY9aLQUf3LKYi6ql6bTNEUV1u+3 | ||
F0r75ihGWXYR3tD3iUD8VTxqr/Uk5h0Y7ZpTen3z8MsIzEU7VMwnaLfSuTeA3X4r | ||
sY1EieWPkJOLxixq2DVRGkxdV6ql+B1PIGkmsVTPw1qq0OAGLZobYIgoqb1YHKjG | ||
0NC0caiA52iGwfKRhxr9q0fhiO2n4MIIYtfCc7kRyYkN9cyOqeZA/7Woph5I4Yra | ||
rlEctb+urg2V8HbaDw== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"rtmp": { | ||
"port": 1935 | ||
}, | ||
"http": { | ||
"bind": "0.0.0.0", | ||
"port": 8000, | ||
"webroot": "./www", | ||
"mediaroot": "./media", | ||
"allow_origin": "*", | ||
"api": true | ||
}, | ||
"https": { | ||
"bind": "0.0.0.0", | ||
"port": 8443, | ||
"key": "./bin/key.pem", | ||
"cert": "./bin/cert.pem" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC8m2eiyPHOpEAX | ||
quRgCvJOkq1AcC/rfl6lovbjIZP95W5ZP+K9q1dtEzp2I+Fg2q/8h7KgWEX/QXGc | ||
uuC3CZ846NGPWdX6+DVH5peB1KH1S/MYqtbPdWaD0L6v4L0kjlQUM9Z7XqNaEUhE | ||
fJc0tHM7TxdbaifLVIG6aVdUty6kuTogoXzn0MST5ccXJ6IbUEF/LTedPWfVUHns | ||
38gzYJvIBRWWCpp+ikYjku5pJZuyPLawKMsqwNS9W0pOoq9GnWCvacPqSLNchAEK | ||
e2dg4JmFKUXJr4HzyiEWky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jWtyN+uM5WgmQ3OHc9CSTqbbdhJR+MsRKF1r90WuAgjblEoZ+BJSUYUbqc | ||
IxjtKX01bGJv2txxFBvYKRrIY8IgJq8gBHMlQy8CgYAEVL2frT8esn4OgfCEyGY6 | ||
+F3A9HcuFsBW5x+PInDQo+8PTH2RoaZxzmrmw2tqkHWnnwJGBWXSjnGbdVdDEilu | ||
iCM1ujPO2NU/QIcwqfBfm9XBPsh052kfiaN80ma1BpRMFkt0BBA7SQVedRvJgDrj | ||
CR9dq010GBwWSnr7BpEokQ== | ||
-----END PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import globals from "globals"; | ||
import pluginJs from "@eslint/js"; | ||
import jsdoc from "eslint-plugin-jsdoc"; | ||
|
||
/** @type {import('eslint').Linter.Config[]} */ | ||
export default [ | ||
pluginJs.configs.recommended, | ||
jsdoc.configs["flat/recommended"], | ||
{ | ||
languageOptions: { globals: globals.node }, | ||
plugins: { | ||
jsdoc, | ||
}, | ||
rules: { | ||
"jsdoc/require-returns-description": "off", | ||
"jsdoc/valid-types": "error", | ||
"jsdoc/check-types": "error", | ||
"jsdoc/require-param-description": "off", | ||
"no-unused-vars": "off", | ||
"no-undef": "warn", | ||
"semi": [2, "always"], | ||
"quotes": [2, "double"] | ||
} | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
export default class AVPacket { | ||
constructor() { | ||
this.codec_id = 0; | ||
this.codec_type = 0; | ||
this.duration = 0; | ||
this.flags = 0; | ||
this.pts = 0; | ||
this.dts = 0; | ||
this.size = 0; | ||
this.offset = 0; | ||
|
||
/**@type {Buffer} */ | ||
this.data = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Created by Chen Mingliang on 23/12/01. | ||
// illuspas@msn.com | ||
// Copyright (c) 2023 NodeMedia. All rights reserved. | ||
// | ||
|
||
// import Pino from "pino"; | ||
// export default Pino(); | ||
|
||
|
||
class Logger { | ||
constructor (level = "info") { | ||
this.levels = ["trace", "debug", "info", "warn", "error"]; | ||
this.level = this.levels.includes(level) ? level : "info"; | ||
} | ||
|
||
log (message, logLevel = "info") { | ||
const messageLevel = this.levels.indexOf(logLevel); | ||
const currentLevel = this.levels.indexOf(this.level); | ||
|
||
if (messageLevel >= currentLevel) { | ||
console.log(`[${this.getTime()}] [${logLevel.toUpperCase()}] ${message}`); | ||
} | ||
} | ||
|
||
getTime () { | ||
const now = new Date(); | ||
return now.toLocaleString(); | ||
} | ||
|
||
trace (message) { | ||
this.log(message, "trace"); | ||
} | ||
|
||
debug (message) { | ||
this.log(message, "debug"); | ||
} | ||
|
||
info (message) { | ||
this.log(message, "info"); | ||
} | ||
|
||
warn (message) { | ||
this.log(message, "warn"); | ||
} | ||
|
||
error (message) { | ||
this.log(message, "error"); | ||
} | ||
} | ||
|
||
export default new Logger("debug"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import NodeHttpServer from "./server/http_server.js"; | ||
import NodeRtmpServer from "./server/rtmp_server.js"; | ||
import { createRequire } from "module"; | ||
import logger from "./core/logger.js"; | ||
|
||
const require = createRequire(import.meta.url); | ||
const Package = require("../package.json"); | ||
|
||
|
||
export default class NodeMediaServer { | ||
constructor(config) { | ||
logger.level = "debug"; | ||
logger.info(`Node-Media-Server v${Package.version}`); | ||
logger.info(`Homepage: ${Package.homepage}`); | ||
logger.info(`License: ${Package.license}`); | ||
logger.info(`Author: ${Package.author}`); | ||
this.ctx = { | ||
config, | ||
sessions: new Map(), | ||
broadcasts: new Map() | ||
}; | ||
this.httpServer = new NodeHttpServer(this.ctx); | ||
this.rtmpServer = new NodeRtmpServer(this.ctx); | ||
} | ||
|
||
run() { | ||
this.httpServer.run(); | ||
this.rtmpServer.run(); | ||
} | ||
} |
Oops, something went wrong.