const React = require("react");
const Gather = require("javascripts/components/gather").Gather;
const ArchivedGather = require("javascripts/components/gather").ArchivedGather;
const Event = require("javascripts/components/event");
const Message = require("javascripts/components/message");
const Settings = require("javascripts/components/settings");
const Sound = require("javascripts/components/sound");
const User = require("javascripts/components/user");
const SplashScreen = React.createClass({
getInitialState() {
return {
status: "connecting", // connected, authFailed, banned
socket: null
}
},
componentDidMount() {
const socketUrl = window.location.protocol + "//" + window.location.host;
let socket = io(socketUrl)
.on("connect", () => {
console.log("Connected");
// removeAuthWidget();
socket.on("reconnect", () => {
console.log("Reconnected");
this.setState({ status: "connected" });
})
.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;
if (status === "connected") {
return ;
}
let splash;
if (status === "authFailed") {
splash =
} else if (status === "banned") {
splash =
} else {
splash =
}
return (
);
}
});
const AuthFailedSplash = React.createClass({
render() {
return (
You need to be logged in to the ENSL website to access gathers
If you are logged on, try visiting a few pages on ENSL.org so the server can update your cookies
If this error persists please contact an admin to fix it
Go to website
);
}
});
const BannedSplash = React.createClass({
render() {
return (
You're currently barred from joining gathers
Either wait for the ban to expire or talk to an admin to get it lifted
See the ban list
);
}
});
const ConnectingSplash = React.createClass({
render() {
return (
Authenticating your ENSL account
);
}
});
const App = React.createClass({
getInitialState() {
let updateTitle = true;
let showEventsPanel = true;
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"));
}
}
return {
events: [],
updateTitle: updateTitle,
showEventsPanel: showEventsPanel,
soundController: new SoundController()
};
},
getDefaultProps() {
return {
gather: {
gatherers: []
},
users: [],
messages: [],
maps: [],
user: null,
servers: [],
archive: [],
socket: null,
soundController: null
};
},
updateTitle() {
let gather = this.props.gather;
if (gather && this.state.updateTitle) {
document.title = `NSL Gathers (${gather.gatherers.length}/12)`;
return;
}
document.title = "NSL Gathers";
},
toggleEventsPanel(event) {
let newState = event.target.checked;
this.setState({ showEventsPanel: newState });
if (storageAvailable('localStorage')) {
localStorage.setItem("showEventsPanel", newState)
}
},
toggleUpdateTitle(event) {
let newState = event.target.checked;
this.setState({ updateTitle: newState });
if (storageAvailable('localStorage')) {
localStorage.setItem("updateTitle", newState)
}
this.updateTitle();
},
thisGatherer() {
let gather = this.props.gather;
let user = this.props.user;
if (gather && user && gather.gatherers.length) {
return gather.gatherers
.filter(gatherer => gatherer.id === user.id)
.pop() || null;
}
return null;
},
componentDidMount() {
let self = this;
let socket = this.props.socket;
let soundController = this.state.soundController;
this.updateTitle();
socket.on('stateChange', data => {
let state = data.state;
if (state.from === 'gathering'
&& state.to === 'election'
&& this.thisGatherer()) {
soundController.playGatherMusic();
}
if (state.from === 'election'
&& state.to === 'gathering') {
soundController.stop();
}
});
socket.on('event:append', data => {
let events = self.state.events;
events.unshift(data);
self.setState({
events: events.slice(0, 20)
});
});
socket.on('users:update',
data => self.setProps({
users: data.users,
user: data.currentUser
})
);
socket.on("message:append", data => {
self.setProps({
messages: self.props.messages.concat(data.messages)
.sort((a, b) => {
return new Date(a.createdAt) - new Date(b.createdAt);
})
});
});
socket.on("message:refresh", data => {
self.setProps({
messages: data.messages
});
});
socket.on("gather:refresh", (data) => {
self.setProps({
gather: data.gather,
maps: data.maps,
servers: data.servers,
previousGather: data.previousGather
});
this.updateTitle();
});
socket.on("gather:archive:refresh", data => {
self.setProps({
archive: data.archive,
maps: data.maps,
servers: data.servers
});
});
socket.emit("users:refresh");
socket.emit("message:refresh");
socket.emit("gather:refresh");
},
render() {
let eventsPanel;
if (this.state.showEventsPanel) {
eventsPanel = ;
}
return
}
});
module.exports = SplashScreen;