2015-07-28 15:54:29 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var socket;
|
2015-08-27 16:54:34 +00:00
|
|
|
var soundController;
|
2015-07-28 15:54:29 +00:00
|
|
|
|
2015-08-11 00:37:43 +00:00
|
|
|
var initialiseVisibilityMonitoring = (socket) => {
|
|
|
|
let hidden, visibilityChange;
|
2015-07-29 10:46:30 +00:00
|
|
|
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
|
|
|
|
hidden = "hidden";
|
|
|
|
visibilityChange = "visibilitychange";
|
|
|
|
} else if (typeof document.mozHidden !== "undefined") {
|
|
|
|
hidden = "mozHidden";
|
|
|
|
visibilityChange = "mozvisibilitychange";
|
|
|
|
} else if (typeof document.msHidden !== "undefined") {
|
|
|
|
hidden = "msHidden";
|
|
|
|
visibilityChange = "msvisibilitychange";
|
|
|
|
} else if (typeof document.webkitHidden !== "undefined") {
|
|
|
|
hidden = "webkitHidden";
|
|
|
|
visibilityChange = "webkitvisibilitychange";
|
|
|
|
}
|
|
|
|
|
2015-08-11 00:37:43 +00:00
|
|
|
document.addEventListener(visibilityChange, () => {
|
2015-07-29 10:46:30 +00:00
|
|
|
if (document[hidden]) {
|
|
|
|
socket.emit("users:away");
|
|
|
|
} else {
|
|
|
|
socket.emit("users:online");
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2015-08-18 09:56:35 +00:00
|
|
|
var removeAuthWidget = () => {
|
|
|
|
$("#authenticating").remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
var showAuthenticationNotice = () => {
|
|
|
|
$("#auth-required").show();
|
|
|
|
};
|
|
|
|
|
2015-08-27 12:11:38 +00:00
|
|
|
var showGatherBanNotice = () => {
|
|
|
|
$("#gather-banned").show();
|
|
|
|
};
|
|
|
|
|
2015-08-18 09:56:35 +00:00
|
|
|
var renderPage = (socket) => {
|
|
|
|
initialiseVisibilityMonitoring(socket);
|
2015-08-27 16:54:34 +00:00
|
|
|
soundController = new SoundController();
|
2015-08-18 09:56:35 +00:00
|
|
|
React.render(<UserMenu />, document.getElementById('side-menu'));
|
|
|
|
React.render(<Chatroom />, document.getElementById('chatroom'));
|
|
|
|
React.render(<Gather />, document.getElementById('gathers'));
|
|
|
|
React.render(<CurrentUser />, document.getElementById('currentuser'));
|
2015-08-27 16:54:34 +00:00
|
|
|
React.render(<SoundPanel />, document.getElementById('soundcontroller'));
|
2015-08-18 09:56:35 +00:00
|
|
|
React.render(<AdminPanel />, document.getElementById('admin-menu'));
|
|
|
|
};
|
|
|
|
|
2015-08-11 00:37:43 +00:00
|
|
|
var initialiseComponents = () => {
|
|
|
|
let socketUrl = window.location.protocol + "//" + window.location.host;
|
2015-07-28 15:54:29 +00:00
|
|
|
socket = io(socketUrl)
|
2015-08-11 00:37:43 +00:00
|
|
|
.on("connect", () => {
|
2015-07-28 15:54:29 +00:00
|
|
|
console.log("Connected");
|
2015-08-18 09:56:35 +00:00
|
|
|
removeAuthWidget();
|
|
|
|
renderPage(socket);
|
2015-08-27 11:07:45 +00:00
|
|
|
socket.on("reconnect", () => {
|
|
|
|
socket.emit("message:refresh");
|
|
|
|
socket.emit("gather:refresh");
|
|
|
|
socket.emit("users:refresh");
|
|
|
|
console.log("Reconnected");
|
|
|
|
})
|
|
|
|
.on("disconnect", () => {
|
|
|
|
console.log("Disconnected")
|
|
|
|
});
|
2015-08-18 09:56:35 +00:00
|
|
|
})
|
|
|
|
.on("error", (error, foo) => {
|
|
|
|
console.log(error);
|
|
|
|
if (error === "Authentication Failed") {
|
|
|
|
removeAuthWidget();
|
|
|
|
showAuthenticationNotice();
|
2015-08-27 12:11:38 +00:00
|
|
|
} else if (error === "Gather Banned") {
|
|
|
|
removeAuthWidget();
|
|
|
|
showGatherBanNotice();
|
2015-08-18 09:56:35 +00:00
|
|
|
}
|
2015-08-27 12:13:58 +00:00
|
|
|
});
|
2015-07-29 10:56:01 +00:00
|
|
|
};
|