74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
/*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/>.*/
|
|
|
|
class channel{
|
|
constructor(){
|
|
//Establish connetion to the server via socket.io
|
|
this.connect();
|
|
//Define socket listeners
|
|
this.defineListeners();
|
|
|
|
//Scrape channel name off URL
|
|
this.channelName = window.location.pathname.split('/c/')[`1`];
|
|
|
|
//Create the Video Player Object
|
|
this.player = new player(this);
|
|
//Create the Chat Box Object
|
|
this.chatBox = new chatBox(this);
|
|
//Create the User List Object
|
|
this.userList = new userList(this);
|
|
//Create the Canopy Panel Object
|
|
this.cPanel = new cPanel(this);
|
|
}
|
|
|
|
connect(){
|
|
this.socket = io({
|
|
extraHeaders: {
|
|
//Include CSRF token
|
|
'x-csrf-token': utils.ajax.getCSRFToken()
|
|
}
|
|
});
|
|
}
|
|
|
|
defineListeners(){
|
|
this.socket.on("connect", () => {
|
|
document.title = `${this.channelName} - Connected`
|
|
});
|
|
|
|
this.socket.on("kick", (data) => {
|
|
new canopyUXUtils.popup(`You have been ${data.type} from the channel for the following reason:<br>${data.reason}`);
|
|
});
|
|
|
|
this.socket.on("clientMetadata", this.handleClientInfo.bind(this));
|
|
|
|
this.socket.on("error", console.log);
|
|
}
|
|
|
|
handleClientInfo(data){
|
|
//Ingest user data
|
|
this.user = data.user;
|
|
|
|
//Re-hydrate permission maps
|
|
this.user.permMap.site = new Map(data.user.permMap.site);
|
|
this.user.permMap.chan = new Map(data.user.permMap.chan);
|
|
|
|
//Tell the chatbox to handle client info
|
|
//should it have its own event listener instead? Guess it's a stylistic choice :P
|
|
this.chatBox.handleClientInfo(data);
|
|
}
|
|
}
|
|
|
|
const client = new channel(); |