diff --git a/.gitignore b/.gitignore index 5148e52..b573f92 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,8 @@ jspm_packages # Optional REPL history .node_repl_history + +# Optional for people who uses JetBrains products +*.idea + +dump.rdb diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..81e952f --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: node server diff --git a/README.md b/README.md index c2ec850..4d5adc3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,80 @@ -# github-audio +GitHub Audio +============ + Listen to music generated by events happening across GitHub + +_Imitation is the sincerest form of flattery._ - __Oscar Wilde__ + +But seriously, [listen-to-wikipedia](https://github.com/hatnote/listen-to-wikipedia) by [@slaporte](https://github.com/slaporte) and [@mahmoud](https://github.com/mahmoud) is the hotness. + +Use [`ULTIMATE_DREAM_KILLER`](https://github.com/debugger22/github-audio/commit/ed47067f5e56ab70d65fa31f72bf2dbc513f8f56) to filter all events except closed PRs. + + +Media Attention +----- +* [The Next Web](http://thenextweb.com/apps/2016/10/03/this-site-tracks-events-across-github-to-generate-calming-work-music/) +* [Product Hunt](https://www.producthunt.com/tech/github-audio) + + +# Installing dependencies + +This application requires: +* node +* npm +* redis + +Dependency Installation on OSX +------------------- + +```bash +$ brew install nodejs +$ brew install npm +$ brew install redis +``` + +Dependency Installation on Linux +--------------------- + +```bash +$ sudo apt-get update +$ sudo apt-get install nodejs +$ sudo apt-get install npm +$ sudo apt-get install redis-server +``` + +# Running the Application +Install node packages +--------------------- + +Navigate to the project directory and run + +```bash +$ npm install +``` + +Environment variables +--------------------- + +``` +$ export GITHUB_OAUTH_KEY= +``` + +Note: Without the GitHub oauth key the number of requests is throttled at 60 per hour. It can be increased to 5000 per hour by using an oauth key. + +Run Redis and Server +---------- + +If you are running locally then run local redis server + +```bash +$ redis-server +``` + +On heroku, you can set up `Heroku Redis` add-on and it sets `REDIS_URL` environment variable. + +In a separate window: +```bash +$ node server +``` + +Note: For production run `export NODE_ENV="production"` before starting the server. diff --git a/app/index.html b/app/index.html new file mode 100644 index 0000000..6ddb343 --- /dev/null +++ b/app/index.html @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Project Audio for GitHub + + + + + + + + + + + + + + + + +
+ + +
+

+ Project Audio for GitHub  + offline +

+
+   + events remaining in queue  +
+
+
+ +
+
+

people listening

+
+
+
+
+ Enter your organization's or repository's names to filter events 

+ You can also download it for macOS and Linux. +
+
+

About

+
+

This website tracks events happening across GitHub and converts them to music notes based on certain parameters.


+

+ There are three types of sounds(bell, string pluck and string swell) based on four types of events(PushEvent, PullRequestEvent, IssuesEvent and IssueCommentEvent). + Bells represent PushEvents, string plucks represent IssuesEvents and IssueCommentEvents whereas string swells represent PullRequestEvents. +

+
+
+ +
+ + + +
+ + + + + + diff --git a/app/public/bin/GitHub-Audio-v1.0-linux-x64.zip b/app/public/bin/GitHub-Audio-v1.0-linux-x64.zip new file mode 100644 index 0000000..ef93e51 Binary files /dev/null and b/app/public/bin/GitHub-Audio-v1.0-linux-x64.zip differ diff --git a/app/public/bin/GitHub-Audio-v1.0-macOS-x64.zip b/app/public/bin/GitHub-Audio-v1.0-macOS-x64.zip new file mode 100644 index 0000000..c0a9a9a Binary files /dev/null and b/app/public/bin/GitHub-Audio-v1.0-macOS-x64.zip differ diff --git a/app/public/css/main.css b/app/public/css/main.css new file mode 100644 index 0000000..f111e48 --- /dev/null +++ b/app/public/css/main.css @@ -0,0 +1,254 @@ +@import 'https://fonts.googleapis.com/css?family=Source+Sans+Pro:400|Josefin+Sans'; + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; +} + +a{ + text-decoration: none; + color: #0091EA; +} + +html,body{ + background-color: #0288D1; + font-family: 'Source Sans Pro', sans-serif; + font-weight: 400; + font-size: 16px; + overflow-x: hidden; + visibility: hidden; +} + +header{ + position: relative;; + width: 100%; + height: 35px; + color: #fff; + font-family: 'Source Sans Pro', sans-serif; + padding-left: 20px; + padding-top: 20px; + padding-bottom: 20px; +} + +.header-text{ + float: left; + font-size: 1.6em; + line-height: 1em; +} + +.offline-text{ + font-size: 0.4em; + visibility: hidden; +} + +.events-remaining{ + float:right; + margin-right: 5%; + margin-top: 30px; +} + +.events-remaining-text, .events-remaining-value{ + font-size: 0.8em; + visibility: hidden; +} + +#volumeSlider{ + cursor:pointer; + position: absolute; + top: 30px; + right: 40px; + width: 100px; + opacity: 0.3; + border-radius: 5px; +} + +#volumeSlider:hover{ + cursor:pointer; + opacity: 0.9; +} + +#area{ + width: 100%; + position: relative; + /*height: calc(100vh - 70px);*/ +} + +circle { + fill-opacity: 0.8; +} + +.label { + font: 1.0em 'Source Sans Pro', sans-serif; + text-shadow:1px 1px 0 rgb(28, 39, 51), + -1px -1px 0 rgb(28, 39, 51), + 1px -1px 0 rgb(28, 39, 51), + -1px 1px 0 rgb(28, 39, 51), + 0px 1px 0 rgb(28, 39, 51), + 1px 0px 0 rgb(28, 39, 51), + 0px -1px 0 rgb(28, 39, 51), + -1px 0px 0 rgb(28, 39, 51); +} + +.online-users-div{ + text-align: center; + position: absolute; + bottom: 60px; + width: 100%; + margin: 0 auto; + font-size: 0.9em; + z-index: 1; + opacity: 0.5; + visibility: hidden; +} + +.online-users-text{ + font-family: 'Source Sans Pro', sans-serif; + font-size: 1em; + color: #E0E0E0; +} + +#config-area{ + width: 100%; + background: #FFFFFF; + min-height: 300px; + padding: 40px; + color: #555555; + font-family: 'Josefin Sans', sans-serif; + font-weight: 300; +} + +#org-repo-filter-div{ + width: 50%; + margin: 0 auto; + margin-bottom: 0px; +} + +#org-repo-filter-name{ + width: 20%; + color: gray; + padding: 5px; + padding-left: 10px; + border: none; + background: #F1F1F1; + font-family: 'Josefin Sans', sans-serif; + font-size: 1em; +} + +.site-description{ + font-size: 1em; + line-height: 1.6em; + width: 50%; + margin: 0 auto; + margin-top: 50px; +} + +footer{ + width: 100%; + height: 200px; + padding: 20px; + background-color: #242729; + color: #9FA6AD; + margin-top: -5px; + position: relative; + font-size: 0.9em; +} + +.footer-left-text-block{ + float:left; + line-height:1.3em; +} + +.footer-right-text-block{ + float:right; + margin-right:2%; + text-align:right; + line-height:1.3em; +} + +.social-buttons{ + position: absolute; + bottom:20px; + right:60px; + z-index: 2; +} + + +@media only screen and (max-device-width: 480px) { + + #config-area{ + padding: 0px; + padding-top: 50px; + min-height: 600px; + } + + .site-description{ + font-size: 1em; + line-height: 1.6em; + width: 50%; + margin: 0 auto; + } + + .footer-left-text-block{ + width: 100%; + margin: 0 auto; + line-height:1.3em; + } + + .footer-right-text-block{ + width: 100%; + margin-left: 0 auto; + line-height:1.3em; + float: left; + text-align: left; + margin-top: 20px; + } + + .online-users-div{ + margin-left: 20px; + text-align: left; + } + + .social-buttons{ + + } + +} diff --git a/app/public/images/electric-guitar.png b/app/public/images/electric-guitar.png new file mode 100644 index 0000000..ce83a12 Binary files /dev/null and b/app/public/images/electric-guitar.png differ diff --git a/app/public/images/favicon.png b/app/public/images/favicon.png new file mode 100644 index 0000000..50485b9 Binary files /dev/null and b/app/public/images/favicon.png differ diff --git a/app/public/images/speaker-muted.svg b/app/public/images/speaker-muted.svg new file mode 100644 index 0000000..de8c56b --- /dev/null +++ b/app/public/images/speaker-muted.svg @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/public/images/speaker.svg b/app/public/images/speaker.svg new file mode 100644 index 0000000..d5d5001 --- /dev/null +++ b/app/public/images/speaker.svg @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/public/js/main.js b/app/public/js/main.js new file mode 100644 index 0000000..a9d963b --- /dev/null +++ b/app/public/js/main.js @@ -0,0 +1,386 @@ +var eventQueue = []; +var svg; +var element; +var drawingArea; +var width; +var height; +var volume = 0.6; +var ULTIMATE_DREAM_KILLER = false; // https://github.com/debugger22/github-audio/pull/19 +var orgRepoFilterNames = []; + +var scale_factor = 6, + note_overlap = 2, + note_timeout = 300, + current_notes = 0, + max_life = 20000; + +var svg_background_color_online = '#0288D1', + svg_background_color_offline = '#E91E63', + svg_text_color = '#FFFFFF', + newuser_box_color = 'rgb(41, 128, 185)', + push_color = 'rgb(155, 89, 182)', + issue_color = 'rgb(46, 204, 113)', + pull_request_color = 'rgb(46, 204, 113)', + comment_color = 'rgb(46, 204, 113)', + edit_color = '#fff', + total_sounds = 51; + + var celesta = [], + clav = [], + swells = [], + all_loaded = false; + + + +var socket = io(); +socket.on('github', function (data) { + $('.online-users-count').html(data.connected_users); + data.data.forEach(function(event){ + if(!isEventInQueue(event)){ + // Filter out events only specified by the user + if(orgRepoFilterNames != []){ + // Don't consider pushes to github.io repos when org filter is on + if(new RegExp(orgRepoFilterNames.join("|")).test(event.repo_name) + && event.repo_name.indexOf('github.io') == -1){ + eventQueue.push(event); + } + }else{ + eventQueue.push(event); + } + } + }); + // Don't let the eventQueue grow more than 1000 + if (eventQueue.length > 1000) eventQueue = eventQueue.slice(0, 1000); +}); + +socket.on('connect', function(){ + if(svg != null){ + $('svg').css('background-color', svg_background_color_online); + $('header').css('background-color', svg_background_color_online); + $('.offline-text').css('visibility', 'hidden'); + $('.events-remaining-text').css('visibility', 'hidden'); + $('.events-remaining-value').css('visibility', 'hidden'); + } +}); + +socket.on('disconnect', function(){ + if(svg != null){ + $('svg').css('background-color', svg_background_color_offline); + $('header').css('background-color', svg_background_color_offline); + $('.offline-text').css('visibility', 'visible'); + $('.events-remaining-text').css('visibility', 'visible'); + $('.events-remaining-value').css('visibility', 'visible'); + + } +}); + +socket.on('error', function(){ + if(svg != null){ + $('svg').css('background-color', svg_background_color_offline); + $('header').css('background-color', svg_background_color_offline); + $('.offline-text').css('visibility', 'visible'); + $('.events-remaining-text').css('visibility', 'visible'); + $('.events-remaining-value').css('visibility', 'visible'); + } +}); + + +/** +* This function checks whether an event is already in the queue +*/ +function isEventInQueue(event){ + for(var i=0; i 9) { + fn = 'c0' + i; + } else { + fn = 'c00' + i; + } + celesta.push(new Howl({ + src : ['https://d1fz9d31zqor6x.cloudfront.net/sounds/celesta/' + fn + '.ogg', + 'https://d1fz9d31zqor6x.cloudfront.net/sounds/celesta/' + fn + '.mp3'], + volume : 0.7, + onload : sound_load(), + buffer: true, + })) + clav.push(new Howl({ + src : ['https://d1fz9d31zqor6x.cloudfront.net/sounds/clav/' + fn + '.ogg', + 'https://d1fz9d31zqor6x.cloudfront.net/sounds/clav/' + fn + '.mp3'], + volume : 0.4, + onload : sound_load(), + buffer: true, + })) + } + + for (var i = 1; i <= 3; i++) { + swells.push(new Howl({ + src : ['https://d1fz9d31zqor6x.cloudfront.net/sounds/swells/swell' + i + '.ogg', + 'https://d1fz9d31zqor6x.cloudfront.net/sounds/swells/swell' + i + '.mp3'], + volume : 1, + onload : sound_load(), + buffer: true, + })); + } + + Howler.volume(volume); + + // Make header and footer visible + $('body').css('visibility', 'visible'); + + $('#org-repo-filter-name').on('input', function() { + orgRepoFilterNames = $('#org-repo-filter-name').val().split(' '); + eventQueue = []; + }); + +}); + + +/** +* Randomly selects a swell sound and plays it +*/ +function playRandomSwell() { + var index = Math.round(Math.random() * (swells.length - 1)); + swells[index].play(); +} + + +/** +* Plays a sound(celesta and clav) based on passed parameters +*/ +function playSound(size, type) { + var max_pitch = 100.0; + var log_used = 1.0715307808111486871978099; + var pitch = 100 - Math.min(max_pitch, Math.log(size + log_used) / Math.log(log_used)); + var index = Math.floor(pitch / 100.0 * Object.keys(celesta).length); + var fuzz = Math.floor(Math.random() * 4) - 2; + index += fuzz; + index = Math.min(Object.keys(celesta).length - 1, index); + index = Math.max(1, index); + if (current_notes < note_overlap) { + current_notes++; + if (type == 'IssuesEvent' || type == 'IssueCommentEvent') { + clav[index].play(); + } else if(type == 'PushEvent') { + celesta[index].play(); + }else{ + playRandomSwell(); + } + setTimeout(function() { + current_notes--; + }, note_timeout); + } +} + +// Following are the n numbers of event consumers +// consuming n events each per second with a random delay between them + +function playFromQueueExchange1(){ + var event = eventQueue.shift(); + if(event != null && event.message != null && !shouldEventBeIgnored(event) && svg != null){ + playSound(event.message.length*1.1, event.type); + if(!document.hidden) + drawEvent(event, svg); + } + setTimeout(playFromQueueExchange1, Math.floor(Math.random() * 1000) + 500); + $('.events-remaining-value').html(eventQueue.length); +} + +function playFromQueueExchange2(){ + var event = eventQueue.shift(); + if(event != null && event.message != null && !shouldEventBeIgnored(event) && svg != null){ + playSound(event.message.length, event.type); + if(!document.hidden) + drawEvent(event, svg); + } + setTimeout(playFromQueueExchange2, Math.floor(Math.random() * 800) + 500); + $('.events-remaining-value').html(eventQueue.length); +} + +// This method capitalizes the string in place +String.prototype.capitalize=function(all){ + if(all){ + return this.split(' ').map(function(e){ + return e.capitalize().join(' '); + }); + }else{ + return this.charAt(0).toUpperCase() + this.slice(1); + } +} + + +function drawEvent(data, svg_area) { + var starting_opacity = 1; + var opacity = 1 / (100 / data.message.length); + if (opacity > 0.5) { + opacity = 0.5; + } + var size = data.message.length; + var label_text; + var ring_radius = 80; + var ring_anim_duration = 3000; + svg_text_color = '#FFFFFF'; + switch(data.type){ + case "PushEvent": + label_text = data.user.capitalize() + " pushed to " + data.repo_name; + edit_color = '#B2DFDB'; + break; + case "PullRequestEvent": + label_text = data.user.capitalize() + " " + + data.action + " " + " a PR for " + data.repo_name; + edit_color = '#C6FF00'; + ring_anim_duration = 10000; + ring_radius = 600; + break; + case "IssuesEvent": + label_text = data.user.capitalize() + " " + + data.action + " an issue in " + data.repo_name; + edit_color = '#FFEB3B'; + break; + case "IssueCommentEvent": + label_text = data.user.capitalize() + " commented in " + data.repo_name; + edit_color = '#FF5722'; + break; + } + var csize = size; + var no_label = false; + var type = data.type; + + var circle_id = 'd' + ((Math.random() * 100000) | 0); + var abs_size = Math.abs(size); + size = Math.max(Math.sqrt(abs_size) * scale_factor, 3); + + Math.seedrandom(data.message) + var x = Math.random() * (width - size) + size; + var y = Math.random() * (height - size) + size; + + + var circle_group = svg_area.append('g') + .attr('transform', 'translate(' + x + ', ' + y + ')') + .attr('fill', edit_color) + .style('opacity', starting_opacity) + + + var ring = circle_group.append('circle'); + ring.attr({r: size, stroke: 'none'}); + ring.transition() + .attr('r', size + ring_radius) + .style('opacity', 0) + .ease(Math.sqrt) + .duration(ring_anim_duration) + .remove(); + + var circle_container = circle_group.append('a'); + circle_container.attr('xlink:href', data.url); + circle_container.attr('target', '_blank'); + circle_container.attr('fill', svg_text_color); + + var circle = circle_container.append('circle'); + circle.classed(type, true); + circle.attr('r', size) + .attr('fill', edit_color) + .transition() + .duration(max_life) + .style('opacity', 0) + .remove(); + + + circle_container.on('mouseover', function() { + circle_container.append('text') + .text(label_text) + .classed('label', true) + .attr('text-anchor', 'middle') + .attr('font-size', '0.8em') + .transition() + .delay(1000) + .style('opacity', 0) + .duration(2000) + .each(function() { no_label = true; }) + .remove(); + }); + + var text = circle_container.append('text') + .text(label_text) + .classed('article-label', true) + .attr('text-anchor', 'middle') + .attr('font-size', '0.8em') + .transition() + .delay(2000) + .style('opacity', 0) + .duration(5000) + .each(function() { no_label = true; }) + .remove(); + + // Remove HTML of decayed events + // Keep it less than 50 + if($('#area svg g').length > 50){ + $('#area svg g:lt(10)').remove(); + } +} diff --git a/app/public/sounds/celesta/c001.mp3 b/app/public/sounds/celesta/c001.mp3 new file mode 100644 index 0000000..ff8fc6b Binary files /dev/null and b/app/public/sounds/celesta/c001.mp3 differ diff --git a/app/public/sounds/celesta/c001.ogg b/app/public/sounds/celesta/c001.ogg new file mode 100644 index 0000000..8d2ee74 Binary files /dev/null and b/app/public/sounds/celesta/c001.ogg differ diff --git a/app/public/sounds/celesta/c002.mp3 b/app/public/sounds/celesta/c002.mp3 new file mode 100644 index 0000000..7f2465f Binary files /dev/null and b/app/public/sounds/celesta/c002.mp3 differ diff --git a/app/public/sounds/celesta/c002.ogg b/app/public/sounds/celesta/c002.ogg new file mode 100644 index 0000000..377f042 Binary files /dev/null and b/app/public/sounds/celesta/c002.ogg differ diff --git a/app/public/sounds/celesta/c003.mp3 b/app/public/sounds/celesta/c003.mp3 new file mode 100644 index 0000000..ea7cc8a Binary files /dev/null and b/app/public/sounds/celesta/c003.mp3 differ diff --git a/app/public/sounds/celesta/c003.ogg b/app/public/sounds/celesta/c003.ogg new file mode 100644 index 0000000..67a84d0 Binary files /dev/null and b/app/public/sounds/celesta/c003.ogg differ diff --git a/app/public/sounds/celesta/c004.mp3 b/app/public/sounds/celesta/c004.mp3 new file mode 100644 index 0000000..1b1e410 Binary files /dev/null and b/app/public/sounds/celesta/c004.mp3 differ diff --git a/app/public/sounds/celesta/c004.ogg b/app/public/sounds/celesta/c004.ogg new file mode 100644 index 0000000..6e9d64a Binary files /dev/null and b/app/public/sounds/celesta/c004.ogg differ diff --git a/app/public/sounds/celesta/c005.mp3 b/app/public/sounds/celesta/c005.mp3 new file mode 100644 index 0000000..6236c42 Binary files /dev/null and b/app/public/sounds/celesta/c005.mp3 differ diff --git a/app/public/sounds/celesta/c005.ogg b/app/public/sounds/celesta/c005.ogg new file mode 100644 index 0000000..5f08d92 Binary files /dev/null and b/app/public/sounds/celesta/c005.ogg differ diff --git a/app/public/sounds/celesta/c006.mp3 b/app/public/sounds/celesta/c006.mp3 new file mode 100644 index 0000000..7d08fb3 Binary files /dev/null and b/app/public/sounds/celesta/c006.mp3 differ diff --git a/app/public/sounds/celesta/c006.ogg b/app/public/sounds/celesta/c006.ogg new file mode 100644 index 0000000..da6af41 Binary files /dev/null and b/app/public/sounds/celesta/c006.ogg differ diff --git a/app/public/sounds/celesta/c007.mp3 b/app/public/sounds/celesta/c007.mp3 new file mode 100644 index 0000000..847ba88 Binary files /dev/null and b/app/public/sounds/celesta/c007.mp3 differ diff --git a/app/public/sounds/celesta/c007.ogg b/app/public/sounds/celesta/c007.ogg new file mode 100644 index 0000000..2c0220b Binary files /dev/null and b/app/public/sounds/celesta/c007.ogg differ diff --git a/app/public/sounds/celesta/c008.mp3 b/app/public/sounds/celesta/c008.mp3 new file mode 100644 index 0000000..71ae306 Binary files /dev/null and b/app/public/sounds/celesta/c008.mp3 differ diff --git a/app/public/sounds/celesta/c008.ogg b/app/public/sounds/celesta/c008.ogg new file mode 100644 index 0000000..a6141f9 Binary files /dev/null and b/app/public/sounds/celesta/c008.ogg differ diff --git a/app/public/sounds/celesta/c009.mp3 b/app/public/sounds/celesta/c009.mp3 new file mode 100644 index 0000000..7bc9d18 Binary files /dev/null and b/app/public/sounds/celesta/c009.mp3 differ diff --git a/app/public/sounds/celesta/c009.ogg b/app/public/sounds/celesta/c009.ogg new file mode 100644 index 0000000..2476f06 Binary files /dev/null and b/app/public/sounds/celesta/c009.ogg differ diff --git a/app/public/sounds/celesta/c010.mp3 b/app/public/sounds/celesta/c010.mp3 new file mode 100644 index 0000000..d8b39cb Binary files /dev/null and b/app/public/sounds/celesta/c010.mp3 differ diff --git a/app/public/sounds/celesta/c010.ogg b/app/public/sounds/celesta/c010.ogg new file mode 100644 index 0000000..3f7e52a Binary files /dev/null and b/app/public/sounds/celesta/c010.ogg differ diff --git a/app/public/sounds/celesta/c011.mp3 b/app/public/sounds/celesta/c011.mp3 new file mode 100644 index 0000000..41bfae4 Binary files /dev/null and b/app/public/sounds/celesta/c011.mp3 differ diff --git a/app/public/sounds/celesta/c011.ogg b/app/public/sounds/celesta/c011.ogg new file mode 100644 index 0000000..1576924 Binary files /dev/null and b/app/public/sounds/celesta/c011.ogg differ diff --git a/app/public/sounds/celesta/c012.mp3 b/app/public/sounds/celesta/c012.mp3 new file mode 100644 index 0000000..aa89252 Binary files /dev/null and b/app/public/sounds/celesta/c012.mp3 differ diff --git a/app/public/sounds/celesta/c012.ogg b/app/public/sounds/celesta/c012.ogg new file mode 100644 index 0000000..4d84c83 Binary files /dev/null and b/app/public/sounds/celesta/c012.ogg differ diff --git a/app/public/sounds/celesta/c013.mp3 b/app/public/sounds/celesta/c013.mp3 new file mode 100644 index 0000000..c6f3954 Binary files /dev/null and b/app/public/sounds/celesta/c013.mp3 differ diff --git a/app/public/sounds/celesta/c013.ogg b/app/public/sounds/celesta/c013.ogg new file mode 100644 index 0000000..dce2d1a Binary files /dev/null and b/app/public/sounds/celesta/c013.ogg differ diff --git a/app/public/sounds/celesta/c014.mp3 b/app/public/sounds/celesta/c014.mp3 new file mode 100644 index 0000000..5f42021 Binary files /dev/null and b/app/public/sounds/celesta/c014.mp3 differ diff --git a/app/public/sounds/celesta/c014.ogg b/app/public/sounds/celesta/c014.ogg new file mode 100644 index 0000000..05bfbe3 Binary files /dev/null and b/app/public/sounds/celesta/c014.ogg differ diff --git a/app/public/sounds/celesta/c015.mp3 b/app/public/sounds/celesta/c015.mp3 new file mode 100644 index 0000000..2d03c00 Binary files /dev/null and b/app/public/sounds/celesta/c015.mp3 differ diff --git a/app/public/sounds/celesta/c015.ogg b/app/public/sounds/celesta/c015.ogg new file mode 100644 index 0000000..3521603 Binary files /dev/null and b/app/public/sounds/celesta/c015.ogg differ diff --git a/app/public/sounds/celesta/c016.mp3 b/app/public/sounds/celesta/c016.mp3 new file mode 100644 index 0000000..e75f0a9 Binary files /dev/null and b/app/public/sounds/celesta/c016.mp3 differ diff --git a/app/public/sounds/celesta/c016.ogg b/app/public/sounds/celesta/c016.ogg new file mode 100644 index 0000000..e995964 Binary files /dev/null and b/app/public/sounds/celesta/c016.ogg differ diff --git a/app/public/sounds/celesta/c017.mp3 b/app/public/sounds/celesta/c017.mp3 new file mode 100644 index 0000000..2596327 Binary files /dev/null and b/app/public/sounds/celesta/c017.mp3 differ diff --git a/app/public/sounds/celesta/c017.ogg b/app/public/sounds/celesta/c017.ogg new file mode 100644 index 0000000..fd8f78f Binary files /dev/null and b/app/public/sounds/celesta/c017.ogg differ diff --git a/app/public/sounds/celesta/c018.mp3 b/app/public/sounds/celesta/c018.mp3 new file mode 100644 index 0000000..10a57ec Binary files /dev/null and b/app/public/sounds/celesta/c018.mp3 differ diff --git a/app/public/sounds/celesta/c018.ogg b/app/public/sounds/celesta/c018.ogg new file mode 100644 index 0000000..6a19eab Binary files /dev/null and b/app/public/sounds/celesta/c018.ogg differ diff --git a/app/public/sounds/celesta/c019.mp3 b/app/public/sounds/celesta/c019.mp3 new file mode 100644 index 0000000..73804ed Binary files /dev/null and b/app/public/sounds/celesta/c019.mp3 differ diff --git a/app/public/sounds/celesta/c019.ogg b/app/public/sounds/celesta/c019.ogg new file mode 100644 index 0000000..6962652 Binary files /dev/null and b/app/public/sounds/celesta/c019.ogg differ diff --git a/app/public/sounds/celesta/c020.mp3 b/app/public/sounds/celesta/c020.mp3 new file mode 100644 index 0000000..099bd79 Binary files /dev/null and b/app/public/sounds/celesta/c020.mp3 differ diff --git a/app/public/sounds/celesta/c020.ogg b/app/public/sounds/celesta/c020.ogg new file mode 100644 index 0000000..961235f Binary files /dev/null and b/app/public/sounds/celesta/c020.ogg differ diff --git a/app/public/sounds/celesta/c021.mp3 b/app/public/sounds/celesta/c021.mp3 new file mode 100644 index 0000000..f85fede Binary files /dev/null and b/app/public/sounds/celesta/c021.mp3 differ diff --git a/app/public/sounds/celesta/c021.ogg b/app/public/sounds/celesta/c021.ogg new file mode 100644 index 0000000..0552639 Binary files /dev/null and b/app/public/sounds/celesta/c021.ogg differ diff --git a/app/public/sounds/celesta/c022.mp3 b/app/public/sounds/celesta/c022.mp3 new file mode 100644 index 0000000..78de515 Binary files /dev/null and b/app/public/sounds/celesta/c022.mp3 differ diff --git a/app/public/sounds/celesta/c022.ogg b/app/public/sounds/celesta/c022.ogg new file mode 100644 index 0000000..02e4054 Binary files /dev/null and b/app/public/sounds/celesta/c022.ogg differ diff --git a/app/public/sounds/celesta/c023.mp3 b/app/public/sounds/celesta/c023.mp3 new file mode 100644 index 0000000..a8b44b3 Binary files /dev/null and b/app/public/sounds/celesta/c023.mp3 differ diff --git a/app/public/sounds/celesta/c023.ogg b/app/public/sounds/celesta/c023.ogg new file mode 100644 index 0000000..2f42c4a Binary files /dev/null and b/app/public/sounds/celesta/c023.ogg differ diff --git a/app/public/sounds/celesta/c024.mp3 b/app/public/sounds/celesta/c024.mp3 new file mode 100644 index 0000000..99296d6 Binary files /dev/null and b/app/public/sounds/celesta/c024.mp3 differ diff --git a/app/public/sounds/celesta/c024.ogg b/app/public/sounds/celesta/c024.ogg new file mode 100644 index 0000000..0753007 Binary files /dev/null and b/app/public/sounds/celesta/c024.ogg differ diff --git a/app/public/sounds/celesta/c025.mp3 b/app/public/sounds/celesta/c025.mp3 new file mode 100644 index 0000000..53981a3 Binary files /dev/null and b/app/public/sounds/celesta/c025.mp3 differ diff --git a/app/public/sounds/celesta/c025.ogg b/app/public/sounds/celesta/c025.ogg new file mode 100644 index 0000000..7d85ffc Binary files /dev/null and b/app/public/sounds/celesta/c025.ogg differ diff --git a/app/public/sounds/celesta/c026.mp3 b/app/public/sounds/celesta/c026.mp3 new file mode 100644 index 0000000..5504753 Binary files /dev/null and b/app/public/sounds/celesta/c026.mp3 differ diff --git a/app/public/sounds/celesta/c026.ogg b/app/public/sounds/celesta/c026.ogg new file mode 100644 index 0000000..c338efb Binary files /dev/null and b/app/public/sounds/celesta/c026.ogg differ diff --git a/app/public/sounds/celesta/c027.mp3 b/app/public/sounds/celesta/c027.mp3 new file mode 100644 index 0000000..04abd51 Binary files /dev/null and b/app/public/sounds/celesta/c027.mp3 differ diff --git a/app/public/sounds/celesta/c027.ogg b/app/public/sounds/celesta/c027.ogg new file mode 100644 index 0000000..cc9f0ea Binary files /dev/null and b/app/public/sounds/celesta/c027.ogg differ diff --git a/app/public/sounds/clav/c001.mp3 b/app/public/sounds/clav/c001.mp3 new file mode 100644 index 0000000..767f196 Binary files /dev/null and b/app/public/sounds/clav/c001.mp3 differ diff --git a/app/public/sounds/clav/c001.ogg b/app/public/sounds/clav/c001.ogg new file mode 100644 index 0000000..6cbb314 Binary files /dev/null and b/app/public/sounds/clav/c001.ogg differ diff --git a/app/public/sounds/clav/c002.mp3 b/app/public/sounds/clav/c002.mp3 new file mode 100644 index 0000000..3e1f896 Binary files /dev/null and b/app/public/sounds/clav/c002.mp3 differ diff --git a/app/public/sounds/clav/c002.ogg b/app/public/sounds/clav/c002.ogg new file mode 100644 index 0000000..50a8469 Binary files /dev/null and b/app/public/sounds/clav/c002.ogg differ diff --git a/app/public/sounds/clav/c003.mp3 b/app/public/sounds/clav/c003.mp3 new file mode 100644 index 0000000..6a8082a Binary files /dev/null and b/app/public/sounds/clav/c003.mp3 differ diff --git a/app/public/sounds/clav/c003.ogg b/app/public/sounds/clav/c003.ogg new file mode 100644 index 0000000..e313fd5 Binary files /dev/null and b/app/public/sounds/clav/c003.ogg differ diff --git a/app/public/sounds/clav/c004.mp3 b/app/public/sounds/clav/c004.mp3 new file mode 100644 index 0000000..9b4ebad Binary files /dev/null and b/app/public/sounds/clav/c004.mp3 differ diff --git a/app/public/sounds/clav/c004.ogg b/app/public/sounds/clav/c004.ogg new file mode 100644 index 0000000..4bf3152 Binary files /dev/null and b/app/public/sounds/clav/c004.ogg differ diff --git a/app/public/sounds/clav/c005.mp3 b/app/public/sounds/clav/c005.mp3 new file mode 100644 index 0000000..8b6a64f Binary files /dev/null and b/app/public/sounds/clav/c005.mp3 differ diff --git a/app/public/sounds/clav/c005.ogg b/app/public/sounds/clav/c005.ogg new file mode 100644 index 0000000..6463364 Binary files /dev/null and b/app/public/sounds/clav/c005.ogg differ diff --git a/app/public/sounds/clav/c006.mp3 b/app/public/sounds/clav/c006.mp3 new file mode 100644 index 0000000..63b254d Binary files /dev/null and b/app/public/sounds/clav/c006.mp3 differ diff --git a/app/public/sounds/clav/c006.ogg b/app/public/sounds/clav/c006.ogg new file mode 100644 index 0000000..99ae38f Binary files /dev/null and b/app/public/sounds/clav/c006.ogg differ diff --git a/app/public/sounds/clav/c007.mp3 b/app/public/sounds/clav/c007.mp3 new file mode 100644 index 0000000..918659e Binary files /dev/null and b/app/public/sounds/clav/c007.mp3 differ diff --git a/app/public/sounds/clav/c007.ogg b/app/public/sounds/clav/c007.ogg new file mode 100644 index 0000000..8834b65 Binary files /dev/null and b/app/public/sounds/clav/c007.ogg differ diff --git a/app/public/sounds/clav/c008.mp3 b/app/public/sounds/clav/c008.mp3 new file mode 100644 index 0000000..c11db41 Binary files /dev/null and b/app/public/sounds/clav/c008.mp3 differ diff --git a/app/public/sounds/clav/c008.ogg b/app/public/sounds/clav/c008.ogg new file mode 100644 index 0000000..9600789 Binary files /dev/null and b/app/public/sounds/clav/c008.ogg differ diff --git a/app/public/sounds/clav/c009.mp3 b/app/public/sounds/clav/c009.mp3 new file mode 100644 index 0000000..5681565 Binary files /dev/null and b/app/public/sounds/clav/c009.mp3 differ diff --git a/app/public/sounds/clav/c009.ogg b/app/public/sounds/clav/c009.ogg new file mode 100644 index 0000000..594c174 Binary files /dev/null and b/app/public/sounds/clav/c009.ogg differ diff --git a/app/public/sounds/clav/c010.mp3 b/app/public/sounds/clav/c010.mp3 new file mode 100644 index 0000000..fc63d83 Binary files /dev/null and b/app/public/sounds/clav/c010.mp3 differ diff --git a/app/public/sounds/clav/c010.ogg b/app/public/sounds/clav/c010.ogg new file mode 100644 index 0000000..df69244 Binary files /dev/null and b/app/public/sounds/clav/c010.ogg differ diff --git a/app/public/sounds/clav/c011.mp3 b/app/public/sounds/clav/c011.mp3 new file mode 100644 index 0000000..d6873d2 Binary files /dev/null and b/app/public/sounds/clav/c011.mp3 differ diff --git a/app/public/sounds/clav/c011.ogg b/app/public/sounds/clav/c011.ogg new file mode 100644 index 0000000..fbe63ed Binary files /dev/null and b/app/public/sounds/clav/c011.ogg differ diff --git a/app/public/sounds/clav/c012.mp3 b/app/public/sounds/clav/c012.mp3 new file mode 100644 index 0000000..7e0c54b Binary files /dev/null and b/app/public/sounds/clav/c012.mp3 differ diff --git a/app/public/sounds/clav/c012.ogg b/app/public/sounds/clav/c012.ogg new file mode 100644 index 0000000..cf13394 Binary files /dev/null and b/app/public/sounds/clav/c012.ogg differ diff --git a/app/public/sounds/clav/c013.mp3 b/app/public/sounds/clav/c013.mp3 new file mode 100644 index 0000000..bf6b3f6 Binary files /dev/null and b/app/public/sounds/clav/c013.mp3 differ diff --git a/app/public/sounds/clav/c013.ogg b/app/public/sounds/clav/c013.ogg new file mode 100644 index 0000000..f7c9695 Binary files /dev/null and b/app/public/sounds/clav/c013.ogg differ diff --git a/app/public/sounds/clav/c014.mp3 b/app/public/sounds/clav/c014.mp3 new file mode 100644 index 0000000..b87059d Binary files /dev/null and b/app/public/sounds/clav/c014.mp3 differ diff --git a/app/public/sounds/clav/c014.ogg b/app/public/sounds/clav/c014.ogg new file mode 100644 index 0000000..acf771e Binary files /dev/null and b/app/public/sounds/clav/c014.ogg differ diff --git a/app/public/sounds/clav/c015.mp3 b/app/public/sounds/clav/c015.mp3 new file mode 100644 index 0000000..b1d7c83 Binary files /dev/null and b/app/public/sounds/clav/c015.mp3 differ diff --git a/app/public/sounds/clav/c015.ogg b/app/public/sounds/clav/c015.ogg new file mode 100644 index 0000000..8c12121 Binary files /dev/null and b/app/public/sounds/clav/c015.ogg differ diff --git a/app/public/sounds/clav/c016.mp3 b/app/public/sounds/clav/c016.mp3 new file mode 100644 index 0000000..b748696 Binary files /dev/null and b/app/public/sounds/clav/c016.mp3 differ diff --git a/app/public/sounds/clav/c016.ogg b/app/public/sounds/clav/c016.ogg new file mode 100644 index 0000000..cd8a47f Binary files /dev/null and b/app/public/sounds/clav/c016.ogg differ diff --git a/app/public/sounds/clav/c017.mp3 b/app/public/sounds/clav/c017.mp3 new file mode 100644 index 0000000..b66ae79 Binary files /dev/null and b/app/public/sounds/clav/c017.mp3 differ diff --git a/app/public/sounds/clav/c017.ogg b/app/public/sounds/clav/c017.ogg new file mode 100644 index 0000000..0a6f8e9 Binary files /dev/null and b/app/public/sounds/clav/c017.ogg differ diff --git a/app/public/sounds/clav/c018.mp3 b/app/public/sounds/clav/c018.mp3 new file mode 100644 index 0000000..d6f0c00 Binary files /dev/null and b/app/public/sounds/clav/c018.mp3 differ diff --git a/app/public/sounds/clav/c018.ogg b/app/public/sounds/clav/c018.ogg new file mode 100644 index 0000000..8317ad2 Binary files /dev/null and b/app/public/sounds/clav/c018.ogg differ diff --git a/app/public/sounds/clav/c019.mp3 b/app/public/sounds/clav/c019.mp3 new file mode 100644 index 0000000..66f87a4 Binary files /dev/null and b/app/public/sounds/clav/c019.mp3 differ diff --git a/app/public/sounds/clav/c019.ogg b/app/public/sounds/clav/c019.ogg new file mode 100644 index 0000000..aa7951c Binary files /dev/null and b/app/public/sounds/clav/c019.ogg differ diff --git a/app/public/sounds/clav/c020.mp3 b/app/public/sounds/clav/c020.mp3 new file mode 100644 index 0000000..055131a Binary files /dev/null and b/app/public/sounds/clav/c020.mp3 differ diff --git a/app/public/sounds/clav/c020.ogg b/app/public/sounds/clav/c020.ogg new file mode 100644 index 0000000..e570a83 Binary files /dev/null and b/app/public/sounds/clav/c020.ogg differ diff --git a/app/public/sounds/clav/c021.mp3 b/app/public/sounds/clav/c021.mp3 new file mode 100644 index 0000000..39ef76c Binary files /dev/null and b/app/public/sounds/clav/c021.mp3 differ diff --git a/app/public/sounds/clav/c021.ogg b/app/public/sounds/clav/c021.ogg new file mode 100644 index 0000000..f6b617a Binary files /dev/null and b/app/public/sounds/clav/c021.ogg differ diff --git a/app/public/sounds/clav/c022.mp3 b/app/public/sounds/clav/c022.mp3 new file mode 100644 index 0000000..29133fc Binary files /dev/null and b/app/public/sounds/clav/c022.mp3 differ diff --git a/app/public/sounds/clav/c022.ogg b/app/public/sounds/clav/c022.ogg new file mode 100644 index 0000000..7f28925 Binary files /dev/null and b/app/public/sounds/clav/c022.ogg differ diff --git a/app/public/sounds/clav/c023.mp3 b/app/public/sounds/clav/c023.mp3 new file mode 100644 index 0000000..96e26fd Binary files /dev/null and b/app/public/sounds/clav/c023.mp3 differ diff --git a/app/public/sounds/clav/c023.ogg b/app/public/sounds/clav/c023.ogg new file mode 100644 index 0000000..2269d6e Binary files /dev/null and b/app/public/sounds/clav/c023.ogg differ diff --git a/app/public/sounds/clav/c024.mp3 b/app/public/sounds/clav/c024.mp3 new file mode 100644 index 0000000..0a44c37 Binary files /dev/null and b/app/public/sounds/clav/c024.mp3 differ diff --git a/app/public/sounds/clav/c024.ogg b/app/public/sounds/clav/c024.ogg new file mode 100644 index 0000000..925ce9b Binary files /dev/null and b/app/public/sounds/clav/c024.ogg differ diff --git a/app/public/sounds/clav/c025.mp3 b/app/public/sounds/clav/c025.mp3 new file mode 100644 index 0000000..06bae2b Binary files /dev/null and b/app/public/sounds/clav/c025.mp3 differ diff --git a/app/public/sounds/clav/c025.ogg b/app/public/sounds/clav/c025.ogg new file mode 100644 index 0000000..3812660 Binary files /dev/null and b/app/public/sounds/clav/c025.ogg differ diff --git a/app/public/sounds/clav/c026.mp3 b/app/public/sounds/clav/c026.mp3 new file mode 100644 index 0000000..e848617 Binary files /dev/null and b/app/public/sounds/clav/c026.mp3 differ diff --git a/app/public/sounds/clav/c026.ogg b/app/public/sounds/clav/c026.ogg new file mode 100644 index 0000000..543cab0 Binary files /dev/null and b/app/public/sounds/clav/c026.ogg differ diff --git a/app/public/sounds/clav/c027.mp3 b/app/public/sounds/clav/c027.mp3 new file mode 100644 index 0000000..02133ed Binary files /dev/null and b/app/public/sounds/clav/c027.mp3 differ diff --git a/app/public/sounds/clav/c027.ogg b/app/public/sounds/clav/c027.ogg new file mode 100644 index 0000000..a57cd31 Binary files /dev/null and b/app/public/sounds/clav/c027.ogg differ diff --git a/app/public/sounds/swells/swell1.mp3 b/app/public/sounds/swells/swell1.mp3 new file mode 100644 index 0000000..46c6e7f Binary files /dev/null and b/app/public/sounds/swells/swell1.mp3 differ diff --git a/app/public/sounds/swells/swell1.ogg b/app/public/sounds/swells/swell1.ogg new file mode 100644 index 0000000..16747f0 Binary files /dev/null and b/app/public/sounds/swells/swell1.ogg differ diff --git a/app/public/sounds/swells/swell2.mp3 b/app/public/sounds/swells/swell2.mp3 new file mode 100644 index 0000000..db8d58e Binary files /dev/null and b/app/public/sounds/swells/swell2.mp3 differ diff --git a/app/public/sounds/swells/swell2.ogg b/app/public/sounds/swells/swell2.ogg new file mode 100644 index 0000000..6afbde0 Binary files /dev/null and b/app/public/sounds/swells/swell2.ogg differ diff --git a/app/public/sounds/swells/swell3.mp3 b/app/public/sounds/swells/swell3.mp3 new file mode 100644 index 0000000..b9cc751 Binary files /dev/null and b/app/public/sounds/swells/swell3.mp3 differ diff --git a/app/public/sounds/swells/swell3.ogg b/app/public/sounds/swells/swell3.ogg new file mode 100644 index 0000000..e09002f Binary files /dev/null and b/app/public/sounds/swells/swell3.ogg differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..8e843a4 --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "github-audio", + "version": "1.0.0", + "description": "Listen to music generated by events across GitHub", + "main": "index.js", + "scripts": { + "test": "test", + "start": "cross-env NODE_ENV=development node server" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/debugger22/github-audio.git" + }, + "keywords": [ + "github", + "music" + ], + "author": "Sudhanshu Mishra", + "license": "MIT", + "bugs": { + "url": "https://github.com/debugger22/github-audio/issues" + }, + "homepage": "https://github.com/debugger22/github-audio#readme", + "dependencies": { + "chalk": "^1.1.3", + "cross-env": "^3.1.2", + "express": "^4.14.0", + "helmet": "^2.2.0", + "ip": "^1.1.3", + "minimist": "^1.2.0", + "path": "^0.12.7", + "redis": "^2.6.2", + "request": "^2.75.0", + "socket.io": "^1.4.8" + }, + "engines": { + "node": "4.x" + } +} diff --git a/server/index.js b/server/index.js new file mode 100755 index 0000000..ea45379 --- /dev/null +++ b/server/index.js @@ -0,0 +1,171 @@ +#!/usr/bin/env nodejs + +var express = require('express'); +var app = express(); +var request = require("request"); // To make HTTP requests at the server side + +var server = require('http').Server(app); +var io = require('socket.io')(server); + +var helmet = require('helmet'); // To change response headers + +// To temporarily store JSON data from GitHub and also +// the number of connected users +var redis = require("redis"); +if (process.env.REDIS_URL) { + redis_client = redis.createClient(process.env.REDIS_URL); +} else { + redis_client = redis.createClient(); +} + +var path = require('path'); + +const logger = require('./logger'); +const argv = require('minimist')(process.argv.slice(2)); +const isDev = process.env.NODE_ENV !== 'production'; + +// Get the intended port number, use port 8000 if not provided +const port = argv.port || process.env.PORT || 8000; +server.listen(port, (err) => { + if(err){ + return logger.error(err.message); + } +}); +if(isDev) + logger.appStarted(port, 'http://localhost'); +else + logger.appStarted(port); + +// Apply security middlewares +app.use(helmet()); + +// Remove x-powered-by header +app.disable('x-powered-by'); + +// server static files +app.use('/static', express.static('app')); + +// Load main web page +app.get('/', function (req, res) { + res.sendFile(path.resolve('app/index.html')); +}); + +var allClients = []; + +// When a socket connection is created +io.on('connection', function (socket) { + allClients.push(socket); + redis_client.incr('connected_users'); + socket.on('disconnect', function() { + logger.v('Got disconnect!'); + var i = allClients.indexOf(socket); + allClients.splice(i, 1); + redis_client.decr('connected_users'); + }); + socket.on('error', function(){ + logger.error('Got errored!'); + redis_client.decr('connected_users'); + }) +}); + +// Function to get events from GitHub API +function fetchDataFromGithub(){ + var options = { + url: 'https://api.github.com/events', + headers: { + 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36', + 'Authorization': 'token ' + process.env.GITHUB_OAUTH_KEY + } + }; + request(options, function (error, response, body) { + if (!error && response.statusCode == 200) { + var data = JSON.parse(body); + var stripedData = stripData(data); // Keep only useful keys + allClients.forEach(function(socket){ + if(socket != null && socket.connected == true){ + redis_client.get('connected_users', function(err, count) { + if(!err && count != null){ + socket.volatile.json.emit('github', {data: stripedData, connected_users: count}); + }else{ + logger.error(err.message); + } + }); + } + }); + + }else{ + logger.error("GitHub status code: " + response.statusCode); + } + }) + setTimeout(fetchDataFromGithub, 2000); +} +setTimeout(fetchDataFromGithub, 2000); + + +function stripData(data){ + var stripedData = []; + var pushEventCounter = 0; + var IssueCommentEventCounter = 0; + var IssuesEventCounter = 0; + data.forEach(function(data){ + if(data.type == 'PushEvent'){ + if(pushEventCounter > 3) return; + if(data.payload.size != 0){ + stripedData.push({ + 'id': data.id, + 'type': data.type, + 'user': data.actor.display_login, + 'user_avatar': data.actor.avatar_url + 'v=3&s=64', + 'repo_id': data.repo.id, + 'repo_name': data.repo.name, + 'payload_size': data.payload.size, + 'message': data.payload.commits[0].message, + 'created': data.created_at, + 'url': data.repo.url + }); + pushEventCounter++; + } + }else if(data.type == 'IssueCommentEvent'){ + stripedData.push({ + 'id': data.id, + 'type': data.type, + 'user': data.actor.display_login, + 'user_avatar': data.actor.avatar_url + 'v=3&s=64', + 'repo_id': data.repo.id, + 'repo_name': data.repo.name, + 'payload_size': 0, + 'message': data.body, + 'created': data.created_at, + 'url': data.payload.comment.html_url + }); + }else if(data.type == 'PullRequestEvent'){ + if (data.payload.pull_request.merged) data.payload.action = 'merged'; + stripedData.push({ + 'id': data.id, + 'type': data.type, + 'user': data.actor.display_login, + 'user_avatar': data.actor.avatar_url + 'v=3&s=64', + 'repo_id': data.repo.id, + 'repo_name': data.repo.name, + 'action': data.payload.action, // opened, reopened, closed, merged + 'message': data.payload.pull_request.title, + 'created': data.created_at, + 'url': data.payload.pull_request.html_url + }); + }else if(data.type == 'IssuesEvent'){ + stripedData.push({ + 'id': data.id, + 'type': data.type, + 'user': data.actor.display_login, + 'user_avatar': data.actor.avatar_url + 'v=3&s=64', + 'repo_id': data.repo.id, + 'repo_name': data.repo.name, + 'action': data.payload.action, // opened, reopened, closed + 'message': data.payload.issue.title, + 'created': data.created_at, + 'url': data.payload.issue.html_url + }); + } + }); + return stripedData; +} diff --git a/server/logger.js b/server/logger.js new file mode 100644 index 0000000..07c07c3 --- /dev/null +++ b/server/logger.js @@ -0,0 +1,44 @@ +/* eslint-disable no-console */ + +const chalk = require('chalk'); +const ip = require('ip'); + +const divider = chalk.gray('\n-----------------------------------'); + +const logger = { + + // Called whenever there's an error on the server we want to print + error: (err) => { + console.error(chalk.red(err)); + }, + + // Called whenever there's a debug log we want to print + d: (log) => { + console.log(chalk.blue(log)); + }, + + // Called whenever there's a verbose log we want to print + v: (log) => { + console.log(chalk.white(log)); + }, + + // Called when express.js app starts on given port w/o errors + appStarted: (port, tunnelStarted) => { + console.log(`Server started ${chalk.green('✓')}`); + + // If the tunnel started, log that and the URL it's available at + if (tunnelStarted) { + console.log(`Tunnel initialised ${chalk.green('✓')}`); + } + + console.log(` +${chalk.bold('Access URLs:')}${divider} +Localhost: ${chalk.magenta(`http://localhost:${port}`)} + LAN: ${chalk.magenta(`http://${ip.address()}:${port}`) + +(tunnelStarted ? `\n Proxy: ${chalk.magenta(tunnelStarted)}` : '')}${divider} +${chalk.blue(`Press ${chalk.italic('CTRL-C')} to stop`)} + `); + }, +}; + +module.exports = logger;