Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added soundcloud auth, like button, node server #2

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
74c4798
Added soundcloud auth, like button, nodejs server
Sep 5, 2015
602a1e5
Made the server.js file work for deployment
jmbeach Sep 10, 2015
bcaab7a
Modified package.json for deploy
jmbeach Sep 10, 2015
bcab88d
done
jmbeach Sep 10, 2015
202c51f
working on package.json
jmbeach Sep 10, 2015
6881070
Working on package.js
jmbeach Sep 10, 2015
3073f8b
Adding grunt build to postinstall
jmbeach Sep 10, 2015
3346636
Fixing package.json
jmbeach Sep 10, 2015
396286b
working on package.json
jmbeach Sep 10, 2015
e1c143a
eiting package.json
jmbeach Sep 10, 2015
aa6732b
working on package.json
jmbeach Sep 10, 2015
a0dcd2e
grunt bs
jmbeach Sep 10, 2015
1c467e6
grunt asasdf
jmbeach Sep 10, 2015
8a77aed
need config file on server
jmbeach Sep 10, 2015
5cc819a
Added readme and a link to demo heroku app
jmbeach Sep 10, 2015
2bc4e42
Fixed callback for deployed version
jmbeach Sep 10, 2015
0ce9cf6
bla herokuy
jmbeach Sep 10, 2015
5c8dd40
callback
jmbeach Sep 10, 2015
4d5d5ba
callback
jmbeach Sep 10, 2015
e08d7a1
gah the callback
jmbeach Sep 10, 2015
406e303
Delete default.json
jmbeach Sep 10, 2015
eb92423
deploy
jmbeach Sep 10, 2015
292c35a
html5 bb
Sep 10, 2015
2cfc94e
Merge branch 'master' of github.com:jmbeach/soundcloud-radio
jmbeach Sep 10, 2015
80d2e0e
config
jmbeach Sep 10, 2015
a506987
cross domain
jmbeach Sep 11, 2015
0a25d8e
bla
Sep 11, 2015
af584bc
Merge branch 'master' of github.com:jmbeach/soundcloud-radio
jmbeach Sep 11, 2015
e8abd79
Cleaned up serverw
jmbeach Sep 11, 2015
6476e6c
Merge branch 'deploy'
jmbeach Sep 11, 2015
bbf7eac
Cleaned up server
jmbeach Sep 11, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
.tmp
.sass-cache
bower_components
config/default.json
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#SoundCloud Radio

##About
A node.js/angular web application for streaming music from SoundCloud profiles in a radio-style format and (eventually) for recommending artists and songs similar to the ones you listen to.

##Demo
<a href="http://robotradio.herokuapp.com/">http://robotradio.herokuapp.com/</a>
143 changes: 143 additions & 0 deletions User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//#region MODULES
var bycript = require('bcrypt-nodejs'),
mysql = require('mysql');
//#endregion

//#region CCONSTANTS
var strParamId = 'id',
strParamClient = 'client',
strParamSecret = 'secret',
strParamRegistered = 'registered',
strParamIsGeneric = 'isGeneric';
//#endregion
//#region MODULES_CONFIG
// config mysql
//var connection = mysql.createConnection({
// host: 'localhost',
// user: 'root',
// database: 'tumblrdashslides_main'
// // password : 'root',
//});
//connection.connect();
//#endregion


//function User(id, client, secret, registered,isGeneric,blogname) {
// this.id = id;
// this.client = client;
// this.secret = secret;
// this.registered = registered != null && registered;
// this.isGeneric = isGeneric;
// this.blogName = blogName;
//}
function User(params) {
this.id = params[strParamId];
this.client = params[strParamClient];
this.secret = params[strParamSecret];
this.registered = params[strParamRegistered];
this.isGeneric = params[strParamIsGeneric];
}

User.findOrCreate = function (options, callback) {
switch (options['method']) {
case 'soundcloud':
var options = {
id: options['soundCloudId'],
client: options['soundCloudToken'],
secret: options['soundCloudSecret'],
isGeneric: false
};
var user = new User(options);
callback(null, user);
break;
case 'tumblr':
var options = {
id: options['tumblrId'],
client: options['tumblrToken'],
secret: options['tumblrSecret'],
isGeneric: false
};
var user = new User(options);
callback(null, user);
break;
}
};

User.find = function (options, callback) {
switch (options['method']) {
case 'local':
var username = options['username'],
password = options['password'];
connection.query("SELECT * FROM `users` WHERE Id = '" + username + "'", function (err, rows, fields) {
if (err) callback(err);
console.log("find user results", rows);
if (rows.length > 0) {
console.log("local user found");
console.log("checking password");
var row = rows[0];
(new User(username)).validPassword(password, function (errPass, res) {
if (errPass) callback(errPass);
if (res) {
var user = new User(
row.Id,
row.clientkey,
row.clientsecret);
callback(null, user);
} else {
// valid user, invalid password.
var user = new User(row.Id);
callback(null, user);
}
});
}
else {
// no user exists
callback(null, null);
}
});
break;
}
}

User.create = function (options, callback) {
switch (options['method']) {
case 'local':
var username = options['username'],
password = options['password'],
token = options['tumblrToken'],
secret = options['tumblrSecret'];
// if tumblr-id present, create a new user
bycript.hash(password, null, null, function (errHash, hash) {
if (errHash) callback(errHash);
console.log("user not found. Creating one.");
var sql = "INSERT INTO `users`(`Id`, `password`,`clientkey`,`clientsecret`) VALUES ('" + username + "','" + hash + "','" + token + "','" + secret + "')";
connection.query(sql, function (updateerr, updaterows, updatefields) {
if (updateerr) callback(updateerr);
var createdUser = new User(username, token, secret);
callback(null, createdUser);
});
});
break;
}
}

User.prototype.validPassword = function (password, callback) {
if (this.id == null) return false;
validPassword(this.id, password, function (err, res) {
if (err) callback(err);
// res is bool
callback(null, res);
});
};
function validPassword(id, password, callback) {
var sql = "SELECT * FROM `users` WHERE Id = '" + id + "'";
connection.query(sql, function (err, rows, fields) {
var hash = rows[0].password;
bycript.compare(password, hash, function (errHash, res) {
if (errHash) callback(errHash);
// res is bool
callback(null, res);
});
});
}
module.exports = User;
12 changes: 9 additions & 3 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
Expand All @@ -17,14 +17,14 @@
<link rel="stylesheet" href="styles/font-awesome.min.css">
<link href='http://fonts.googleapis.com/css?family=Montserrat|Lato:100,400,700,400italic,700italic' rel='stylesheet' type='text/css'>
</head>
<body ng-app="scradioApp">
<body ng-app="scradioApp" style="margin 0px auto">
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->

<!-- Add your site or application content here -->

<div ng-view=""></div>
<div ui-view="master"></div>


<!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
Expand All @@ -48,6 +48,9 @@
<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/threejs/build/three.js"></script>
<script src="bower_components/tweenjs/build/tween.min.js"></script>
<script src="bower_components/threex.windowresize/threex.windowresize.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/json3/lib/json3.js"></script>
<script src="bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/affix.js"></script>
Expand All @@ -66,6 +69,7 @@
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="bower_components/angular-touch/angular-touch.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/lodash/dist/lodash.compat.js"></script>
Expand All @@ -79,6 +83,8 @@
<script src="scripts/radio/directives.js"></script>
<script src="scripts/radio/directive.player.js"></script>
<script src="scripts/radio/stations.js"></script>
<script src="scripts/animations/TrackViewer.js"></script>
<script src="scripts/radio/track.js"></script>
<!-- endbuild -->
</body>
</html>
107 changes: 107 additions & 0 deletions app/scripts/animations/TrackViewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
function TrackViewer(options) {
//options:
// canvasHolder - string - selector for element which will contain
// the track viewer.
var canvasHolderSelector = options.canvasHolder;
var camera, scene, renderer;
var geometry, material, mesh;
var mouse = new THREE.Vector2();
var W;
var H, $w,
frame = 0;

this.Camera = function () {
return camera;
}
var isCenteringTrack = false;
var trackToCenter = null;

this.AddToScene = function(object) {
scene.add(object);
}
this.Tracks = [];

function onMouseMove( event ) {

// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
camera.rotation.y = mouse.x/2
}
function setup() {
W = window.innerWidth;
H = 500;
$w = $(window);
renderer = new THREE.WebGLRenderer({});
renderer.setSize(W, H);
renderer.setClearColor(0x000000);
$canvasHolder = $(canvasHolderSelector);
$canvasHolder.append(renderer.domElement);
camera = new THREE.PerspectiveCamera(50, W / H, 1, 10000);
camera.position.z = 200;
scene = new THREE.Scene();
renderer.domElement.addEventListener( 'mousemove', onMouseMove, false );
renderer.domElement.addEventListener( 'mouseleave', function() {
var tween = new TWEEN.Tween(camera.rotation).to({
y: 0,
x:0,
z:0
}).start();
}, false );
}

function draw(time) {
requestAnimationFrame(draw);
// update code goes here
TWEEN.update(time);
renderer.render(scene, camera);
}

$(function() {
setup();
draw();
})

function isMobile() {
return navigator.userAgent.match(/Mobi/);
}
}
TrackViewer.prototype.AddTrack = function(trackData) {
THREE.ImageUtils.crossOrigin = '';
var id = trackData.id;
if (this.FindTrack(id)) return;
var texture = THREE.ImageUtils.loadTexture(trackData.img);
var material = new THREE.MeshBasicMaterial({
map:texture
});
var plane = new THREE.Mesh(new THREE.PlaneGeometry(200,200), material );
if (this.Tracks.length >0) {
var previousTrack = this.Tracks[this.Tracks.length-1];
plane.position.x =previousTrack.art.position.x+200;
}
this.Tracks.push(new Track({art:plane,id:id}));
this.AddToScene(plane);
// this.AddToScene(imageObj);
}
TrackViewer.prototype.CenterTrack = function(trackId) {
var track = this.FindTrack(trackId);
if (track) {
var tween = new TWEEN.Tween(this.Camera().position).to({
x:track.art.position.x,
y:this.Camera().position.y,
z:this.Camera().position.z
});
tween.start();
}
}
TrackViewer.prototype.FindTrack = function(trackId) {
for (var i =0; i <this.Tracks.length;i++) {
var track = this.Tracks[i];
if (track.id == trackId) {
return track;
}
}
return null;
}
28 changes: 18 additions & 10 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ angular
'ngCookies',
'ngResource',
'ngRoute',
'ui.router',
'ngSanitize',
'ngTouch',
])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'RadioCtrl'
})
.otherwise({
redirectTo: '/'
});
});
.config([ '$routeProvider', '$locationProvider', '$stateProvider',
function ($routeProvider, $locationProvider, $stateProvider) {
$locationProvider.html5Mode({
enabled: true
});
$stateProvider
.state('default', {
url: "/",
views: {
"master": {
templateUrl: '/views/main.html',
controller: 'RadioCtrl',
controllerAs: 'RadioCtrl'
}
}
});
}]);
Loading