mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-22 12:41:11 +00:00
Refactored and added ensl client
This commit is contained in:
parent
5c2fa4f34a
commit
e293e1b5ca
7 changed files with 156 additions and 30 deletions
|
@ -2,23 +2,26 @@
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
var enslClient = require(path.join(__dirname, "../lib/ensl/client"))();
|
||||||
var chatController = require(path.join(__dirname, "../lib/chat/controller"));
|
var chatController = require(path.join(__dirname, "../lib/chat/controller"));
|
||||||
|
|
||||||
module.exports = function (io) {
|
module.exports = function (io) {
|
||||||
var root = io.of("/");
|
var root = io.of("/");
|
||||||
var authorised = io.of("/authorised");
|
var authorised = io.of("/authorised");
|
||||||
|
|
||||||
|
|
||||||
|
var id = 2131;
|
||||||
|
|
||||||
// Authorisation
|
// Authorisation
|
||||||
root.use(function (socket, next) {
|
root.use(function (socket, next) {
|
||||||
socket._user = {
|
enslClient.getUserById({
|
||||||
id: Math.floor(Math.random () * 10000000),
|
id: id
|
||||||
username: "Chris (" + socket.id.slice(0,5) + ")",
|
}, function (error, response, body) {
|
||||||
steamId: "11111111",
|
if (error) return next(error);
|
||||||
email: "cablanchard@gmail.com",
|
socket._user = body;
|
||||||
bans: [],
|
socket._user.avatar = enslClient.getFullAvatarUri(socket._user.avatar);
|
||||||
avatar: "http://www.ensl.org/local/avatars/6359.jpg"
|
next();
|
||||||
};
|
});
|
||||||
next();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var refreshGatherers = function (socket) {
|
var refreshGatherers = function (socket) {
|
||||||
|
|
27
lib/ensl/client.js
Normal file
27
lib/ensl/client.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var request = require("request");
|
||||||
|
var env = process.env.NODE_ENV || "development";
|
||||||
|
|
||||||
|
function EnslClient (options) {
|
||||||
|
if (!(this instanceof EnslClient)) {
|
||||||
|
return new EnslClient(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.baseUrl = (env === "production") ? "http://www.ensl.org/" : "http://staging.ensl.org";
|
||||||
|
}
|
||||||
|
|
||||||
|
EnslClient.prototype.getUserById = function (options, callback) {
|
||||||
|
var id = options.id;
|
||||||
|
var url = this.baseUrl + "/api/v1/users/" + id;
|
||||||
|
request({
|
||||||
|
url: url,
|
||||||
|
json: true
|
||||||
|
}, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
EnslClient.prototype.getFullAvatarUri = function (url) {
|
||||||
|
return this.baseUrl + url;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = EnslClient;
|
|
@ -1,3 +1,7 @@
|
||||||
|
$(function () {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var GatherCounter = React.createClass({
|
var GatherCounter = React.createClass({
|
||||||
render: function () {
|
render: function () {
|
||||||
return (
|
return (
|
||||||
|
@ -11,6 +15,32 @@ var GatherCounter = React.createClass({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var UserLogin = React.createClass({
|
||||||
|
handleSubmit: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
render: function () {
|
||||||
|
return (
|
||||||
|
<form onSubmit={this.handleSubmit} >
|
||||||
|
<div className="input-group">
|
||||||
|
<input
|
||||||
|
id="btn-input"
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
placeholder="Choose an ID..." />
|
||||||
|
<span className="input-group-btn">
|
||||||
|
<input
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-primary"
|
||||||
|
id="btn-chat"
|
||||||
|
value="Login" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var Gatherer = React.createClass({
|
var Gatherer = React.createClass({
|
||||||
render: function () {
|
render: function () {
|
||||||
return (
|
return (
|
||||||
|
@ -39,6 +69,9 @@ var GathererMenu = React.createClass({
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<ul className="nav" id="side-menu">
|
<ul className="nav" id="side-menu">
|
||||||
|
<li>
|
||||||
|
<UserLogin />
|
||||||
|
</li>
|
||||||
<GatherCounter {...this.props} />
|
<GatherCounter {...this.props} />
|
||||||
{gatherers}
|
{gatherers}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -186,5 +219,27 @@ var MessageBar = React.createClass({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
React.render(<GathererMenu count={0} gatherers={[]} />, document.getElementById('side-menu'));
|
var socket;
|
||||||
React.render(<Chatroom history={[]}/>, document.getElementById('chatroom'));
|
|
||||||
|
function initialiseComponents () {
|
||||||
|
socket = io("http://localhost:8000/")
|
||||||
|
.on("connect", function () {
|
||||||
|
console.log("Connected");
|
||||||
|
})
|
||||||
|
.on("reconnect", function () {
|
||||||
|
console.log("Reconnected");
|
||||||
|
})
|
||||||
|
.on("disconnect", function () {
|
||||||
|
console.log("Disconnected")
|
||||||
|
});
|
||||||
|
|
||||||
|
React.render(<GathererMenu count={0} gatherers={[]} />, document.getElementById('side-menu'));
|
||||||
|
React.render(<Chatroom history={[]}/>, document.getElementById('chatroom'));
|
||||||
|
};
|
||||||
|
|
||||||
|
initialiseComponents();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "NODE_ENV=test mocha spec/",
|
"test": "NODE_ENV=test mocha spec/",
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"compile:dev:react": "node_modules/react-tools/bin/jsx --watch --source-map-inline -x jsx lib/react/ public/js/",
|
"compile:dev:react": "node_modules/react-tools/bin/jsx --watch --no-cache-dir --source-map-inline -x jsx lib/react/ public/js/",
|
||||||
"compile:react": "node_modules/react-tools/bin/jsx -x jsx lib/react/ public/js/",
|
"compile:react": "node_modules/react-tools/bin/jsx -x jsx lib/react/ public/js/",
|
||||||
"dev": "nodemon index.js"
|
"dev": "nodemon index.js"
|
||||||
},
|
},
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
"morgan": "~1.6.1",
|
"morgan": "~1.6.1",
|
||||||
"node-mysql": "~0.4.2",
|
"node-mysql": "~0.4.2",
|
||||||
"react-tools": "~0.13.3",
|
"react-tools": "~0.13.3",
|
||||||
"request": "^2.60.0",
|
"request": "~2.60.0",
|
||||||
"socket.io": "~1.3.5",
|
"socket.io": "~1.3.5",
|
||||||
"winston": "~1.0.1"
|
"winston": "~1.0.1"
|
||||||
},
|
},
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,13 +0,0 @@
|
||||||
var socket = io("http://localhost:8000/");
|
|
||||||
|
|
||||||
socket.on("connect", function () {
|
|
||||||
console.log("Connected!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// socket.on("reconnect", function () {
|
|
||||||
|
|
||||||
// });
|
|
||||||
|
|
||||||
// socket.on("disconnect", function () {
|
|
||||||
|
|
||||||
// });
|
|
|
@ -1,2 +1 @@
|
||||||
<script src="/js/client.js"></script>
|
|
||||||
<script src="/js/app.js"></script>
|
<script src="/js/app.js"></script>
|
Loading…
Reference in a new issue