-
-
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.
- Loading branch information
Showing
13 changed files
with
138 additions
and
72 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
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); | ||
|
||
const 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
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,8 @@ | ||
// @ts-check | ||
// | ||
// Created by Chen Mingliang on 23/12/01. | ||
// illuspas@msn.com | ||
// Copyright (c) 2023 NodeMedia. All rights reserved. | ||
// | ||
|
||
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
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 @@ | ||
// @ts-check | ||
|
||
import BaseSession from "../session/base_session.js"; | ||
import BroadcastServer from "../server/broadcast_server.js"; | ||
|
||
export default class Context { | ||
constructor(config) { | ||
this.config = config; | ||
|
||
/** @type {Map<string, BaseSession>} */ | ||
this.sessions = new Map(); | ||
|
||
/** @type {Map<string, BroadcastServer>} */ | ||
this.broadcasts = new Map(); | ||
} | ||
} |
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,53 +1,64 @@ | ||
// @ts-check | ||
// | ||
// 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); | ||
|
||
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"); | ||
if (messageLevel >= currentLevel) { | ||
console.log(`[${this.getTime()}] [${logLevel.toUpperCase()}] ${message}`); | ||
} | ||
} | ||
|
||
|
||
getTime() { | ||
const now = new Date(); | ||
return now.toLocaleString(); | ||
} | ||
|
||
/** | ||
* @param {string} message | ||
*/ | ||
trace(message) { | ||
this.log(message, "trace"); | ||
} | ||
|
||
/** | ||
* @param {string} message | ||
*/ | ||
debug(message) { | ||
this.log(message, "debug"); | ||
} | ||
|
||
/** | ||
* @param {string} message | ||
*/ | ||
info(message) { | ||
this.log(message, "info"); | ||
} | ||
|
||
/** | ||
* @param {string} message | ||
*/ | ||
warn(message) { | ||
this.log(message, "warn"); | ||
} | ||
|
||
/** | ||
* @param {string} message | ||
*/ | ||
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
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
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
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