diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 7b4e5dab7..c6460ed27 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -1498,13 +1498,20 @@ function openBackingTrack(options) { var musicSessionId = options["id"]; delete options["id"]; - - return $.ajax({ - type: "POST", - dataType: "json", - contentType: 'application/json', - url: "/api/sessions/" + musicSessionId + "/backing_tracks/open", - data: JSON.stringify(options) + return new Promise(function(resolve, reject){ + $.ajax({ + type: "POST", + dataType: "json", + contentType: 'application/json', + url: "/api/sessions/" + musicSessionId + "/backing_tracks/open", + data: JSON.stringify(options) + }) + .done(function(resp){ + resolve(resp); + }) + .fail(function(xhr){ + reject(xhr) + }) }) } @@ -1653,13 +1660,20 @@ function closeMetronome(options) { var musicSessionId = options["id"]; delete options["id"]; - - return $.ajax({ - type: "POST", - dataType: "json", - contentType: 'application/json', - url: "/api/sessions/" + musicSessionId + "/metronome/close", - data: JSON.stringify(options) + return new Promise((resolve, reject) => { + $.ajax({ + type: "POST", + dataType: "json", + contentType: 'application/json', + url: "/api/sessions/" + musicSessionId + "/metronome/close", + data: JSON.stringify(options) + }) + .done((resp) => { + resolve(resp) + }) + .fail(jqXHR => { + reject(jqXHR); + }) }) } diff --git a/web/app/assets/javascripts/react-components/SessionMediaTracks.js.jsx.coffee b/web/app/assets/javascripts/react-components/SessionMediaTracks.js.jsx.coffee index ca7b1b58d..bad21aed4 100644 --- a/web/app/assets/javascripts/react-components/SessionMediaTracks.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/SessionMediaTracks.js.jsx.coffee @@ -466,6 +466,7 @@ ChannelGroupIds = context.JK.ChannelGroupIds unless @childWindow? logger.debug("opening media control window") @childWindow = window.open("/popups/media-controls", 'Media Controls', 'scrollbars=yes,toolbar=no,status=no,height=155,width=350') + console.log('childWindow', @childWindow) @childWindow.PopupProps = {media: @state, jamTrackState: context.JamTrackStore.getState(), downloadingJamTrack: context.SessionStore.downloadingJamTrack, windowUnloaded: @windowUnloaded } if !@state.popupOpen setTimeout(() => diff --git a/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee b/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee index eba538bbf..30edc5737 100644 --- a/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee @@ -300,19 +300,36 @@ ConfigureTracksActions = @ConfigureTracksActions logger.debug("SessionStore: OnLog", detail) # codeInitiated means the user did not initiate this - onCloseMedia: (codeInitiated) -> + # onCloseMedia: (codeInitiated) -> - logger.debug("SessionStore: onCloseMedia", codeInitiated) - if @helper.recordedTracks() - @closeRecording() - else if @helper.jamTracks() || @downloadingJamTrack - @closeJamTrack() - else if @helper.backingTrack() && @helper.backingTrack().path - @closeBackingTrack() - else if @helper.isMetronomeOpen() - @closeMetronomeTrack() - else - logger.error("don't know how to close open media", @helper) unless codeInitiated + # logger.debug("SessionStore: onCloseMedia", codeInitiated) + # if @helper.recordedTracks() + # @closeRecording() + # else if @helper.jamTracks() || @downloadingJamTrack + # @closeJamTrack() + # else if @helper.backingTrack() && @helper.backingTrack().path + # @closeBackingTrack() + # else if @helper.isMetronomeOpen() + # @closeMetronomeTrack() + # else + # logger.error("don't know how to close open media", @helper) unless codeInitiated + + + onCloseMedia: `async function(codeInitiated) { + + logger.debug("SessionStore: onCloseMedia", codeInitiated); + if (this.helper.recordedTracks()) { + this.closeRecording(); + } else if (this.helper.jamTracks() || this.downloadingJamTrack) { + this.closeJamTrack(); + } else if (this.helper.backingTrack() && this.helper.backingTrack().path) { + this.closeBackingTrack(); + } else if (this.helper.isMetronomeOpen()) { + await this.closeMetronomeTrack(); + } else { + if (!codeInitiated) { return logger.error("don't know how to close open media", this.helper); } + } + }` # closeJamTrack: () -> # logger.debug("closing jam track"); @@ -402,7 +419,8 @@ ConfigureTracksActions = @ConfigureTracksActions # @app.notifyServerError(jqXHR, "Unable to Open Backing Track For Playback"); # ) - onOpenBackingTrack: `function(result) { + onOpenBackingTrack: `async function(result) { + console.log('onOpenBackingTrack', result) if (!this.inSession()) { logger.debug("ignoring backing track selected callback (not in session)"); return; @@ -411,26 +429,24 @@ ConfigureTracksActions = @ConfigureTracksActions if (result.success) { logger.debug("backing track selected: " + result.file); - return rest.openBackingTrack({id: this.currentSessionId, backing_track_path: result.file}) - .done(async () => { - + try{ + await rest.openBackingTrack({id: this.currentSessionId, backing_track_path: result.file}); const openResult = await context.jamClient.SessionOpenBackingTrackFile(result.file, false); - + console.log('openResult', openResult) if (openResult) { // storing session state in memory, not in response of Session server response. bad. - return this.openBackingTrack = result.file; + this.openBackingTrack = result.file; } else { this.app.notify({ "title": "Couldn't Open Backing Track", "text": "Is the file a valid audio file?", "icon_url": "/assets/content/icon_alert_big.png" }); - return this.closeBackingTrack(); + this.closeBackingTrack(); } - }) - .fail(jqXHR => { - return this.app.notifyServerError(jqXHR, "Unable to Open Backing Track For Playback"); - }); + }catch(jqXHR){ + this.app.notifyServerError(jqXHR, "Unable to Open Backing Track For Playback"); + } } }` @@ -488,20 +504,19 @@ ConfigureTracksActions = @ConfigureTracksActions # }) # ) - closeMetronomeTrack: `function() { + closeMetronomeTrack: `async function() { logger.debug("SessionStore: closeMetronomeTrack"); - return rest.closeMetronome({id: this.currentSessionId}) - .done(async() => { + try{ + await rest.closeMetronome({id: this.currentSessionId}) await context.jamClient.SessionCloseMetronome(); this.refreshCurrentSession(true); - }) - .fail(jqXHR => { - return this.app.notify({ + }catch(jqXHR){ + this.app.notify({ "title": "Couldn't Close MetronomeTrack", "text": "Couldn't inform the server to close MetronomeTrack. msg=" + jqXHR.responseText, "icon_url": "/assets/content/icon_alert_big.png" }); - }); + } }` # closeBackingTrack: () -> @@ -1436,10 +1451,14 @@ ConfigureTracksActions = @ConfigureTracksActions # SessionStatsActions.pushStats(connectionStats, parentConnectionStats) updateBackendStats: `async function() { + //const clientId = await context.jamClient.clientID(); + //const parentClientId = await context.jamClient.getParentClientId(); + const clientId = context.JK.app.clientId + const connectionStats = await window.jamClient.getConnectionDetail('', false); const parentConnectionStats = await window.jamClient.getConnectionDetail('', true); - //console.log("CONNECTION STATES", connectionStats) - //console.log("PARENT STATES", parentConnectionStats) + console.log("CONNECTION STATES", connectionStats) + console.log("PARENT STATES", parentConnectionStats) SessionStatsActions.pushStats(connectionStats, parentConnectionStats); }` diff --git a/web/app/assets/javascripts/react-components/stores/SessionsStore.js.coffee b/web/app/assets/javascripts/react-components/stores/SessionsStore.js.coffee index d43389f4b..757fb8b89 100644 --- a/web/app/assets/javascripts/react-components/stores/SessionsStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/SessionsStore.js.coffee @@ -47,7 +47,7 @@ SessionActions = @SessionActions foundIndex = -1 - console.log("STATE", state) + #console.log("STATE", state) if state.sessions.length > 0 for x in [0..state.sessions.length - 1] if state.sessions[x].id == session.id diff --git a/web/app/assets/javascripts/session.js b/web/app/assets/javascripts/session.js index 5a749b0c1..661a7d534 100644 --- a/web/app/assets/javascripts/session.js +++ b/web/app/assets/javascripts/session.js @@ -2667,7 +2667,7 @@ } async function openBackingTrack(e) { - + alert('session.openBackingTrack') if($openBackingTrack.is('.disabled')) { logger.debug("backing track dialog already open") return false;