mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-10 07:11:53 +00:00
Fix gather music
This commit is contained in:
parent
2eb33f3809
commit
e5df60582c
6 changed files with 23 additions and 81 deletions
|
@ -26,21 +26,6 @@ var _ = require("lodash");
|
|||
var winston = require("winston");
|
||||
|
||||
module.exports = function (namespace) {
|
||||
// var refreshGather = _.debounce(function () {
|
||||
// namespace.sockets.forEach(function (socket) {
|
||||
// socket.emit("gather:refresh", {
|
||||
// gather: Gather.current.toJson(),
|
||||
// currentGatherer: Gather.current.getGatherer(socket._user),
|
||||
// maps: Map.list,
|
||||
// servers: Server.list,
|
||||
// previousGather: Gather.previous ? Gather.previous.toJson() : null
|
||||
// });
|
||||
// });
|
||||
// }, 200, {
|
||||
// leading: true,
|
||||
// trailing: true
|
||||
// });
|
||||
|
||||
var refreshGather = _.debounce(function () {
|
||||
namespace.emit("gather:refresh", {
|
||||
gather: Gather.current ? Gather.current.toJson() : null,
|
||||
|
|
|
@ -598,26 +598,6 @@ var MapVoting = React.createClass({
|
|||
})
|
||||
|
||||
var Gather = React.createClass({
|
||||
getDefaultProps() {
|
||||
return {
|
||||
gather: null,
|
||||
user: null
|
||||
}
|
||||
},
|
||||
|
||||
// checkForStateChange: function (data) {
|
||||
// let previousState = this.props.gather.state;
|
||||
// let newState = data.gather.state;
|
||||
// if (newState === previousState) return;
|
||||
|
||||
// // Callbacks for new states
|
||||
// if (newState === "election"
|
||||
// && previousState === "gathering"
|
||||
// && data.currentGatherer) {
|
||||
// soundController.playGatherMusic();
|
||||
// }
|
||||
// },
|
||||
|
||||
thisGatherer() {
|
||||
let gather = this.props.gather;
|
||||
let user = this.props.user;
|
||||
|
|
|
@ -2,31 +2,6 @@
|
|||
|
||||
var socket, soundController;
|
||||
|
||||
var initialiseVisibilityMonitoring = (socket) => {
|
||||
let 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, () => {
|
||||
if (document[hidden]) {
|
||||
socket.emit("users:away");
|
||||
} else {
|
||||
socket.emit("users:online");
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
var removeAuthWidget = () => $("#authenticating").remove();
|
||||
|
||||
var showAuthenticationNotice = () => $("#auth-required").show();
|
||||
|
@ -39,9 +14,7 @@ var initialiseComponents = () => {
|
|||
.on("connect", () => {
|
||||
console.log("Connected");
|
||||
removeAuthWidget();
|
||||
soundController = new SoundController({
|
||||
socket: socket
|
||||
});
|
||||
soundController = new SoundController();
|
||||
React.render(<App socket={socket} soundController={soundController}/>,
|
||||
document.getElementById("body_content"));
|
||||
socket.on("reconnect", () => {
|
||||
|
@ -54,7 +27,7 @@ var initialiseComponents = () => {
|
|||
console.log("Disconnected")
|
||||
});
|
||||
})
|
||||
.on("error", (error, foo) => {
|
||||
.on("error", error => {
|
||||
console.log(error);
|
||||
if (error === "Authentication Failed") {
|
||||
removeAuthWidget();
|
||||
|
|
|
@ -15,9 +15,28 @@ var App = React.createClass({
|
|||
}
|
||||
},
|
||||
|
||||
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.props.soundController;
|
||||
|
||||
socket.on('notification', data => {
|
||||
if (data && data.sound === 'gather_starting'
|
||||
&& this.thisGatherer()) {
|
||||
soundController.playGatherMusic();
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('users:update',
|
||||
data => self.setProps({
|
||||
|
@ -119,6 +138,7 @@ var App = React.createClass({
|
|||
<div className="col-md-6" id="gathers">
|
||||
<Gather
|
||||
gather={this.props.gather}
|
||||
thisGatherer={this.thisGatherer()}
|
||||
user={this.props.user}
|
||||
maps={this.props.maps}
|
||||
servers={this.props.servers}
|
||||
|
|
|
@ -55,14 +55,6 @@ module.exports = namespace => {
|
|||
|
||||
socket.on('users:refresh', refreshUsers.bind(null, socket));
|
||||
|
||||
socket.on('users:online', () => {
|
||||
socket._user.online = true;
|
||||
});
|
||||
|
||||
socket.on('users:away', () => {
|
||||
socket._user.online = false;
|
||||
});
|
||||
|
||||
socket.on('users:update:profile', data => {
|
||||
if (socket._user.id !== data.id) return;
|
||||
socket._user.updateProfile(data.profile, function (error) {
|
||||
|
|
|
@ -37,7 +37,7 @@ var rankVotes = function (votes, candidates) {
|
|||
};
|
||||
|
||||
class SoundController {
|
||||
constructor (options) {
|
||||
constructor () {
|
||||
if (Howl === undefined) {
|
||||
throw new Error("Howl.js required to created sound controller");
|
||||
}
|
||||
|
@ -48,14 +48,6 @@ class SoundController {
|
|||
this.gather.music.play();
|
||||
}, this.MINIMUM_PLAY_INTERVAL);
|
||||
|
||||
if (options && options.socket) {
|
||||
socket.on("notification", data => {
|
||||
if (data && data.sound === "gather_starting") {
|
||||
this.playGatherMusic();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.isMuted = Howler._muted;
|
||||
|
||||
this.volume = Howler._volume;
|
||||
|
|
Loading…
Reference in a new issue