changed Project Stucture - Part2

This commit is contained in:
Julian Lechner
2025-04-06 16:42:30 +02:00
parent 2085339bdb
commit d28c19dd0b
10 changed files with 62 additions and 28 deletions
+9
View File
@@ -4,6 +4,15 @@
![GitHub package.json version](https://img.shields.io/github/package-json/v/FrauJulian/discord-audio-stream)
![GitHub Repo stars](https://img.shields.io/github/stars/FrauJulian/discord-audio-stream?style=social)
# !ATTENTION!
Usefully Links to write docs:
ConnectionOptions:
- https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Connection.d.ts#L82
# !ATTENTION!
<p>This NPM package was created to make it easier to stream audio to Discord.</p>
<p>There is a security feature of discord that stops the stream of audio after some time. This problem can be solved by disconnecting the Discord channel every 1.5 hours for 2 seconds and then reconnecting the channel. (If you use this package!) I recommend using a database to store the data e.g. MySQL, SQLite, json file and other database types.</p>
<p>The package does not fix this error yet. However, it is currently being worked on!</p>
-5
View File
@@ -1,5 +0,0 @@
import {AudioStreamManager} from "./src";
let temp = new AudioStreamManager("MySql", "frg");
console.log(temp);
+7
View File
@@ -18,6 +18,13 @@
"audio",
"music"
],
"contributors": [
{
"name": "Julian Lechner aka. FrauJulian",
"github": "https://github.com/FrauJulian",
"web": "https://fraujulian.xyz/"
}
],
"author": "FrauJulian | Julian Lechner",
"license": "CUSTOM-LICENSE",
"bugs": {
+3
View File
@@ -0,0 +1,3 @@
export interface IJsonDao {
}
+11
View File
@@ -0,0 +1,11 @@
import {IJsonDao} from "./IJsonDao";
import {Config, JsonDB} from "node-json-db";
export class JsonDao implements IJsonDao {
private _jsonDatabaseContext: JsonDB;
constructor(fileLocation: string) {
this._jsonDatabaseContext = new JsonDB(new Config(fileLocation, true, false, "/", true));
}
}
+3
View File
@@ -0,0 +1,3 @@
export interface IMySqlDao {
}
+17
View File
@@ -0,0 +1,17 @@
import {IMySqlDao} from "./IMySqlDao";
import mysql, {Connection, ConnectionOptions} from 'mysql2/promise';
import {Connection as BaseConnection} from "mysql2/typings/mysql/lib/Connection";
export class MysqlDao implements IMySqlDao {
private _mysqlDatabaseContext!: Connection;
constructor(mysqlAuthenticationData: ConnectionOptions) {
this.InitializeDatabaseContext(mysqlAuthenticationData).catch(error => {
throw new Error(error)
});
}
private async InitializeDatabaseContext(mysqlAuthenticationData: ConnectionOptions): Promise<void> {
this._mysqlDatabaseContext = await mysql.createConnection(mysqlAuthenticationData);
}
}
@@ -1,30 +1,19 @@
import {JsonDatabaseServices} from "../../InternalServices/DatabaseServices/JsonDatabaseServices";
import {MySqlDatabaseServices} from "../../InternalServices/DatabaseServices/MySqlDatabaseServices";
import {Constants} from "../../Core/Contants";
import {ConnectionOptions} from "mysql2/promise";
export class AudioStreamManager {
constructor(
databaseType: "Json" | "MySql",
databaseOptions: {
Host: string;
Port: number;
Username: string;
Password: string;
Database: string;
} | string) {
constructor(databaseType: "Json" | "MySql", databaseOptions: ConnectionOptions | string) {
if (databaseType === "MySql" &&
databaseOptions &&
typeof databaseOptions === "object") {
console.log("mysql passed")
Constants.DatabaseServices = new MySqlDatabaseServices(databaseOptions);
} else if (databaseType === "Json" &&
databaseOptions &&
typeof databaseOptions === "string") {
console.log("json passed")
Constants.DatabaseServices = new JsonDatabaseServices(databaseOptions);
} else {
console.log("err passed")
throw new Error("Failed validating database.")
}
}
@@ -1,7 +1,10 @@
import {IDatabaseServices} from "./IDatabaseServices";
import {JsonDao} from "../../DataAccess/Json/JsonDao";
export class JsonDatabaseServices implements IDatabaseServices {
constructor(databaseOptions : string) {
// IMPLEMENT DATABASE
private _databaseDao: JsonDao;
constructor(databaseOptions : any) {
this._databaseDao = new JsonDao(databaseOptions);
}
}
@@ -1,14 +1,11 @@
import {IDatabaseServices} from "./IDatabaseServices";
import {MysqlDao} from "../../DataAccess/MySql/MysqlDao";
import {ConnectionOptions} from "mysql2/promise";
export class MySqlDatabaseServices implements IDatabaseServices {
private _databaseDao: MysqlDao;
constructor(databaseOptions: {
Host: string;
Port: number;
Username: string;
Password: string;
Database: string;
}) {
//IMPLEMENT DATABASE
constructor(databaseOptions: ConnectionOptions) {
this._databaseDao = new MysqlDao(databaseOptions);
}
}