mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-02-17 01:12:20 +00:00
List gather joins
This commit is contained in:
parent
703944a709
commit
1645c296e5
5 changed files with 120 additions and 21 deletions
|
@ -5,6 +5,7 @@
|
||||||
*
|
*
|
||||||
* Server API
|
* Server API
|
||||||
* gather:refresh - Refreshes active gather
|
* gather:refresh - Refreshes active gather
|
||||||
|
* gather:notification - Creates a notification
|
||||||
*
|
*
|
||||||
* Client API
|
* Client API
|
||||||
* gather:join - Assigns user to gather
|
* gather:join - Assigns user to gather
|
||||||
|
@ -13,23 +14,38 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Gather = require("./gather");
|
var Gather = require("./gather");
|
||||||
var latestGather = new Gather();
|
var gather = new Gather();
|
||||||
|
|
||||||
module.exports = function (namespace) {
|
module.exports = function (namespace) {
|
||||||
var refreshGather = function () {
|
var refreshGather = function () {
|
||||||
namespace.emit("gather:refresh", {
|
namespace.emit("gather:refresh", {
|
||||||
gather: gather
|
gather: gather.toJson()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace.on("connection", function (socket) {
|
namespace.on("connection", function (socket) {
|
||||||
|
|
||||||
socket.on("gather:join", function (data) {
|
socket.on("gather:join", function (data) {
|
||||||
|
if (gather.can("addGatherer")) {
|
||||||
|
gather.addGatherer(socket._user);
|
||||||
|
refreshGather();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("gather:leave", function (data) {
|
||||||
|
if (gather.can("removeGatherer")) {
|
||||||
|
gather.removeGatherer(socket._user);
|
||||||
|
refreshGather();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("disconnect", function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("gather:vote", function (data) {
|
socket.on("gather:vote", function (data) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
refreshGather();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -136,9 +136,8 @@ Gather.prototype.marines = function () {
|
||||||
|
|
||||||
Gather.prototype.toJson = function () {
|
Gather.prototype.toJson = function () {
|
||||||
return {
|
return {
|
||||||
lobby: this.lobby(),
|
gatherers: this.gatherers,
|
||||||
marines: this.marines(),
|
state: this.current
|
||||||
aliens: this.aliens()
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,12 @@ var UserLine = React.createClass({
|
||||||
});
|
});
|
||||||
|
|
||||||
var UserMenu = React.createClass({
|
var UserMenu = React.createClass({
|
||||||
|
getDefaultProps: function () {
|
||||||
|
return {
|
||||||
|
count: 0,
|
||||||
|
users: []
|
||||||
|
};
|
||||||
|
},
|
||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
socket.on('userCount', this.updateUsers);
|
socket.on('userCount', this.updateUsers);
|
||||||
},
|
},
|
||||||
|
@ -93,6 +99,11 @@ var UserMenu = React.createClass({
|
||||||
});
|
});
|
||||||
|
|
||||||
var Chatroom = React.createClass({
|
var Chatroom = React.createClass({
|
||||||
|
getDefaultProps: function () {
|
||||||
|
return {
|
||||||
|
history: []
|
||||||
|
};
|
||||||
|
},
|
||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
var TIMER_INTERVAL = 60000; // Every minute
|
var TIMER_INTERVAL = 60000; // Every minute
|
||||||
|
@ -129,7 +140,6 @@ var Chatroom = React.createClass({
|
||||||
},
|
},
|
||||||
scrollToBottom: function () {
|
scrollToBottom: function () {
|
||||||
var node = React.findDOMNode(this.refs.messageContainer);
|
var node = React.findDOMNode(this.refs.messageContainer);
|
||||||
console.log(node)
|
|
||||||
node.scrollTop = node.scrollHeight;
|
node.scrollTop = node.scrollHeight;
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
|
@ -234,16 +244,40 @@ var MessageBar = React.createClass({
|
||||||
});
|
});
|
||||||
|
|
||||||
var Gather = React.createClass({
|
var Gather = React.createClass({
|
||||||
|
getDefaultProps: function () {
|
||||||
|
return {
|
||||||
|
gather: {
|
||||||
|
gatherers: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
componentDidMount: function () {
|
||||||
|
var self = this;
|
||||||
|
socket.on("gather:refresh", function (data) {
|
||||||
|
self.setProps({
|
||||||
|
gather: data.gather
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
joinGather: function (e) {
|
joinGather: function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
alert("Joined gather!");
|
socket.emit("gather:join", {});
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
|
var gatherers = this.props.gather.gatherers.map(function (gatherer) {
|
||||||
|
console.log(gatherer)
|
||||||
|
return (<Gatherer gatherer={gatherer} />);
|
||||||
|
})
|
||||||
return (
|
return (
|
||||||
<div className="panel panel-default">
|
<div className="panel panel-default">
|
||||||
<div className="panel-heading">
|
<div className="panel-heading">
|
||||||
Current Gather
|
Current Gather
|
||||||
</div>
|
</div>
|
||||||
|
<table className="table">
|
||||||
|
<tbody>
|
||||||
|
{gatherers}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
<div className="panel-body">
|
<div className="panel-body">
|
||||||
</div>
|
</div>
|
||||||
<div className="panel-footer">
|
<div className="panel-footer">
|
||||||
|
@ -257,6 +291,14 @@ var Gather = React.createClass({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var Gatherer = React.createClass({
|
||||||
|
render: function () {
|
||||||
|
return (
|
||||||
|
<tr><td>{this.props.gatherer.user.username}</td></tr>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var socket;
|
var socket;
|
||||||
|
|
||||||
function initialiseComponents () {
|
function initialiseComponents () {
|
||||||
|
@ -272,9 +314,9 @@ function initialiseComponents () {
|
||||||
console.log("Disconnected")
|
console.log("Disconnected")
|
||||||
});
|
});
|
||||||
|
|
||||||
React.render(<UserMenu count={0} users={[]} />, document.getElementById('side-menu'));
|
React.render(<UserMenu />, document.getElementById('side-menu'));
|
||||||
React.render(<Chatroom history={[]}/>, document.getElementById('chatroom'));
|
React.render(<Chatroom />, document.getElementById('chatroom'));
|
||||||
React.render(<Gather history={[]}/>, document.getElementById('gathers'));
|
React.render(<Gather />, document.getElementById('gathers'));
|
||||||
};
|
};
|
||||||
|
|
||||||
initialiseComponents();
|
initialiseComponents();
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
this.time_zone = user['time_zone'];
|
this.time_zone = user['time_zone'];
|
||||||
this.avatar = client.baseUrl + user['avatar'];
|
this.avatar = client.baseUrl + user['avatar'];
|
||||||
this.admin = user['admin'];
|
this.admin = user['admin'];
|
||||||
this.steam = {
|
// this.steam = {
|
||||||
url: user['steam']['url'],
|
// url: user['steam']['url'],
|
||||||
nickname: user['steam']['nickname']
|
// nickname: user['steam']['nickname']
|
||||||
};
|
// };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = User;
|
module.exports = User;
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue