diff --git a/src/app/channel/message.js b/src/app/pm/message.js similarity index 100% rename from src/app/channel/message.js rename to src/app/pm/message.js diff --git a/src/app/pm/pmHandler.js b/src/app/pm/pmHandler.js new file mode 100644 index 0000000..29b4ad1 --- /dev/null +++ b/src/app/pm/pmHandler.js @@ -0,0 +1,51 @@ +/*Canopy - The next generation of stoner streaming software +Copyright (C) 2024-2025 Rainbownapkin and the TTN Community + +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 .*/ + +//local includes +const config = require("../../../config.json"); +const csrfUtils = require("../../utils/csrfUtils"); +const userBanModel = require("../../schemas/user/userBanSchema"); + +/** + * Class containg global server-side private message relay logic + */ +class pmHandler{ + /** + * Instantiates object containing global server-side private message relay logic + * @param {Socket.io} io - Socket.io server instanced passed down from server.js + */ + constructor(io){ + /** + * Socket.io server instance passed down from server.js + */ + this.io = io; + + /** + * Socket.io server namespace for handling messaging + */ + this.namespace = io.of('/pm'); + + //Handle connections from private messaging namespace + this.namespace.on("connection", this.handleConnection.bind(this) ); + } + + async handleConnection(socket){ + + } + +} + +module.exports = pmHandler; \ No newline at end of file diff --git a/src/server.js b/src/server.js index f584830..6005d30 100644 --- a/src/server.js +++ b/src/server.js @@ -33,6 +33,7 @@ const mongoose = require('mongoose'); //Define Local Imports //Application const channelManager = require('./app/channel/channelManager'); +const pmHandler = require('./app/pm/pmHandler'); //Util const configCheck = require('./utils/configCheck'); const scheduler = require('./utils/scheduler'); @@ -196,6 +197,7 @@ scheduler.kickoff(); //Hand over general-namespace socket.io connections to the channel manager module.exports.channelManager = new channelManager(io) +module.exports.pmHandler = new pmHandler(io) //Listen Function webServer.listen(port, () => { diff --git a/www/js/channel/channel.js b/www/js/channel/channel.js index fd72349..f7955d1 100644 --- a/www/js/channel/channel.js +++ b/www/js/channel/channel.js @@ -68,12 +68,15 @@ class channel{ * Handles initial client connection */ connect(){ - this.socket = io({ - extraHeaders: { + const clientOptions = { + extraHeaders: { //Include CSRF token 'x-csrf-token': utils.ajax.getCSRFToken() } - }); + }; + + this.socket = io(clientOptions); + this.pmSocket = io("/pm", clientOptions); } /**