$ = jQuery
context = window
logger = context.JK.logger
RecordingActions = @RecordingActions
SessionActions = @SessionActions
JamBlasterActions = @JamBlasterActions
VideoLiveStreamActions = @VideoLiveStreamActions

#window.StupidCallback: () =>
#  alert("STUPID CALLBACK")

@CallbackStore = Reflux.createStore(
  {
    init: () ->
      # Register with the app store to get @app
      this.listenTo(context.AppStore, this.onAppInit)

    onAppInit: (@app) ->
      if context.jamClient.RegisterGenericCallBack?
        console.log("REGISTERING GENERIC CALLBACK")
        context.jamClient.RegisterGenericCallBack('CallbackStore.onGenericCallback')
        #context.jamClient.RegisterGenericCallBack('StupidCallback')

    onGenericCallback: (map) ->
      console.log("GENERIC CALLBACK CALLED: ", map)
      if map.cmd == 'join_session'
        SessionActions.joinSession(map['music_session_id'])
      else if map.cmd == 'start_livestream'
        VideoLiveStreamActions.startLiveStream()
      else if map.cmd == 'client_pair_state'
        JamBlasterActions.pairState(map)
      else if map.cmd == 'jamblaster_tracks_updated'
        JamBlasterActions.jamblasterTracksUpdated()
      else if map.cmd == 'file_xfer_from_parent'
        if map.filename && map.filename.indexOf('RT-mix.wav') > -1
          RecordingActions.mixTransferred()
  }
)
