Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
illuspas committed Nov 30, 2024
1 parent 9bf30cc commit 88dcc8d
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 247 deletions.
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default [
"no-unused-vars": "off",
"no-undef": "error",
"semi": [2, "always"],
"quotes": [2, "double"]
"quotes": [2, "double"],
"indent": ["error", 2]
}
},
];
24 changes: 12 additions & 12 deletions src/core/avpacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
//

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;
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 = Buffer.alloc(0);
}
/**@type {Buffer} */
this.data = Buffer.alloc(0);
}
}
14 changes: 7 additions & 7 deletions src/core/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import BaseSession from "../session/base_session.js";
import BroadcastServer from "../server/broadcast_server.js";

export default class Context {
constructor(config) {
this.config = config;
constructor(config) {
this.config = config;

/** @type {Map<string, BaseSession>} */
this.sessions = new Map();
/** @type {Map<string, BaseSession>} */
this.sessions = new Map();

/** @type {Map<string, BroadcastServer>} */
this.broadcasts = new Map();
}
/** @type {Map<string, BroadcastServer>} */
this.broadcasts = new Map();
}
}
28 changes: 14 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ 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 = new Context(config);
this.httpServer = new NodeHttpServer(this.ctx);
this.rtmpServer = new NodeRtmpServer(this.ctx);
}
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 = new Context(config);
this.httpServer = new NodeHttpServer(this.ctx);
this.rtmpServer = new NodeRtmpServer(this.ctx);
}

run() {
this.httpServer.run();
this.rtmpServer.run();
}
run() {
this.httpServer.run();
this.rtmpServer.run();
}
}
164 changes: 82 additions & 82 deletions src/protocol/amf.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,96 +254,96 @@ export default class AMF {

try {
switch (type) {
case 0: // Number(Double) type
value = v.getFloat64(1, !le);
offset += 8;
break;
case 1: { // Boolean type
const b = v.getUint8(1);
value = !!b;
offset += 1;
break;
case 0: // Number(Double) type
value = v.getFloat64(1, !le);
offset += 8;
break;
case 1: { // Boolean type
const b = v.getUint8(1);
value = !!b;
offset += 1;
break;
}
case 2: { // String type
const amfstr = AMF.parseString(arrayBuffer, dataOffset + 1, dataSize - 1);
value = amfstr.data;
offset += amfstr.size;
break;
}
case 3: { // Object(s) type
value = {};
let terminal = 0; // workaround for malformed Objects which has missing ScriptDataObjectEnd
if ((v.getUint32(dataSize - 4, !le) & 0x00FFFFFF) === 9) {
terminal = 3;
}
case 2: { // String type
const amfstr = AMF.parseString(arrayBuffer, dataOffset + 1, dataSize - 1);
value = amfstr.data;
offset += amfstr.size;
break;
while (offset < dataSize - 4) { // 4 === type(UI8) + ScriptDataObjectEnd(UI24)
const amfobj = AMF.parseObject(arrayBuffer, dataOffset + offset, dataSize - offset - terminal);
if (amfobj.objectEnd) { break; }
value[amfobj.data.name] = amfobj.data.value;
offset += amfobj.size;
}
case 3: { // Object(s) type
value = {};
let terminal = 0; // workaround for malformed Objects which has missing ScriptDataObjectEnd
if ((v.getUint32(dataSize - 4, !le) & 0x00FFFFFF) === 9) {
terminal = 3;
}
while (offset < dataSize - 4) { // 4 === type(UI8) + ScriptDataObjectEnd(UI24)
const amfobj = AMF.parseObject(arrayBuffer, dataOffset + offset, dataSize - offset - terminal);
if (amfobj.objectEnd) { break; }
value[amfobj.data.name] = amfobj.data.value;
offset += amfobj.size;
}
if (offset <= dataSize - 3) {
const marker = v.getUint32(offset - 1, !le) & 0x00FFFFFF;
if (marker === 9) {
offset += 3;
}
if (offset <= dataSize - 3) {
const marker = v.getUint32(offset - 1, !le) & 0x00FFFFFF;
if (marker === 9) {
offset += 3;
}
break;
}
case 8: { // ECMA array type (Mixed array)
value = {};
offset += 4; // ECMAArrayLength(UI32)
let terminal = 0; // workaround for malformed MixedArrays which has missing ScriptDataObjectEnd
if ((v.getUint32(dataSize - 4, !le) & 0x00FFFFFF) === 9) {
terminal = 3;
}
while (offset < dataSize - 8) { // 8 === type(UI8) + ECMAArrayLength(UI32) + ScriptDataVariableEnd(UI24)
const amfvar = AMF.parseVariable(arrayBuffer, dataOffset + offset, dataSize - offset - terminal);
if (amfvar.objectEnd) { break; }
value[amfvar.data.name] = amfvar.data.value;
offset += amfvar.size;
}
if (offset <= dataSize - 3) {
const marker = v.getUint32(offset - 1, !le) & 0x00FFFFFF;
if (marker === 9) {
offset += 3;
}
}
break;
break;
}
case 8: { // ECMA array type (Mixed array)
value = {};
offset += 4; // ECMAArrayLength(UI32)
let terminal = 0; // workaround for malformed MixedArrays which has missing ScriptDataObjectEnd
if ((v.getUint32(dataSize - 4, !le) & 0x00FFFFFF) === 9) {
terminal = 3;
}
case 9: // ScriptDataObjectEnd
value = undefined;
offset = 1;
objectEnd = true;
break;
case 10: { // Strict array type
// ScriptDataValue[n]. NOTE: according to video_file_format_spec_v10_1.pdf
value = [];
const strictArrayLength = v.getUint32(1, !le);
offset += 4;
for (let i = 0; i < strictArrayLength; i++) {
const val = AMF.parseValue(arrayBuffer, dataOffset + offset, dataSize - offset);
value.push(val.data);
offset += val.size;
}
break;
while (offset < dataSize - 8) { // 8 === type(UI8) + ECMAArrayLength(UI32) + ScriptDataVariableEnd(UI24)
const amfvar = AMF.parseVariable(arrayBuffer, dataOffset + offset, dataSize - offset - terminal);
if (amfvar.objectEnd) { break; }
value[amfvar.data.name] = amfvar.data.value;
offset += amfvar.size;
}
case 11: { // Date type
const date = AMF.parseDate(arrayBuffer, dataOffset + 1, dataSize - 1);
value = date.data;
offset += date.size;
break;
if (offset <= dataSize - 3) {
const marker = v.getUint32(offset - 1, !le) & 0x00FFFFFF;
if (marker === 9) {
offset += 3;
}
}
case 12: { // Long string type
const amfLongStr = AMF.parseString(arrayBuffer, dataOffset + 1, dataSize - 1);
value = amfLongStr.data;
offset += amfLongStr.size;
break;
break;
}
case 9: // ScriptDataObjectEnd
value = undefined;
offset = 1;
objectEnd = true;
break;
case 10: { // Strict array type
// ScriptDataValue[n]. NOTE: according to video_file_format_spec_v10_1.pdf
value = [];
const strictArrayLength = v.getUint32(1, !le);
offset += 4;
for (let i = 0; i < strictArrayLength; i++) {
const val = AMF.parseValue(arrayBuffer, dataOffset + offset, dataSize - offset);
value.push(val.data);
offset += val.size;
}
default:
// ignore and skip
offset = dataSize;
logger.warn("AMF", "Unsupported AMF value type " + type);
break;
}
case 11: { // Date type
const date = AMF.parseDate(arrayBuffer, dataOffset + 1, dataSize - 1);
value = date.data;
offset += date.size;
break;
}
case 12: { // Long string type
const amfLongStr = AMF.parseString(arrayBuffer, dataOffset + 1, dataSize - 1);
value = amfLongStr.data;
offset += amfLongStr.size;
break;
}
default:
// ignore and skip
offset = dataSize;
logger.warn("AMF", "Unsupported AMF value type " + type);
}
} catch (e) {
logger.error("AMF", e.toString());
Expand Down
Loading

0 comments on commit 88dcc8d

Please sign in to comment.