$ = jQuery context = window logger = context.JK.logger PLAYBACK_MONITOR_MODE = context.JK.PLAYBACK_MONITOR_MODE RecordingActions = @RecordingActions @MediaPlaybackStore = Reflux.createStore( { listenables: @MediaPlaybackActions playbackStateChanged: false positionUpdateChanged: false currentTimeChanged: false playbackState: null positionMs: 0 durationMs: 0 isRecording: false sessionHelper: null init: () -> this.listenTo(context.SessionStore, this.onSessionChanged); onCurrentTimeChanged: (time) -> @time = time @currentTimeChanged = true @issueChange() onSessionChanged: (session) -> @isRecording = session.isRecording @sessionHelper = session # onMediaStartPlay: (data) -> # logger.debug("calling jamClient.SessionStartPlay"); # context.jamClient.SessionStartPlay(data.playbackMode); onMediaStartPlay: `async function(data) { logger.debug("calling jamClient.SessionStartPlay ......"); await context.jamClient.SessionStartPlay(data.playbackMode); }` # onMediaStopPlay: (data) -> # # if a JamTrack is open, and the user hits 'pause' or 'stop', we need to automatically stop the recording # if @sessionHelper.jamTracks() && @isRecording # logger.debug("preemptive jamtrack stop") # @startStopRecording(); # if !data.endReached # logger.debug("calling jamClient.SessionStopPlay. endReached:", data.endReached) # context.jamClient.SessionStopPlay() onMediaStopPlay: `async function(data) { // if a JamTrack is open, and the user hits 'pause' or 'stop', we need to automatically stop the recording if (this.sessionHelper.jamTracks() && this.isRecording) { logger.debug("preemptive jamtrack stop"); this.startStopRecording(); } if (!data.endReached) { logger.debug("calling jamClient.SessionStopPlay. endReached:", data.endReached); await context.jamClient.SessionStopPlay(); } }` # onMediaPausePlay: (data) -> # # if a JamTrack is open, and the user hits 'pause' or 'stop', we need to automatically stop the recording # if @sessionHelper.jamTracks() && @isRecording # logger.debug("preemptive jamtrack stop") # @startStopRecording(); # if !data.endReached # logger.debug("calling jamClient.SessionPausePlay. endReached:", data.endReached) # context.jamClient.SessionPausePlay() onMediaPausePlay: `async function(data) { // if a JamTrack is open, and the user hits 'pause' or 'stop', we need to automatically stop the recording if (this.sessionHelper.jamTracks() && this.isRecording) { logger.debug("preemptive jamtrack stop"); this.startStopRecording(); } if (!data.endReached) { logger.debug("calling jamClient.SessionPausePlay. endReached:", data.endReached); await context.jamClient.SessionPausePlay(); } }` startStopRecording: () -> if @isRecording RecordingActions.stopRecording.trigger() else RecordingActions.startRecording.trigger() # onMediaChangePosition: (data) -> # seek = data.positionMs; # if data.playbackMonitorMode == PLAYBACK_MONITOR_MODE.JAMTRACK # # if positionMs == 0, then seek it back to whatever the earliest play start is to catch all the prelude # if(seek == 0) # duration = context.jamClient.SessionGetJamTracksPlayDurationMs(); # seek = duration.start; # logger.debug("calling jamClient.SessionTrackSeekMs(" + seek + ")"); # if data.playbackMonitorMode == PLAYBACK_MONITOR_MODE.JAMTRACK # context.jamClient.SessionJamTrackSeekMs(seek); # else # context.jamClient.SessionTrackSeekMs(seek); onMediaChangePosition: `async function(data) { let seek = data.positionMs; if (data.playbackMonitorMode === PLAYBACK_MONITOR_MODE.JAMTRACK) { // if positionMs == 0, then seek it back to whatever the earliest play start is to catch all the prelude if(seek === 0) { const duration = await context.jamClient.SessionGetJamTracksPlayDurationMs(); seek = duration.start; } } logger.debug("calling jamClient.SessionTrackSeekMs(" + seek + ")"); if (data.playbackMonitorMode === PLAYBACK_MONITOR_MODE.JAMTRACK) { await context.jamClient.SessionJamTrackSeekMs(seek); } else { await context.jamClient.SessionTrackSeekMs(seek); } }` issueChange: () -> @state = playbackState: @playbackState playbackStateChanged: @playbackStateChanged positionUpdateChanged: @positionUpdateChanged currentTimeChanged: @currentTimeChanged positionMs: @positionMs durationMs: @durationMs isPlaying: @isPlaying time: @time this.trigger(@state) @playbackStateChanged = false @positionUpdateChanged = false @currentTimeChanged = false onPlaybackStateChange: (text) -> @playbackState = text @playbackStateChanged = true @issueChange() # onPositionUpdate: (playbackMode) -> # if playbackMode == PLAYBACK_MONITOR_MODE.JAMTRACK # @positionMs = context.jamClient.SessionCurrrentJamTrackPlayPosMs() # duration = context.jamClient.SessionGetJamTracksPlayDurationMs() # @durationMs = duration.media_len # else # @positionMs = context.jamClient.SessionCurrrentPlayPosMs() # @durationMs = context.jamClient.SessionGetTracksPlayDurationMs() # @isPlaying = context.jamClient.isSessionTrackPlaying() # @positionUpdateChanged = true # @issueChange() onPositionUpdate: `async function(playbackMode) { if (playbackMode === PLAYBACK_MONITOR_MODE.JAMTRACK) { this.positionMs = await context.jamClient.SessionCurrrentJamTrackPlayPosMs(); const duration = await context.jamClient.SessionGetJamTracksPlayDurationMs(); this.durationMs = duration.media_len; } else { this.positionMs = await context.jamClient.SessionCurrrentPlayPosMs(); this.durationMs = await context.jamClient.SessionGetTracksPlayDurationMs(); } this.isPlaying = await context.jamClient.isSessionTrackPlaying(); this.positionUpdateChanged = true; return this.issueChange(); }` } )