Updated support for static chat rooms, added disconnected auto reload

This commit is contained in:
Daniel Seripap 2016-12-25 22:57:57 -05:00
parent b31d758306
commit bd1fbb09a4
5 changed files with 56 additions and 6 deletions

View File

@ -40,7 +40,16 @@ function generateNewRoom(req, res, id) {
app.get('/', (req, res) => generateNewRoom(req, res, 'lobby') );
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;

View File

@ -9,14 +9,26 @@ import he from 'he';
export default class App {
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._socket = io(this._roomId);
this._chat = new Chat(this._darkwire, this._socket);
this._darkwire.connected = false;
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() {
this._chat = new Chat(this._darkwire, this._socket);
if (!this._roomId) { return; }
@ -104,6 +116,14 @@ export default class App {
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();
// Nav links
@ -249,8 +269,13 @@ export default class App {
addParticipantsMessage(data) {
let message = '';
let headerMsg = '';
const { numUsers } = data;
$('#participants').text(data.numUsers);
if (numUsers === 0) {
window.location.reload();
}
$('#participants').text(numUsers);
}
renderParticipantsList() {
@ -268,4 +293,10 @@ export default class App {
});
}
retryConnection() {
window.setTimeout(() => {
window.location.reload();
}, 10000);
}
}

View File

@ -25,7 +25,7 @@ export default class FileHandler {
}
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];
if (file) {

11
src/restricted.txt Normal file
View File

@ -0,0 +1,11 @@
admin
admins
about
about-us
darkwire
official
l0bby
10bby
1obby
i0bby
iobby

View File

@ -70,7 +70,6 @@ class Room {
// when the user disconnects.. perform this
socket.on('disconnect', () => {
console.log('disconnected');
if (addedUser) {
--this.numUsers;
this.users = _.without(this.users, socket.user);