Skip to content

Commit

Permalink
removed some unneccesary code that was commented out in js assets; cl…
Browse files Browse the repository at this point in the history
…arified some comments about recorder; obfuscated the api keys by setting them to env vars that are passed to the javascript files as global vars on window.
  • Loading branch information
brittlewis12 committed Nov 30, 2013
1 parent acaf48f commit dc4dcbe
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 52 deletions.
14 changes: 0 additions & 14 deletions app/assets/javascripts/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,4 @@ $(function(){
$("#about-link").click(function(){
$("#about").slideDown("slow");
});

// // smooth scrolling
// $('a[href*=#]:not([href=#])').click(function() {
// if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
// var target = $(this.hash);
// target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
// if (target.length) {
// $('html,body').animate({
// scrollTop: target.offset().top
// }, 1000);
// return false;
// }
// }
// });
});
2 changes: 1 addition & 1 deletion app/assets/javascripts/buffer_animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ window.onload = function() {
    if (val < 99){
      setTimeout( songProgress, (1000/9) );
    }
}
}
13 changes: 4 additions & 9 deletions app/assets/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@ function saveAudio() {
audioRecorder.exportWAV( doneEncoding );
}

// Matt Diamond function for play audio, which actually will do a force download.
// function playAudio() {
// audioRecorder.exportWAV( doneRecording );
// }

// Interacting with our DOM. Makes filename for track by taking in songName and userName and track number. Then calls
// passToUploader function and connects the blob to the filename.
// Interacting with the DOM. Creates a filename for track by taking in songName and userName and track number. Then calls
// uploadToS3 function and connects the blob to the filename.
function doneEncoding(blob) {
var songName = $(".song-name").html();
var numTracks = $(".song-name").attr("data-tracks");
if ((numTracks + 1) < 10) {
if ( (Number(numTracks) + 1) < 10 ) {
var trackNum = "0" + (Number(numTracks) + 1);
} else {
trackNum = (Number(numTracks) + 1);
}
var username = $(".song-name").attr("data-user");
var songId = $(".song-name").attr("data-song-id");
Recorder.passToUploader(blob, (songName + "/" + trackNum + username + ".wav"), songId);
Recorder.uploadToS3(blob, (songName + "/" + trackNum + username + ".wav"), songId);
}

// Click on/off for Record button. Starts and stops recording action. Saves on stop. Clears and records on start.
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ function finishedLoading(bufferList) {
};
}

// Goes through DOM and sees if checkbox input is checked or not. If checked, it adds track url to bufferList.
// If track is unchecked, it isn't added to bufferList. If track is unchecked, but is in bufferList from previous play,
// Goes through DOM and determines if each track is checked or not. If checked, it adds track url to bufferList.
// If track is unchecked, it is skipped. If track is unchecked, but is in bufferList from previous play,
// it is taken out of the bufferList.
function checkWhichTracksToPlay() {
$.each($('input'),function(index, value) {
Expand Down
37 changes: 13 additions & 24 deletions app/assets/javascripts/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,39 +80,39 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}

source.connect(this.node);
this.node.connect(this.context.destination); //this should not be necessary
this.node.connect(this.context.destination);
};

// beatcove created function. This takes place of force download. It takes a blob, sets it to our AWS key, and sends to S3.
Recorder.passToUploader = function(blob, filepath, songId) {
// this function instantiates a connection to our S3 bucket,
// takes the blob and filename, and sends it to S3.
Recorder.uploadToS3 = function(blob, filepath, songId) {
var blob = blob;
AWS.config.update({accessKeyId: "AKIAIWQL5BA6V37OGUQQ", secretAccessKey: "***REMOVED***"});
AWS.config.update({accessKeyId: _awsAccessId, secretAccessKey: _awsSecretKey});
AWS.config.region = "us-west-2";

// constructor function creates S3 connection object
var beatcove = new AWS.S3({ params: {Bucket: 'beatcove'}});
// instantiates an S3 connection to our beatcove bucket
var beatcove = new AWS.S3({ params: {Bucket: "beatcove"}});

// public-read unauthenticated viewers access to read/download content.
// This allows anyone to listen to our wav files without making changes.
// sets the permissions of the file to be public but read-only, so anyone can listen to tracks.
var params = {ACL: "public-read", Key: filepath, ContentType: blob.type, Body: blob};

// putObject is a method from AWS javascript SDK that puts our object (beatcove) into the S3 bucket.
// AWS JavaScript SDK method that sends the audio file to our beatcove S3 bucket
beatcove.putObject(params, function(error, data) {
// response from AMAZON
// callbacks based on response from AWS
if (error) {
alert("Something went wrong, and we weren't able to save your track. Please try again.");
} else {
console.log("about to try to do some ajax trickery!!");
// persist in DATABASE (not on S3)
// persist the track info to our server's PostgreSQL database (not S3)
$.ajax({
url: "/songs/" + songId + "/tracks/",
type: "POST",
data: {track: {name: filepath, url:"https://beatcove.s3-us-west-2.amazonaws.com/" + filepath}},
dataType: "json",
// response from DATABASE
// server response error callback function
error: function() {
alert("record was so bad, it could not persist in our DB");
},
// server response success callback function
success: function(data){
console.log(data);
window.location.replace("/songs/"+ songId);
Expand All @@ -122,17 +122,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
});
}

// Matt Diamond Code that is called on save. Forces user to download file. We replaced this with the passToUploader function.
// Recorder.forceDownload = function(blob, filename){
// var url = (window.URL || window.webkitURL).createObjectURL(blob);
// var link = window.document.createElement('a');
// link.href = url;
// link.download = filename || 'output.wav';
// var click = document.createEvent("Event");
// click.initEvent("click", true, true);
// link.dispatchEvent(click);
// }

window.Recorder = Recorder;

} )(window);
8 changes: 6 additions & 2 deletions app/views/tracks/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= javascript_tag do %>
window._awsSecretKey = "<%= ENV['AWS_SECRET_ACCESS_KEY'] %>"
window._awsAccessId = "<%= ENV['AWS_ACCESS_KEY_ID'] %>"
<% end %>
<%= javascript_include_tag :record_assets %>

<div class="song-home">
<div class="recorder">
<div class="center">
Expand All @@ -15,4 +19,4 @@
</div>
</div>
</div>
</div>
</div>

0 comments on commit dc4dcbe

Please sign in to comment.