Split pmHandler to create auxServer class for easy creation of server classes auxiliary to the channel.
This commit is contained in:
parent
d874f5e2da
commit
597a984e46
79
src/app/auxServer.js
Normal file
79
src/app/auxServer.js
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*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 <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
|
//local includes
|
||||||
|
const loggerUtils = require("../utils/loggerUtils");
|
||||||
|
const socketUtils = require("../utils/socketUtils");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class containg global server-side logic for handling namespaces outside of the main one
|
||||||
|
*/
|
||||||
|
class auxServer{
|
||||||
|
/**
|
||||||
|
* Instantiates object containing global server-side private message relay logic
|
||||||
|
* @param {Socket.io} io - Socket.io server instanced passed down from server.js
|
||||||
|
* @param {channelManager} chanServer - Sister channel management server object
|
||||||
|
*/
|
||||||
|
constructor(io, chanServer, namespace){
|
||||||
|
/**
|
||||||
|
* Socket.io server instance passed down from server.js
|
||||||
|
*/
|
||||||
|
this.io = io;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sister channel management server object
|
||||||
|
*/
|
||||||
|
this.chanServer = chanServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Socket.io server namespace for handling messaging
|
||||||
|
*/
|
||||||
|
this.namespace = io.of(namespace);
|
||||||
|
|
||||||
|
//Handle connections from private messaging namespace
|
||||||
|
this.namespace.on("connection", this.handleConnection.bind(this) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles global server-side initialization for new connections to aux server
|
||||||
|
* @param {Socket} socket - Requesting Socket
|
||||||
|
*/
|
||||||
|
async handleConnection(socket){
|
||||||
|
try{
|
||||||
|
//ensure unbanned ip and valid CSRF token
|
||||||
|
if(!(await socketUtils.validateSocket(socket))){
|
||||||
|
socket.disconnect();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//If the socket wasn't authorized
|
||||||
|
if(await socketUtils.authSocketLite(socket) == null){
|
||||||
|
socket.disconnect();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}catch(err){
|
||||||
|
//Flip a table if something fucks up
|
||||||
|
return loggerUtils.socketCriticalExceptionHandler(socket, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineListeners(socket){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = auxServer;
|
||||||
|
|
@ -14,44 +14,25 @@ GNU Affero General Public License for more details.
|
||||||
You should have received a copy of the GNU Affero General Public License
|
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/>.*/
|
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//NPM Imports
|
|
||||||
const validator = require('validator');//No express here, so regular validator it is!
|
|
||||||
|
|
||||||
//local includes
|
//local includes
|
||||||
|
const auxServer = require('../auxServer');
|
||||||
const chatPreprocessor = require('../chatPreprocessor');
|
const chatPreprocessor = require('../chatPreprocessor');
|
||||||
const loggerUtils = require("../../utils/loggerUtils");
|
const loggerUtils = require("../../utils/loggerUtils");
|
||||||
const socketUtils = require("../../utils/socketUtils");
|
|
||||||
const message = require("./message");
|
const message = require("./message");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class containg global server-side private message relay logic
|
* Class containg global server-side private message relay logic
|
||||||
*/
|
*/
|
||||||
class pmHandler{
|
class pmHandler extends auxServer{
|
||||||
/**
|
/**
|
||||||
* Instantiates object containing global server-side private message relay logic
|
* Instantiates object containing global server-side private message relay logic
|
||||||
* @param {Socket.io} io - Socket.io server instanced passed down from server.js
|
* @param {Socket.io} io - Socket.io server instanced passed down from server.js
|
||||||
* @param {channelManager} chanServer - Sister channel management server object
|
* @param {channelManager} chanServer - Sister channel management server object
|
||||||
*/
|
*/
|
||||||
constructor(io, chanServer){
|
constructor(io, chanServer){
|
||||||
/**
|
super(io, chanServer, "/pm");
|
||||||
* Socket.io server instance passed down from server.js
|
|
||||||
*/
|
|
||||||
this.io = io;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sister channel management server object
|
|
||||||
*/
|
|
||||||
this.chanServer = chanServer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Socket.io server namespace for handling messaging
|
|
||||||
*/
|
|
||||||
this.namespace = io.of('/pm');
|
|
||||||
|
|
||||||
this.chatPreprocessor = new chatPreprocessor(null, null);
|
this.chatPreprocessor = new chatPreprocessor(null, null);
|
||||||
|
|
||||||
//Handle connections from private messaging namespace
|
|
||||||
this.namespace.on("connection", this.handleConnection.bind(this) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -59,31 +40,21 @@ class pmHandler{
|
||||||
* @param {Socket} socket - Requesting Socket
|
* @param {Socket} socket - Requesting Socket
|
||||||
*/
|
*/
|
||||||
async handleConnection(socket){
|
async handleConnection(socket){
|
||||||
try{
|
//Check if we're properly authorized
|
||||||
//ensure unbanned ip and valid CSRF token
|
const authorized = await super.handleConnection(socket, "${user}");
|
||||||
if(!(await socketUtils.validateSocket(socket))){
|
|
||||||
socket.disconnect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If the socket wasn't authorized
|
//If we're authorized
|
||||||
if(await socketUtils.authSocketLite(socket) == null){
|
if(authorized){
|
||||||
socket.disconnect();
|
//Throw the user into their own unique channel
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Throw socket into room named after it's user
|
|
||||||
socket.join(socket.user.user);
|
socket.join(socket.user.user);
|
||||||
|
|
||||||
//Define network related event listeners against socket
|
//Define listeners
|
||||||
this.defineListeners(socket);
|
this.defineListeners(socket);
|
||||||
}catch(err){
|
|
||||||
//Flip a table if something fucks up
|
|
||||||
return loggerUtils.socketCriticalExceptionHandler(socket, err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defineListeners(socket){
|
defineListeners(socket){
|
||||||
|
super.defineListeners(socket);
|
||||||
socket.on("pm", (data)=>{this.handlePM(data, socket)});
|
socket.on("pm", (data)=>{this.handlePM(data, socket)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -369,7 +369,6 @@ class pmPanel extends panelObj{
|
||||||
handleAutoScroll(){
|
handleAutoScroll(){
|
||||||
//If autoscroll is enabled
|
//If autoscroll is enabled
|
||||||
if(this.autoScroll){
|
if(this.autoScroll){
|
||||||
console.log("SCROLLME");
|
|
||||||
//Set seshBuffer scrollTop to the difference between scrollHeight and buffer height (scroll to the bottom)
|
//Set seshBuffer scrollTop to the difference between scrollHeight and buffer height (scroll to the bottom)
|
||||||
this.seshBuffer.scrollTop = this.seshBuffer.scrollHeight - Math.round(this.seshBuffer.getBoundingClientRect().height);
|
this.seshBuffer.scrollTop = this.seshBuffer.scrollHeight - Math.round(this.seshBuffer.getBoundingClientRect().height);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue