import api from './api' ; import featureFlags from './feature-flags' ; import { getDateString } from './utils' ; export const enum Events { APP_LOAD = 'APP_LOAD' , DRAW_NOTE = 'DRAW_NOTE' , DELETE_NOTE = 'DELETE_NOTE' , DELETE_MASKED_NOTES = 'DELETE_MASKED_NOTES' , MOVE_NOTE = 'MOVE_NOTE' , PLAY = 'PLAY' , STOP = 'STOP' , UNDO = 'UNDO' , REDO = 'REDO' , SELECT_TOOL = 'SELECT_TOOL' , SELECT_VOICE = 'SELECT_VOICE' , SELECT_QUANTIZATION = 'SELECT_QUANTIZATION' , SELECT_KEY = 'SELECT_KEY' , SELECT_MODE = 'SELECT_MODE' , SET_CONSTRAIN_TO_KEY = 'SET_CONSTRAIN_TO_KEY' , USE_MASK_TOOL = 'USE_MASK_TOOL' , USE_MASK_LANE = 'USE_MASK_LANE' , MUTE_VOICE = 'MUTE_VOICE' , UNMUTE_VOICE = 'UNMUTE_VOICE' , CHANGE_LOOP = 'CHANGE_LOOP' , PRESS_PIANOROLL = 'PRESS_PIANOROLL' , START_GENERATE = 'START_GENERATE' , GENERATE = 'GENERATE' , SET_N_SAMPLES_TO_GENERATE = 'SET_N_SAMPLES_TO_GENERATE' , SET_CONVENTIONAL_SURPRISING = 'SET_CONVENTIONAL_SURPRISING' , SET_MAJOR_MINOR = 'SET_MAJOR_MINOR' , SET_SIMILAR_DIFFERENT = 'SET_SIMILAR_DIFFERENT' , SELECT_CANDIDATE_SEQUENCE = 'SELECT_CANDIDATE_SEQUENCE' , CLEAR_CANDIDATE_SEQUENCES = 'CLEAR_CANDIDATE_SEQUENCES' , CHOOSE_CANDIDATE_SEQUENCE = 'CHOOSE_CANDIDATE_SEQUENCE' , IMPLICITLY_COMMIT_CANDIDATE = 'IMPLICITLY_COMMIT_CANDIDATE' , SAVE_STATE = 'SAVE_STATE' } export interface LogEvent { event : Events ; timestamp : number ; payload ? : any ; id : string ; } export class LoggingService { private logEvents : LogEvent [ ] = [ ] ; private sessionId = getDateString ( ) ; logEvent ( event , payload = undefined ) { const logEvent = { event , timestamp : Date . now ( ) , id : featureFlags . id , } ; if ( payload !== undefined ) { logEvent . payload = payload ; } console . log ( event , logEvent ) ; this . logEvents . push ( logEvent ) ; if ( featureFlags . firebaseLogging ) { api . writeLogEvent ( this . sessionId , logEvent ) ; } if ( featureFlags . sheetsLogging ) { this . logToGoogleForm ( logEvent ) ; } } private logToGoogleForm ( logEvent ) { ( < HTMLTextAreaElement > ( document . getElementById ( 'sheets-logging-textarea' ) ) ) . value = JSON . stringify ( logEvent ) ; const form = < HTMLFormElement > ( document . getElementById ( 'sheets-logging-form' ) ) ; form . submit ( ) ; console . log ( 'logged to googleform' ) ; } } export default new LoggingService ( ) ;