Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
illuspas committed Nov 28, 2024
1 parent 10b3499 commit f7fb379
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 168 deletions.
6 changes: 1 addition & 5 deletions bin/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
},
"http": {
"bind": "0.0.0.0",
"port": 8000,
"webroot": "./www",
"mediaroot": "./media",
"allow_origin": "*",
"api": true
"port": 8000
},
"https": {
"bind": "0.0.0.0",
Expand Down
5 changes: 5 additions & 0 deletions src/core/context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// @ts-check
//
// Created by Chen Mingliang on 24/11/28.
// illuspas@msn.com
// Copyright (c) 2023 NodeMedia. All rights reserved.
//

import BaseSession from "../session/base_session.js";
import BroadcastServer from "../server/broadcast_server.js";
Expand Down
126 changes: 124 additions & 2 deletions src/protocol/amf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,137 @@
*/

import logger from "../core/logger.js";
import decodeUTF8 from "./utf8-conv.js";
import { IllegalStateException } from "./exception.js";

/**
*
* @param {Uint8Array} uint8array
* @param {number} start
* @param {number} checkLength
* @returns {boolean}
*/
function checkContinuation(uint8array, start, checkLength) {
const array = uint8array;
if (start + checkLength < array.length) {
while (checkLength--) {
if ((array[++start] & 0xC0) !== 0x80) { return false; }
}
return true;
} else {
return false;
}
}

/**
*
* @param {Uint8Array} uint8array
* @returns {string}
*/
function decodeUTF8(uint8array) {
const out = [];
const input = uint8array;
let i = 0;
const length = uint8array.length;

while (i < length) {
if (input[i] < 0x80) {
out.push(String.fromCharCode(input[i]));
++i;
continue;
} else if (input[i] < 0xC0) {
// fallthrough
} else if (input[i] < 0xE0) {
if (checkContinuation(input, i, 1)) {
const ucs4 = (input[i] & 0x1F) << 6 | (input[i + 1] & 0x3F);
if (ucs4 >= 0x80) {
out.push(String.fromCharCode(ucs4 & 0xFFFF));
i += 2;
continue;
}
}
} else if (input[i] < 0xF0) {
if (checkContinuation(input, i, 2)) {
const ucs4 = (input[i] & 0xF) << 12 | (input[i + 1] & 0x3F) << 6 | input[i + 2] & 0x3F;
if (ucs4 >= 0x800 && (ucs4 & 0xF800) !== 0xD800) {
out.push(String.fromCharCode(ucs4 & 0xFFFF));
i += 3;
continue;
}
}
} else if (input[i] < 0xF8) {
if (checkContinuation(input, i, 3)) {
let ucs4 = (input[i] & 0x7) << 18 | (input[i + 1] & 0x3F) << 12 |
(input[i + 2] & 0x3F) << 6 | (input[i + 3] & 0x3F);
if (ucs4 > 0x10000 && ucs4 < 0x110000) {
ucs4 -= 0x10000;
out.push(String.fromCharCode((ucs4 >>> 10) | 0xD800));
out.push(String.fromCharCode((ucs4 & 0x3FF) | 0xDC00));
i += 4;
continue;
}
}
}
out.push(String.fromCharCode(0xFFFD));
++i;
}

return out.join("");
}

class RuntimeException {
constructor(message) {
this._message = message;
}

get name() {
return "RuntimeException";
}

get message() {
return this._message;
}

toString() {
return this.name + ": " + this.message;
}
}

class IllegalStateException extends RuntimeException {
constructor(message) {
super(message);
}

get name() {
return "IllegalStateException";
}
}

class InvalidArgumentException extends RuntimeException {
constructor(message) {
super(message);
}

get name() {
return "InvalidArgumentException";
}
}

class NotImplementedException extends RuntimeException {
constructor(message) {
super(message);
}

get name() {
return "NotImplementedException";
}
}

const le = (function () {
const buf = new ArrayBuffer(2);
(new DataView(buf)).setInt16(0, 256, true); // little-endian write
return (new Int16Array(buf))[0] === 256; // platform-spec read, if equal then LE
})();


export default class AMF {
static parseScriptData(arrayBuffer, dataOffset, dataSize) {
const data = {};
Expand Down
66 changes: 0 additions & 66 deletions src/protocol/exception.js

This file was deleted.

93 changes: 0 additions & 93 deletions src/protocol/utf8-conv.js

This file was deleted.

9 changes: 7 additions & 2 deletions src/server/rtmp_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
// Copyright (c) 2023 Nodemedia. All rights reserved.
//

import Context from "../core/context.js";

export default class NodeRtmpServer {
constructor(config) {
this.config = config;
/**
* @param {Context} ctx
*/
constructor(ctx) {
this.ctx = ctx;
}

run = () => {
Expand Down

0 comments on commit f7fb379

Please sign in to comment.