Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Support for Spacebar WebRTC #1108

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,560 changes: 2,432 additions & 128 deletions assets/schemas.json

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@
"@spacebar/api": "dist/api",
"@spacebar/cdn": "dist/cdn",
"@spacebar/gateway": "dist/gateway",
"@spacebar/util": "dist/util"
"@spacebar/util": "dist/util",
"@spacebar/webrtc": "dist/webrtc"
},
"optionalDependencies": {
"erlpack": "^0.1.4",
"medooze-media-server": "0.129.9",
"nodemailer-mailgun-transport": "^2.1.5",
"nodemailer-mailjet-transport": "github:n0script22/nodemailer-mailjet-transport",
"nodemailer-sendgrid-transport": "github:Maria-Golomb/nodemailer-sendgrid-transport",
"semantic-sdp": "3.26.0",
"sqlite3": "^5.1.6"
}
}
10 changes: 9 additions & 1 deletion src/bundle/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import http from "http";
import * as Api from "@spacebar/api";
import * as Gateway from "@spacebar/gateway";
import { CDNServer } from "@spacebar/cdn";
import * as Webrtc from "@spacebar/webrtc";
import express from "express";
import { green, bold } from "picocolors";
import { Config, initDatabase, Sentry } from "@spacebar/util";
Expand All @@ -36,12 +37,14 @@ server.on("request", app);
const api = new Api.SpacebarServer({ server, port, production, app });
const cdn = new CDNServer({ server, port, production, app });
const gateway = new Gateway.Server({ server, port, production });
const webrtc = new Webrtc.Server({ server, port, production });

process.on("SIGTERM", async () => {
console.log("Shutting down due to SIGTERM");
await gateway.stop();
await cdn.stop();
await api.stop();
await webrtc.stop();
server.close();
Sentry.close();
});
Expand All @@ -54,7 +57,12 @@ async function main() {
await new Promise((resolve) =>
server.listen({ port }, () => resolve(undefined)),
);
await Promise.all([api.start(), cdn.start(), gateway.start()]);
await Promise.all([
api.start(),
cdn.start(),
gateway.start(),
webrtc.start(),
]);

Sentry.errorHandler(app);

Expand Down
72 changes: 72 additions & 0 deletions src/bundle/WinServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

process.on("unhandledRejection", console.error);
process.on("uncaughtException", console.error);

import http from "http";
import * as Api from "@spacebar/api";
import * as Gateway from "@spacebar/gateway";
import { CDNServer } from "@spacebar/cdn";
//import * as Webrtc from "@spacebar/webrtc";
import express from "express";
import { green, bold } from "picocolors";
import { Config, initDatabase, Sentry } from "@spacebar/util";

const app = express();
const server = http.createServer();
const port = Number(process.env.PORT) || 3001;
const production = process.env.NODE_ENV == "development" ? false : true;
server.on("request", app);

const api = new Api.SpacebarServer({ server, port, production, app });
const cdn = new CDNServer({ server, port, production, app });
const gateway = new Gateway.Server({ server, port, production });
//const webrtc = new Webrtc.Server({ server, port, production });

process.on("SIGTERM", async () => {
console.log("Shutting down due to SIGTERM");
await gateway.stop();
await cdn.stop();
await api.stop();
// await webrtc.stop();
server.close();
Sentry.close();
});

async function main() {
await initDatabase();
await Config.init();
await Sentry.init(app);

await new Promise((resolve) =>
server.listen({ port }, () => resolve(undefined)),
);
await Promise.all([
api.start(),
cdn.start(),
gateway.start(),
// webrtc.start(),
]);

Sentry.errorHandler(app);

console.log(`[Server] ${green(`listening on port ${bold(port)}`)}`);
}

main().catch(console.error);
12 changes: 10 additions & 2 deletions src/bundle/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
console.log(`[Process] starting with ${cores} threads`);

if (cores === 1) {
require("./Server");
if (process.env.WEBRTC_DISABLE == "1" || process.platform == "win32") {
require("./WinServer");
} else {
require("./Server");
}
} else {
process.env.EVENT_TRANSMISSION = "process";

Expand Down Expand Up @@ -107,5 +111,9 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
});
}
} else {
require("./Server");
if (process.env.WEBRTC_DISABLE == "1" || process.platform == "win32") {
require("./WinServer");
} else {
require("./Server");
}
}
1 change: 1 addition & 0 deletions src/gateway/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class Server {
}

this.server.on("upgrade", (request, socket, head) => {
if (request.url?.includes("voice")) return;
MaddyUnderStars marked this conversation as resolved.
Show resolved Hide resolved
this.ws.handleUpgrade(request, socket, head, (socket) => {
this.ws.emit("connection", socket, request);
});
Expand Down
Loading
Loading