diff --git a/diamondsCluster/diamondsCluster.js b/diamondsCluster/diamondsCluster.js index e6468f0..e8475db 100755 --- a/diamondsCluster/diamondsCluster.js +++ b/diamondsCluster/diamondsCluster.js @@ -44,7 +44,7 @@ app.use(express.static(__dirname + '/public')); function start() { var httpServer = http.createServer(app); // server is the node server (web app via express) - var server = httpServer.listen(serverPort, function(err) { + var server = httpServer.listen(serverPort, function (err) { if (err) return cb(err); // this code can launch the server on port 80 and switch the user id away from sudo @@ -59,11 +59,11 @@ function start() { redisClient = redis.createClient(redisPort, redisIP); - redisClient.on('connect', function() { + redisClient.on('connect', function () { console.log('Redis client connected'); }); - redisClient.on("error", function(err) { + redisClient.on("error", function (err) { console.log("Error " + err); }); } @@ -77,7 +77,7 @@ if (cluster.isMaster) { console.log('worker %s started.', worker.process.pid); } - cluster.on('death', function(worker) { + cluster.on('death', function (worker) { console.log('worker %s died. restart...', worker.process.pid); }); @@ -147,10 +147,10 @@ if (cluster.isMaster) { // Respond to web sockets with socket.on - io.sockets.on('connection', function(socket) { + io.sockets.on('connection', function (socket) { var ioClientCounter = 0; // Can I move this outside into global vars? - socket.on('addme', function(data) { + socket.on('addme', function (data) { let username = data.username; var userColor = data.color; var userNote = data.note || 60; @@ -194,7 +194,7 @@ if (cluster.isMaster) { socket.corpus = defaultCorpus; if (data.corpus) { socket.corpus = data.corpus - // .emit to send message back to caller. + // .emit to send message back to caller. socket.emit('registerComplete', { 'greeting': `SERVER: You have connected. Hello: ${username} ID: ${socket.id} Color: ${socket.userColor}`, 'username': username, @@ -227,7 +227,7 @@ if (cluster.isMaster) { //socket.broadcast.emit('chat', 'SERVER: A new user has connected: ' + username + " " + socket.id + 'Color: ' + socket.userColor); // Redis server to get the shared currentSection - redisClient.get('currentSection', function(err, reply) { + redisClient.get('currentSection', function (err, reply) { currentSection = reply; if (currentSection) { var title = getSection(currentSection); @@ -239,7 +239,7 @@ if (cluster.isMaster) { // If it is a normal user, alert the audioController if (username == "a_user") { // oscClient.send('/causeway/registerUser', socket.id, socket.userColor, socket.userLocation[0],socket.userLocation[1], socket.userNote); - redisClient.get('audioControllerID-' + socket.sessionName, function(err, reply) { + redisClient.get('audioControllerID-' + socket.sessionName, function (err, reply) { let audioControllerID = reply; if (audioControllerID) { io.to(audioControllerID).emit('/diamonds/registerUser', { id: socket.id, color: socket.userColor, locationX: socket.userLocation[0], locationY: socket.userLocation[1] }, 1); @@ -249,7 +249,7 @@ if (cluster.isMaster) { }); - socket.on('disconnect', function() { + socket.on('disconnect', function () { // ioClients.remove(socket.id); // FIXME: Remove client if they leave io.sockets.emit('chat', 'SERVER: ' + socket.id + ' has left the building'); }); @@ -258,7 +258,7 @@ if (cluster.isMaster) { // **************************************************** // **** The phrase generation system using set scans in redis to rita markov loadText - socket.on('item', function(data) { + socket.on('item', function (data) { // --- Someone selected 'item', search for texts that use the word, then markov them. --- // // sscan for texts, recursively filling up a matching text array. If it doesn't find 10 // texts are randomly chosen and passed to the callback function. These are passed to @@ -269,7 +269,7 @@ if (cluster.isMaster) { var matchingTexts = []; var cursor = '0'; - var diamondsCorpus = sscan(data, function(returnedTexts) { + var diamondsCorpus = sscan(data, function (returnedTexts) { // console.log("*** Texts Returned ***\n", returnedTexts); let generatedText; // Now Markov the texts @@ -284,10 +284,12 @@ if (cluster.isMaster) { console.log("*** Generated Text ***\n", generatedText); // Save generated sentances into redis. if (generatedText) { + console.log("*** TEST ***\n", generatedText); + redisClient.lpush("markov", generatedText); // Send generated sentances to EVERYONE FIXME: Should this only be a few people? socket.emit('itemback', { phrase: generatedText, color: socket.userColor, sessionName: socket.sessionName }); - redisClient.get('controllerID-' + socket.sessionName, function(err, reply) { + redisClient.get('controllerID-' + socket.sessionName, function (err, reply) { let controllerID = reply; if (controllerID) { io.to(controllerID).emit('itemback', { phrase: generatedText, color: socket.userColor, sessionName: socket.sessionName }); @@ -301,7 +303,7 @@ if (cluster.isMaster) { // } // }); - redisClient.get('installationID-' + socket.sessionName, function(err, reply) { + redisClient.get('installationID-' + socket.sessionName, function (err, reply) { let installationID = reply; if (installationID) { io.to(installationID).emit('itemback', { phrase: generatedText, color: socket.userColor, sessionName: socket.sessionName }); @@ -318,7 +320,7 @@ if (cluster.isMaster) { cursor, 'MATCH', '*' + data.text + '*', 'COUNT', '10', // Find 10 occurances of the word that was tapped in the CORPUS. - function(err, res) { + function (err, res) { if (err) throw err; // Update the cursor position for the next scan @@ -362,7 +364,7 @@ if (cluster.isMaster) { console.log('--- Iteration complete, matches below ---'); if (matchingTexts.length < 10) { // Not enough, add random texts. - let texts = redisClient.srandmember(socket.corpus, (10 - matchingTexts.length), function(err, reply) { + let texts = redisClient.srandmember(socket.corpus, (10 - matchingTexts.length), function (err, reply) { if (err) throw err; // console.log("Texts to add: ", JSON.stringify(reply[1])); matchingTexts.push(reply[1]); @@ -412,7 +414,7 @@ if (cluster.isMaster) { // ******************************************************* // ******************************************************* - socket.on('registerSession', function(data) { + socket.on('registerSession', function (data) { let sessionName = data.sessionName; redisClient.sadd('sessionList', sessionName); data.corpus = data.corpus || defaultCorpus; @@ -430,15 +432,15 @@ if (cluster.isMaster) { // }) }); - socket.on('joinSession', function(data) { + socket.on('joinSession', function (data) { let sessionName = data.sessionName; console.log(`User ${data.username} is Joining: ${sessionName}`); redisClient.sismember('sessionList', sessionName, (err, reply) => { - if (!reply) { - redisClient.sadd('sessionList', sessionName); - } - }) - // Do I save this for use in the audience page to come? + if (!reply) { + redisClient.sadd('sessionList', sessionName); + } + }) + // Do I save this for use in the audience page to come? socket.sessionName = sessionName; redisClient.hget(sessionName + "-session", 'corpus', (err, reply) => { // do something with the reply @@ -464,7 +466,7 @@ if (cluster.isMaster) { }); function updateSessions() { - redisClient.smembers('sessionList', function(err, reply) { + redisClient.smembers('sessionList', function (err, reply) { let sessionList = reply; console.log(`Session List: ${sessionList}`); io.sockets.emit('sessions', { @@ -473,7 +475,7 @@ if (cluster.isMaster) { }); }; - socket.on('getSessions', function(data) { + socket.on('getSessions', function (data) { redisClient.smembers('sessionList', (err, reply) => { let sessionList = reply; console.log(`Sending session List: ${sessionList}`); @@ -485,17 +487,17 @@ if (cluster.isMaster) { - socket.on('start', function(data) { + socket.on('start', function (data) { console.log("start: ", data); socket.broadcast.emit('start', data); }); - socket.on('excite', function(data) { + socket.on('excite', function (data) { console.log("excite: ", data); socket.broadcast.emit('excite', data); }); - socket.on('echo', function(data) { + socket.on('echo', function (data) { console.log("echo: ", data.phrase); // No SessionName? add it in if (socket.sessionName && !data.sessionName) { @@ -504,17 +506,17 @@ if (cluster.isMaster) { socket.broadcast.emit('echo', data); }); - socket.on('kill', function(data) { + socket.on('kill', function (data) { console.log("kill: ", data); socket.broadcast.emit('kill', data); }); - socket.on('volta', function(data) { + socket.on('volta', function (data) { console.log("volta: ", data); socket.broadcast.emit('volta', data); }); - socket.on('end', function(data) { + socket.on('end', function (data) { console.log("end: ", data); socket.broadcast.emit('end', data); }); @@ -531,21 +533,21 @@ if (cluster.isMaster) { - socket.on('interactionTrail', function(data) { + socket.on('interactionTrail', function (data) { console.log("Received interactionTrail: " + data); // send somewhere? perhaps theatre? redisClient.lpush("interactionTrail", data); // Store for some other time... }) - socket.on('audience/enable', function(data) { + socket.on('audience/enable', function (data) { console.log("audience/enable", data); io.sockets.emit('audienceEnable', data); }); - socket.on('nextChord', function(data) { - redisClient.get('audioControllerID-' + socket.sessionName, function(err, reply) { + socket.on('nextChord', function (data) { + redisClient.get('audioControllerID-' + socket.sessionName, function (err, reply) { let audioControllerID = reply; if (audioControllerID) { io.to(audioControllerID).emit('/diamonds/nextChord', { id: socket.id }, 1); @@ -554,18 +556,18 @@ if (cluster.isMaster) { socket.broadcast.emit('triggerNextChord', data); }); - socket.on('playChord', function(data) { + socket.on('playChord', function (data) { console.log("playChord", data); io.sockets.emit('playChord', data); }); - socket.on('sustainChord', function(data) { + socket.on('sustainChord', function (data) { console.log("sustainChord", data); io.sockets.emit('sustainChord', data); }); - socket.on('triggerBeginning', function(data) { - redisClient.get('audioControllerID-' + socket.sessionName, function(err, reply) { + socket.on('triggerBeginning', function (data) { + redisClient.get('audioControllerID-' + socket.sessionName, function (err, reply) { let audioControllerID = reply; if (audioControllerID) { io.to(audioControllerID).emit('/diamonds/triggerBeginning', { id: socket.id }, 1); @@ -574,8 +576,8 @@ if (cluster.isMaster) { socket.broadcast.emit('triggerBeginning', data); }); - socket.on('triggerUtopalypse', function(data) { - redisClient.get('audioControllerID-' + socket.sessionName, function(err, reply) { + socket.on('triggerUtopalypse', function (data) { + redisClient.get('audioControllerID-' + socket.sessionName, function (err, reply) { let audioControllerID = reply; if (audioControllerID) { io.to(audioControllerID).emit('/diamonds/triggerUtopalypse', { id: socket.id }, 1); @@ -584,8 +586,8 @@ if (cluster.isMaster) { socket.broadcast.emit('triggerUtopalypse', data); }); - socket.on('triggerDiamonds', function(data) { - redisClient.get('audioControllerID-' + socket.sessionName, function(err, reply) { + socket.on('triggerDiamonds', function (data) { + redisClient.get('audioControllerID-' + socket.sessionName, function (err, reply) { let audioControllerID = reply; if (audioControllerID) { io.to(audioControllerID).emit('/diamonds/triggerDiamonds', { id: socket.id }, 1); @@ -594,8 +596,8 @@ if (cluster.isMaster) { socket.broadcast.emit('triggerDiamonds', data); }); - socket.on('triggerEnding', function(data) { - redisClient.get('audioControllerID-' + socket.sessionName, function(err, reply) { + socket.on('triggerEnding', function (data) { + redisClient.get('audioControllerID-' + socket.sessionName, function (err, reply) { let audioControllerID = reply; if (audioControllerID) { io.to(audioControllerID).emit('/diamonds/triggerEnding', { id: socket.id }, 1); @@ -605,7 +607,7 @@ if (cluster.isMaster) { }); - socket.on('selectedPhrase', function(data) { + socket.on('selectedPhrase', function (data) { console.log("****** Phrase Selected: ******\n" + data.phrase); redisClient.lpush("generatedPoem", data.phrase); @@ -624,7 +626,7 @@ if (cluster.isMaster) { // } // }); - redisClient.get('installationID-' + socket.sessionName, function(err, reply) { + redisClient.get('installationID-' + socket.sessionName, function (err, reply) { let installationID = reply; if (installationID) { data.sessionName = socket.sessionName; @@ -632,7 +634,7 @@ if (cluster.isMaster) { } }); - redisClient.get('audioControllerID-' + socket.sessionName, function(err, reply) { + redisClient.get('audioControllerID-' + socket.sessionName, function (err, reply) { let audioControllerID = reply; if (audioControllerID) { data.sessionName = socket.sessionName; @@ -643,7 +645,7 @@ if (cluster.isMaster) { - socket.on('section', function(data) { + socket.on('section', function (data) { console.log("Section is now: " + data); currentSection = data; redisClient.set("currentSection", currentSection); @@ -662,16 +664,16 @@ if (cluster.isMaster) { "End" ]; - getSection = function(sect) { + getSection = function (sect) { return sectionTitles[sect]; } // sendSection(currentSection); // Sets everyone's section - sendSection = function(sect) { + sendSection = function (sect) { var title = getSection(sect); io.sockets.emit('setSection', { sect: sect, title: title }); - redisClient.get('audioControllerID-' + socket.sessionName, function(err, reply) { + redisClient.get('audioControllerID-' + socket.sessionName, function (err, reply) { let audioControllerID = reply; if (audioControllerID) { io.to(audioControllerID).emit('/diamonds/currentSection', { section: sect, title: title }, 1); @@ -680,7 +682,7 @@ if (cluster.isMaster) { }; // Section shared from Max to UIs - shareSection = function(sect) { + shareSection = function (sect) { var title = getSection(sect); io.sockets.emit('setSection', sect, title); }; diff --git a/diamondsCluster/public/js/theater.js b/diamondsCluster/public/js/theater.js index 8d87491..93ec213 100644 --- a/diamondsCluster/public/js/theater.js +++ b/diamondsCluster/public/js/theater.js @@ -113,7 +113,11 @@ function draw1() { // } var newDivBar; var w1 = 10; + socket.on('itemback', function (data) { + + console.log("somethingBack", data.sessionName); + if (data.sessionName == user.sessionName) { if (userbars[data.color] > 0) { userbars[data.color] = userbars[data.color] + 1 @@ -189,6 +193,7 @@ socket.on('itemback', function (data) { socket.on('selectedPhrase', function (data) { console.log("New Phrase: " + data.phrase); + document.getElementsByClassName('sw')[0].style.display = "none"; if (data.sessionName == user.sessionName) { document.getElementsByClassName('newgentext')[0].innerHTML = data.phrase; var newgentext = document.getElementsByClassName('newgentext')[0];