2015-07-28 15:54:29 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var socket;
|
|
|
|
|
2015-07-29 10:46:30 +00:00
|
|
|
function initialiseVisibilityMonitoring (socket) {
|
|
|
|
var hidden, visibilityChange;
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener(visibilityChange, function () {
|
|
|
|
if (document[hidden]) {
|
|
|
|
socket.emit("users:away");
|
|
|
|
} else {
|
|
|
|
socket.emit("users:online");
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2015-07-28 15:54:29 +00:00
|
|
|
function initialiseComponents () {
|
|
|
|
var socketUrl = window.location.protocol + "//" + window.location.host;
|
|
|
|
socket = io(socketUrl)
|
|
|
|
.on("connect", function () {
|
|
|
|
console.log("Connected");
|
|
|
|
})
|
|
|
|
.on("reconnect", function () {
|
|
|
|
console.log("Reconnected");
|
|
|
|
})
|
|
|
|
.on("disconnect", function () {
|
|
|
|
console.log("Disconnected")
|
|
|
|
});
|
|
|
|
|
2015-07-29 10:56:01 +00:00
|
|
|
initialiseVisibilityMonitoring(socket);
|
2015-07-29 10:46:30 +00:00
|
|
|
|
|
|
|
// Render Page
|
2015-07-28 15:54:29 +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-07-29 14:35:58 +00:00
|
|
|
React.render(<AdminPanel />, document.getElementById('admin-menu'));
|
2015-07-29 10:56:01 +00:00
|
|
|
};
|