Skip to content

Commit

Permalink
rooms dynamic update complete
Browse files Browse the repository at this point in the history
  • Loading branch information
tameeshB committed Dec 31, 2017
1 parent 83684c3 commit 3fe680e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 8 additions & 4 deletions public/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class RoomsContainer extends React.Component {
constructor(props) {
super(props);
this.switchRoom = this.switchRoom.bind(this);
this.newThreadPrompt = this.newThreadPrompt.bind(this);
}
// this.props.data
/*
Expand Down Expand Up @@ -229,7 +230,7 @@ class RoomsContainer extends React.Component {
if (data.status == 409) {
var roomPass = prompt("Enter the room access password", "Password here");
} else if (data.status == 200) {
var roomPass = prompt("Enter desired password for new room. Leave blank for no password", "Password here");
var roomPass = prompt("Enter desired password for new room. Leave blank for no password", "");
}else{
alert(data.message);
return;
Expand All @@ -241,16 +242,19 @@ class RoomsContainer extends React.Component {
});
socket.on('roomPassCheckRet',function(data_){
console.log(data_);
})
})
if(data_.status!=200)
return alert(data_.message);
this.props.newRoom(data_.room.roomname);
}.bind(this))
}.bind(this))
}
}
render() {//class component
return (
<div>
<div className="compose has-text-centered" id="newThreadParent">
<a onClick={this.newThreadPrompt} className="button is-danger is-block is-bold">
<span className="compose">New Thread</span>
<span className="compose">New/Join Thread</span>
</a>
</div>
<div className="main">
Expand Down
13 changes: 11 additions & 2 deletions server_sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ module.exports = function (app, io, db) {
id: newRoomId,
roomname: data.roomName
});
socketonline[data.roomName] = [socket.id];
online[data.roomName] = [socket.username];
socket.emit('roomPassCheckRet', {
status: 200,
message: 'Created new room!',
Expand All @@ -194,8 +196,7 @@ module.exports = function (app, io, db) {
if (newrooms_.indexOf(data.roomName) >= 0) {
//nothing
} else {
console.log('\x1b[36m%s\x1b[0m', "DID NOT DETECT ROOM");
//1) make subdoc unique.
//1) make subdoc unique. @todo
//2) proper callback/async
//can add user to group
//@async
Expand Down Expand Up @@ -227,6 +228,14 @@ module.exports = function (app, io, db) {
}
})
}
if (socketonline[data.roomName])
socketonline[data.roomName].push(socket.id);
else
socketonline[data.roomName] = [socket.id];
if (online[data.roomName])
online[data.roomName].push(socket.username);
else
online[data.roomName] = [socket.username];
socket.emit('roomPassCheckRet', {
status: 200,
message: 'Joined room!',
Expand Down

0 comments on commit 3fe680e

Please sign in to comment.