This commit is contained in:
Seth Call 2015-01-09 16:11:04 -06:00
parent 0ab7686205
commit 5ac69fc646
5 changed files with 76 additions and 6 deletions

View File

@ -2,10 +2,53 @@ $ = jQuery
context = window
context.JK ||= {};
context.JK.DownloadJamTrack = class SyncViewer
# There are different states that a JamTrack can be in.
# The final success state is that the JamTrack is on disk and loadable. (show synchronized state)
# But there are others until you get there:
# The JamTrack does not exist on the server, so we will create it (packaging state)
# The JamTrack exists on the server, but not on disk, so we will download it (downloading state)
# The JamTrack is on the disk, but does not yet have keys, so we will fetch them (keying)
context.JK.DownloadJamTrack = class DownloadJamTrack
constructor: (@app) ->
@EVENTS = context.JK.EVENTS
@rest = context.JK.Rest()
@jamTrackId = null
@states = {
synchronized: 'synchronized',
packaging: 'packaging',
downloading: 'downloading',
keying: 'keying',
initial: 'initial'
}
@state = @states.initial
init: () =>
init: (jamTrackId) =>
@jamTrackId = jamTrackId
@root = $($('#template-download-jamtrack').html())
# after you've created the DownloadJamTrack widget, call synchronize which will begin ensuring that the jamtrack
# is downloaded and ready to open
synchronize: () =>
this.checkState()
transition: (newState) =>
checkState: () =>
isPlayable = context.jamClient.JamTrackIsPlayable()
if isPlayable
this.transition(@states.synchronized)
else
@rest.getJamTrackRight({id: @jamTrackId})
.done(this.processJamTrackRight)
.fail(@app.ajaxError)
processJamTrackRight: (myJamTrack) =>
if response.signing_state

View File

@ -679,6 +679,9 @@
function TrackSetInstrument(track, instrumentId) {}
function JamTrackIsPlayable() {
return true;
}
// Method which sets volume
function UpdateMixer(mixerId) {}
@ -973,6 +976,8 @@
this.TrackGetChatUsesMusic = TrackGetChatUsesMusic;
this.TrackSetChatUsesMusic = TrackSetChatUsesMusic;
this.JamTrackIsPlayable = JamTrackIsPlayable;
// Scoring Knobs
this.GetScoreWorkTimingInterval = GetScoreWorkTimingInterval;
this.SetScoreWorkTimingInterval = SetScoreWorkTimingInterval;

View File

@ -1347,6 +1347,28 @@
});
}
function getJamTrackRight(options) {
var jamTrackId = options['id'];
return $.ajax({
type: "GET",
url: '/api/jamtracks/rights' + jamTrackId + '?' + $.param(options),
dataType: "json",
contentType: 'application/json'
})
}
function enqueueJamTrack(options) {
var jamTrackId = options['id'];
return $.ajax({
type: "POST",
url: '/api/jamtracks/enqueue?' + jamTrackId + '?' + $.param(options),
dataType: "json",
contentType: 'applications/json'
});
}
function getPurchasedJamTracks(options) {
return $.ajax({
type: "GET",
@ -1583,6 +1605,7 @@
this.updateAudioLatency = updateAudioLatency;
this.getJamtracks = getJamtracks;
this.getPurchasedJamTracks = getPurchasedJamTracks;
this.getJamTrackRight = getJamTrackRight;
this.addJamtrackToShoppingCart = addJamtrackToShoppingCart;
this.getShoppingCarts = getShoppingCarts;
this.removeShoppingCart = removeShoppingCart;

View File

@ -197,7 +197,7 @@ SampleApp::Application.routes.draw do
match '/jamtracks/downloads' => 'api_jam_tracks#downloads', :via => :get, :as => 'api_jam_tracks_downloads'
match '/jamtracks/download/:id' => 'api_jam_tracks#download', :via => :get, :as => 'api_jam_tracks_download'
match '/jamtracks/enqueue/:id' => 'api_jam_tracks#enqueue', :via => :post, :as => 'api_jam_tracks_enqueue'
match '/jamtracks/show/:id' => 'api_jam_tracks#show_jam_track_right', :via => :get, :as => 'api_jam_tracks_show_right'
match '/jamtracks/rights/:id' => 'api_jam_tracks#show_jam_track_right', :via => :get, :as => 'api_jam_tracks_show_right'
match '/jamtracks/keys' => 'api_jam_tracks#keys', :via => :post, :as => 'api_jam_tracks_keys'
# Shopping carts

View File

@ -1,7 +1,7 @@
describe "DownloadJamTrack", ->
beforeEach ->
this.fixtures = fixture.load("downoadJamTrack.html", "user_sync_track1.json"); # append these fixtures which were already cached
this.fixtures = fixture.load("downoadJamTrack.html"); # append these fixtures which were already cached
this.server = sinon.fakeServer.create();
window.jamClient = sinon.stub()
this.downloadJamTrack = new JK.DownloadJamTrack()
@ -12,5 +12,4 @@ describe "DownloadJamTrack", ->
this.server.restore();
it "display state correctly", ->
$track = this.syncViewer.createTrack(this.track1)
this.syncViewer.updateTrackState($track)
//$track = this.downloadJamTrack.createTrack()