mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-18 10:49:02 +00:00
Updated support for static chat rooms, added disconnected auto reload
This commit is contained in:
parent
b31d758306
commit
bd1fbb09a4
11
src/app.js
11
src/app.js
@ -40,7 +40,16 @@ function generateNewRoom(req, res, id) {
|
|||||||
app.get('/', (req, res) => generateNewRoom(req, res, 'lobby') );
|
app.get('/', (req, res) => generateNewRoom(req, res, 'lobby') );
|
||||||
|
|
||||||
app.get('/:roomId', (req, res) => {
|
app.get('/:roomId', (req, res) => {
|
||||||
const roomId = req.params.roomId || false;
|
const stripName = (name) => {
|
||||||
|
const chatName = name.toLowerCase().replace(/[^A-Za-z0-9]/g, '-');
|
||||||
|
if (chatName.length >= 25) {
|
||||||
|
return chatName.substr(0, 25);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chatName;
|
||||||
|
};
|
||||||
|
|
||||||
|
const roomId = stripName(req.params.roomId) || false;
|
||||||
|
|
||||||
let roomExists = _.findWhere(rooms, {_id: roomId}) || false;
|
let roomExists = _.findWhere(rooms, {_id: roomId}) || false;
|
||||||
|
|
||||||
|
@ -9,14 +9,26 @@ import he from 'he';
|
|||||||
export default class App {
|
export default class App {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._roomId = window.location.pathname.length ? window.location.pathname : null;
|
this._roomId = window.location.pathname.length ? this.stripName(window.location.pathname) : null;
|
||||||
this._darkwire = new Darkwire();
|
this._darkwire = new Darkwire();
|
||||||
this._socket = io(this._roomId);
|
this._socket = io(this._roomId);
|
||||||
this._chat = new Chat(this._darkwire, this._socket);
|
this._darkwire.connected = false;
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stripName(name) {
|
||||||
|
const chatName = name.replace('/','').toLowerCase().replace(/[^A-Za-z0-9]/g, '-');
|
||||||
|
if (chatName.length >= 25) {
|
||||||
|
const limitedChatName = chatName.substr(0, 25);
|
||||||
|
window.history.replaceState( {} , limitedChatName, `/${limitedChatName}` );
|
||||||
|
return `/${limitedChatName}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '/' + chatName;
|
||||||
|
};
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
this._chat = new Chat(this._darkwire, this._socket);
|
||||||
|
|
||||||
if (!this._roomId) { return; }
|
if (!this._roomId) { return; }
|
||||||
|
|
||||||
@ -104,6 +116,14 @@ export default class App {
|
|||||||
this._chat.removeChatTyping(data);
|
this._chat.removeChatTyping(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._socket.on('disconnect', (data) => {
|
||||||
|
this._darkwire.connected = false;
|
||||||
|
this._chat.log('Disconnected from server, automatically reloading chatroom in 10 seconds.', {
|
||||||
|
error: true,
|
||||||
|
});
|
||||||
|
this.retryConnection();
|
||||||
|
});
|
||||||
|
|
||||||
this.initChat();
|
this.initChat();
|
||||||
|
|
||||||
// Nav links
|
// Nav links
|
||||||
@ -249,8 +269,13 @@ export default class App {
|
|||||||
addParticipantsMessage(data) {
|
addParticipantsMessage(data) {
|
||||||
let message = '';
|
let message = '';
|
||||||
let headerMsg = '';
|
let headerMsg = '';
|
||||||
|
const { numUsers } = data;
|
||||||
|
|
||||||
$('#participants').text(data.numUsers);
|
if (numUsers === 0) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#participants').text(numUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderParticipantsList() {
|
renderParticipantsList() {
|
||||||
@ -268,4 +293,10 @@ export default class App {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retryConnection() {
|
||||||
|
window.setTimeout(() => {
|
||||||
|
window.location.reload();
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ export default class FileHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
confirmTransfer(event) {
|
confirmTransfer(event) {
|
||||||
const validFileTypes = ['png','jpg','jpeg','gif','zip','rar','gzip','pdf','txt','json','doc','docx'];
|
const validFileTypes = ['png','jpg','jpeg','gif','zip','rar','gzip','pdf','txt','json','doc','docx','csv','js','html','css'];
|
||||||
const file = event.target.files && event.target.files[0];
|
const file = event.target.files && event.target.files[0];
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
|
11
src/restricted.txt
Normal file
11
src/restricted.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
admin
|
||||||
|
admins
|
||||||
|
about
|
||||||
|
about-us
|
||||||
|
darkwire
|
||||||
|
official
|
||||||
|
l0bby
|
||||||
|
10bby
|
||||||
|
1obby
|
||||||
|
i0bby
|
||||||
|
iobby
|
@ -70,7 +70,6 @@ class Room {
|
|||||||
|
|
||||||
// when the user disconnects.. perform this
|
// when the user disconnects.. perform this
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
console.log('disconnected');
|
|
||||||
if (addedUser) {
|
if (addedUser) {
|
||||||
--this.numUsers;
|
--this.numUsers;
|
||||||
this.users = _.without(this.users, socket.user);
|
this.users = _.without(this.users, socket.user);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user