2016-01-26 10:44:34 +00:00
|
|
|
import {Events} from "javascripts/components/event";
|
|
|
|
import {CurrentUser, AdminPanel, ProfileModal, UserMenu} from "javascripts/components/user";
|
|
|
|
import {SoundPanel} from "javascripts/components/sound";
|
|
|
|
import {TeamSpeakButton, TeamSpeakModal} from "javascripts/components/teamspeak";
|
|
|
|
import {SettingsPanel} from "javascripts/components/settings";
|
|
|
|
import {Chatroom} from "javascripts/components/message";
|
|
|
|
import {Gather, ArchivedGathers} from "javascripts/components/gather"
|
|
|
|
|
2016-01-22 10:12:23 +00:00
|
|
|
const React = require("react");
|
|
|
|
const Sound = require("javascripts/components/sound");
|
2016-01-26 10:44:34 +00:00
|
|
|
const SoundController = Sound.SoundController;
|
2016-01-22 21:39:03 +00:00
|
|
|
const helper = require("javascripts/helper");
|
|
|
|
const storageAvailable = helper.storageAvailable;
|
2016-01-22 10:12:23 +00:00
|
|
|
const SplashScreen = React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
2016-01-26 10:44:34 +00:00
|
|
|
status: "connecting",
|
2016-01-22 10:12:23 +00:00
|
|
|
socket: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const socketUrl = window.location.protocol + "//" + window.location.host;
|
|
|
|
let socket = io(socketUrl)
|
|
|
|
.on("connect", () => {
|
|
|
|
console.log("Connected");
|
2016-01-26 10:44:34 +00:00
|
|
|
this.setState({ status: "connected" });
|
|
|
|
socket
|
|
|
|
.on("reconnect", () => {
|
2016-01-22 10:12:23 +00:00
|
|
|
console.log("Reconnected");
|
|
|
|
})
|
|
|
|
.on("disconnect", () => {
|
|
|
|
console.log("Disconnected")
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.on("error", error => {
|
|
|
|
console.log(error);
|
|
|
|
if (error === "Authentication Failed") {
|
|
|
|
this.setState({ status: "authFailed" });
|
|
|
|
} else if (error === "Gather Banned") {
|
|
|
|
this.setState({ status: "banned" });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setState({ socket: socket });
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const status = this.state.status;
|
2016-01-26 10:44:34 +00:00
|
|
|
|
2016-01-22 10:12:23 +00:00
|
|
|
if (status === "connected") {
|
|
|
|
return <App socket={this.state.socket} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
let splash;
|
|
|
|
if (status === "authFailed") {
|
2016-01-26 10:44:34 +00:00
|
|
|
splash = <AuthFailedSplash />;
|
2016-01-22 10:12:23 +00:00
|
|
|
} else if (status === "banned") {
|
2016-01-26 10:44:34 +00:00
|
|
|
splash = <BannedSplash />;
|
|
|
|
} else if (status === "connecting") {
|
|
|
|
splash = <ConnectingSplash />;
|
2016-01-22 10:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2016-01-26 10:44:34 +00:00
|
|
|
<div style={{"minHeight": "750px"}}>
|
|
|
|
<div className="container-fluid">
|
2016-01-22 10:12:23 +00:00
|
|
|
{splash}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const AuthFailedSplash = React.createClass({
|
|
|
|
render() {
|
|
|
|
return (
|
2016-01-26 10:44:34 +00:00
|
|
|
<div className="row" id="auth-required">
|
|
|
|
<div className="col-lg-6 col-lg-offset-3">
|
|
|
|
<div className="add-top jumbotron jumbo-auth text-center">
|
2016-01-22 10:12:23 +00:00
|
|
|
<div>
|
|
|
|
<img src="/ensl_logo.png" alt="ENSL Logo" />
|
|
|
|
</div>
|
|
|
|
<h3>You need to be logged in to the ENSL website to access gathers</h3>
|
|
|
|
<h3><small>If you are logged on, try visiting a few pages on ENSL.org so the server can update your cookies</small></h3>
|
|
|
|
<h3><small>If this error persists please contact an admin to fix it</small></h3>
|
|
|
|
<br />
|
2016-01-26 10:44:34 +00:00
|
|
|
<p><a className="btn btn-primary btn-lg" href="www.ensl.org" role="button">Go to website</a></p>
|
2016-01-22 10:12:23 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const BannedSplash = React.createClass({
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-lg-6 col-lg-offset-3">
|
|
|
|
<div className="add-top jumbotron jumbo-auth text-center">
|
|
|
|
<div>
|
|
|
|
<img src="/ensl_logo.png" alt="ENSL Logo" />
|
|
|
|
</div>
|
|
|
|
<h3>You're currently barred from joining gathers</h3>
|
|
|
|
<h3><small>Either wait for the ban to expire or talk to an admin to get it lifted</small></h3>
|
|
|
|
<br />
|
|
|
|
<p><a className="btn btn-primary btn-lg" href="http://www.ensl.org/bans" role="button">See the ban list</a></p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const ConnectingSplash = React.createClass({
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="row" id="authenticating">
|
|
|
|
<div className="col-lg-6 col-lg-offset-3">
|
|
|
|
<div className="add-top jumbotron jumbo-auth text-center">
|
|
|
|
<div>
|
|
|
|
<img src="/ensl_logo.png" className="jumbo-img" alt="ENSL Logo" />
|
|
|
|
</div>
|
|
|
|
<br />
|
|
|
|
<h3>Authenticating your ENSL account</h3>
|
|
|
|
<br />
|
|
|
|
<div>
|
|
|
|
<img src="/spinner.svg" className="spinner" alt="Loading" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const App = React.createClass({
|
2016-01-26 10:44:34 +00:00
|
|
|
propTypes: {
|
|
|
|
socket: React.PropTypes.object.isRequired
|
|
|
|
},
|
|
|
|
|
2015-10-29 19:50:38 +00:00
|
|
|
getInitialState() {
|
|
|
|
let updateTitle = true;
|
2016-01-02 21:32:26 +00:00
|
|
|
let showEventsPanel = true;
|
2015-10-29 19:50:38 +00:00
|
|
|
|
2016-01-02 21:32:26 +00:00
|
|
|
if (storageAvailable('localStorage')) {
|
|
|
|
if (localStorage.getItem("updateTitle") !== null) {
|
|
|
|
updateTitle = JSON.parse(localStorage.getItem("updateTitle"));
|
|
|
|
}
|
|
|
|
if (localStorage.getItem("showEventsPanel") !== null) {
|
|
|
|
showEventsPanel = JSON.parse(localStorage.getItem("showEventsPanel"));
|
|
|
|
}
|
2015-10-29 19:50:38 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 10:22:23 +00:00
|
|
|
return {
|
|
|
|
gather: {
|
|
|
|
gatherers: []
|
|
|
|
},
|
|
|
|
users: [],
|
2015-10-02 14:53:11 +00:00
|
|
|
messages: [],
|
|
|
|
maps: [],
|
2015-11-15 16:26:32 +00:00
|
|
|
user: null,
|
2015-10-02 14:53:11 +00:00
|
|
|
servers: [],
|
|
|
|
archive: [],
|
2015-11-15 16:26:32 +00:00
|
|
|
socket: null,
|
2016-01-26 10:44:34 +00:00
|
|
|
events: [],
|
|
|
|
updateTitle: updateTitle,
|
|
|
|
showEventsPanel: showEventsPanel,
|
|
|
|
soundController: new SoundController()
|
2015-10-29 19:50:38 +00:00
|
|
|
};
|
2015-10-01 10:22:23 +00:00
|
|
|
},
|
|
|
|
|
2015-10-03 22:39:51 +00:00
|
|
|
updateTitle() {
|
2016-01-26 10:44:34 +00:00
|
|
|
let gather = this.state.gather;
|
2015-10-29 19:50:38 +00:00
|
|
|
if (gather && this.state.updateTitle) {
|
2015-10-03 22:39:51 +00:00
|
|
|
document.title = `NSL Gathers (${gather.gatherers.length}/12)`;
|
2015-10-29 19:50:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
document.title = "NSL Gathers";
|
|
|
|
},
|
|
|
|
|
2016-01-02 21:32:26 +00:00
|
|
|
toggleEventsPanel(event) {
|
|
|
|
let newState = event.target.checked;
|
|
|
|
this.setState({ showEventsPanel: newState });
|
|
|
|
if (storageAvailable('localStorage')) {
|
|
|
|
localStorage.setItem("showEventsPanel", newState)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-10-29 19:50:38 +00:00
|
|
|
toggleUpdateTitle(event) {
|
|
|
|
let newState = event.target.checked;
|
2016-01-02 21:32:26 +00:00
|
|
|
this.setState({ updateTitle: newState });
|
2015-10-29 19:50:38 +00:00
|
|
|
if (storageAvailable('localStorage')) {
|
|
|
|
localStorage.setItem("updateTitle", newState)
|
2015-10-03 22:39:51 +00:00
|
|
|
}
|
2015-10-29 19:50:38 +00:00
|
|
|
this.updateTitle();
|
2015-10-03 22:39:51 +00:00
|
|
|
},
|
|
|
|
|
2015-10-02 17:52:04 +00:00
|
|
|
thisGatherer() {
|
2016-01-26 10:44:34 +00:00
|
|
|
let gather = this.state.gather;
|
|
|
|
let user = this.state.user;
|
2015-10-02 17:52:04 +00:00
|
|
|
if (gather && user && gather.gatherers.length) {
|
|
|
|
return gather.gatherers
|
|
|
|
.filter(gatherer => gatherer.id === user.id)
|
|
|
|
.pop() || null;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2015-10-01 10:22:23 +00:00
|
|
|
componentDidMount() {
|
|
|
|
let self = this;
|
2015-10-02 14:53:11 +00:00
|
|
|
let socket = this.props.socket;
|
2016-01-22 10:12:23 +00:00
|
|
|
let soundController = this.state.soundController;
|
2015-10-02 17:52:04 +00:00
|
|
|
|
2015-10-29 19:50:38 +00:00
|
|
|
this.updateTitle();
|
|
|
|
|
2015-12-24 20:16:46 +00:00
|
|
|
socket.on('stateChange', data => {
|
|
|
|
let state = data.state;
|
|
|
|
|
2015-12-24 20:07:58 +00:00
|
|
|
if (state.from === 'gathering'
|
|
|
|
&& state.to === 'election'
|
2015-10-02 17:52:04 +00:00
|
|
|
&& this.thisGatherer()) {
|
|
|
|
soundController.playGatherMusic();
|
|
|
|
}
|
2015-12-24 20:07:58 +00:00
|
|
|
|
|
|
|
if (state.from === 'election'
|
2015-12-29 10:26:19 +00:00
|
|
|
&& state.to === 'gathering') {
|
2015-12-24 20:07:58 +00:00
|
|
|
soundController.stop();
|
|
|
|
}
|
2015-10-02 17:52:04 +00:00
|
|
|
});
|
2015-10-01 10:22:23 +00:00
|
|
|
|
2015-12-29 16:26:11 +00:00
|
|
|
socket.on('event:append', data => {
|
|
|
|
let events = self.state.events;
|
|
|
|
events.unshift(data);
|
|
|
|
self.setState({
|
|
|
|
events: events.slice(0, 20)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-10-01 10:22:23 +00:00
|
|
|
socket.on('users:update',
|
2016-01-26 10:44:34 +00:00
|
|
|
data => self.setState({
|
2015-10-02 14:53:11 +00:00
|
|
|
users: data.users,
|
|
|
|
user: data.currentUser
|
|
|
|
})
|
|
|
|
);
|
2015-10-01 10:22:23 +00:00
|
|
|
|
|
|
|
socket.on("message:append", data => {
|
2016-01-26 10:44:34 +00:00
|
|
|
self.setState({
|
|
|
|
messages: self.state.messages.concat(data.messages)
|
2015-10-01 10:22:23 +00:00
|
|
|
.sort((a, b) => {
|
|
|
|
return new Date(a.createdAt) - new Date(b.createdAt);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("message:refresh", data => {
|
2016-01-26 10:44:34 +00:00
|
|
|
self.setState({
|
2015-10-02 14:53:11 +00:00
|
|
|
messages: data.messages
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("gather:refresh", (data) => {
|
2016-01-26 10:44:34 +00:00
|
|
|
self.setState({
|
2015-10-02 14:53:11 +00:00
|
|
|
gather: data.gather,
|
|
|
|
maps: data.maps,
|
|
|
|
servers: data.servers,
|
|
|
|
previousGather: data.previousGather
|
|
|
|
});
|
2015-10-03 22:39:51 +00:00
|
|
|
this.updateTitle();
|
2015-10-02 14:53:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("gather:archive:refresh", data => {
|
2016-01-26 10:44:34 +00:00
|
|
|
self.setState({
|
2015-10-02 14:53:11 +00:00
|
|
|
archive: data.archive,
|
|
|
|
maps: data.maps,
|
|
|
|
servers: data.servers
|
2015-10-01 10:22:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.emit("users:refresh");
|
|
|
|
socket.emit("message:refresh");
|
2016-01-22 10:12:23 +00:00
|
|
|
socket.emit("gather:refresh");
|
2015-10-01 10:22:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2016-01-26 10:44:34 +00:00
|
|
|
const socket = this.props.socket;
|
|
|
|
|
2016-01-02 21:32:26 +00:00
|
|
|
let eventsPanel;
|
|
|
|
if (this.state.showEventsPanel) {
|
|
|
|
eventsPanel = <Events events={this.state.events} />;
|
|
|
|
}
|
|
|
|
|
2016-01-26 10:44:34 +00:00
|
|
|
let profileModal, chatroom, currentUser;
|
|
|
|
if (this.state.user) {
|
|
|
|
profileModal = <ProfileModal user={this.state.user} />;
|
|
|
|
chatroom = <Chatroom messages={this.state.messages}
|
|
|
|
user={this.state.user} socket={socket} />;
|
|
|
|
currentUser = (
|
|
|
|
<ul className="nav navbar-top-links navbar-right" id="currentuser">
|
|
|
|
<CurrentUser user={this.state.user} />
|
2015-10-01 10:22:23 +00:00
|
|
|
</ul>
|
2016-01-26 10:44:34 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="wrapper">
|
|
|
|
<header className="main-header">
|
|
|
|
<a href="/" className="logo">
|
|
|
|
<span className="logo-mini">NSL Gathers</span>
|
|
|
|
<span className="logo-lg">NSL Gathers</span>
|
|
|
|
</a>
|
|
|
|
<nav className="navbar navbar-static-top" role="navigation">
|
|
|
|
<a href="#" className="sidebar-toggle" data-toggle="offcanvas" role="button">
|
|
|
|
<span className="sr-only">Toggle navigation</span>
|
|
|
|
</a>
|
|
|
|
<div className="navbar-custom-menu">
|
|
|
|
<ul className="nav navbar-nav">
|
|
|
|
<li className="dropdown messages-menu">
|
|
|
|
<a href="#" className="dropdown-toggle" data-toggle="dropdown">
|
|
|
|
<i className="fa fa-envelope-o"></i>
|
|
|
|
<span className="label label-success">4</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
</header>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div id="wrapper">
|
|
|
|
<nav className="navbar navbar-default navbar-static-top"
|
|
|
|
role="navigation"
|
|
|
|
style={{marginBottom: "0"}}>
|
|
|
|
<div className="navbar-header">
|
|
|
|
<a className="navbar-brand" href="/">NSL Gathers <small><i>Alpha</i></small></a>
|
|
|
|
</div>
|
|
|
|
{currentUser}
|
|
|
|
<ul className="nav navbar-top-links navbar-right" id="soundcontroller">
|
|
|
|
<SoundPanel soundController={this.state.soundController} />
|
|
|
|
</ul>
|
|
|
|
<TeamSpeakButton />
|
|
|
|
<ul className="nav navbar-top-links navbar-right">
|
|
|
|
<li className="dropdown">
|
|
|
|
<a className="dropdown-toggle" data-toggle="dropdown" href="#">
|
|
|
|
Info <i className="fa fa-caret-down"></i>
|
|
|
|
</a>
|
|
|
|
<ul className="dropdown-menu">
|
|
|
|
<li>
|
|
|
|
<a href="https://github.com/cblanc/sws_gathers" target="_blank">
|
|
|
|
<i className="fa fa-github"> </i> Github
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a href="http://steamcommunity.com/id/nslgathers" target="_blank">
|
|
|
|
<i className="fa fa-external-link"> </i> Steam Bot
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a href="http://www.ensl.org/articles/464" target="_blank">
|
|
|
|
<i className="fa fa-external-link"> </i> Gather Rules
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a href="/messages" target="_blank">
|
|
|
|
<i className="fa fa-external-link"> </i> Message Archive
|
|
|
|
</a>
|
|
|
|
</li>
|
2015-10-01 10:22:23 +00:00
|
|
|
</ul>
|
2016-01-26 10:44:34 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
<AdminPanel socket={socket} />
|
|
|
|
<SettingsPanel
|
|
|
|
toggleEventsPanel={this.toggleEventsPanel}
|
|
|
|
showEventsPanel={this.state.showEventsPanel}
|
|
|
|
toggleUpdateTitle={this.toggleUpdateTitle}
|
|
|
|
updateTitle={this.state.updateTitle} />
|
|
|
|
<TeamSpeakModal />
|
|
|
|
{profileModal}
|
|
|
|
<div style={{minHeight: "750px"}}>
|
|
|
|
<div className="container-fluid">
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-2 hidden-xs">
|
|
|
|
<ul className="nav" id="side-menu">
|
|
|
|
<UserMenu users={this.state.users} user={this.state.user}
|
|
|
|
socket={socket} />
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-4" id="chatroom">
|
|
|
|
{chatroom}
|
|
|
|
</div>
|
|
|
|
<div className="col-md-6" id="gathers">
|
|
|
|
<Gather
|
|
|
|
socket={socket}
|
|
|
|
maps={this.state.maps}
|
|
|
|
user={this.state.user}
|
|
|
|
gather={this.state.gather}
|
|
|
|
servers={this.state.servers}
|
|
|
|
thisGatherer={this.thisGatherer()}
|
|
|
|
previousGather={this.state.previousGather}
|
|
|
|
soundController={this.state.soundController} />
|
|
|
|
{eventsPanel}
|
|
|
|
<hr />
|
|
|
|
<ArchivedGathers archive={this.state.archive}
|
|
|
|
maps={this.state.maps}
|
|
|
|
servers={this.state.servers} />
|
|
|
|
</div>
|
2015-10-01 10:22:23 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-01-26 10:44:34 +00:00
|
|
|
);
|
2015-10-01 10:22:23 +00:00
|
|
|
}
|
2016-01-22 10:12:23 +00:00
|
|
|
});
|
|
|
|
|
2016-01-26 10:44:34 +00:00
|
|
|
module.exports = SplashScreen;
|