forked from debugger22/github-audio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee81ef6
commit 33acf4c
Showing
5 changed files
with
166 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,51 @@ | ||
# github-audio | ||
GitHub Audio | ||
============ | ||
|
||
Listen to music generated by events happening across GitHub | ||
|
||
|
||
Installation on OSX | ||
------------------- | ||
|
||
```bash | ||
$ brew install nodejs | ||
$ brew npm | ||
$ brew install redis | ||
``` | ||
|
||
Installation on Linux | ||
--------------------- | ||
|
||
```bash | ||
$ sudo apt-get updade | ||
$ sudo apt-get install nodejs | ||
$ sudo apt-get install npm | ||
$ sudo apt-get install redis-server | ||
``` | ||
|
||
Install node packages | ||
--------------------- | ||
|
||
Navigate to the project directory and run | ||
|
||
```bash | ||
$ npm install | ||
``` | ||
|
||
Environment variables | ||
--------------------- | ||
|
||
``` | ||
$ export GITHUB_OAUTH_KEY=<your_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 server | ||
---------- | ||
|
||
```bash | ||
$ node app/server.js | ||
``` | ||
|
||
Note: For production run `export NODE_ENV="production"` before starting the server. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env nodejs | ||
|
||
var app = require('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); | ||
|
||
// To temporarily store JSON data from GitHub and also | ||
// the number of connected users | ||
var redis = require("redis"), | ||
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); | ||
|
||
// Load main web page | ||
app.get('/', function (req, res) { | ||
res.sendFile(path.resolve('app/index.html')); | ||
}); | ||
|
||
|
||
// When a socket connection is created | ||
io.on('connection', function (socket) { | ||
|
||
|
||
// 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) { | ||
socket.emit('github', body); | ||
}else{ | ||
logger.d("GitHib request: " + options.headers.Authorization); | ||
logger.error("GitHub status code: " + response.statusCode); | ||
} | ||
}) | ||
|
||
setTimeout(fetchDataFromGithub, 2000); | ||
} | ||
|
||
setTimeout(fetchDataFromGithub, 2000); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |