2019-09-05 15:36:11 +12:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import { bindActionCreators } from 'redux' ;
import Header from '../components/Header' ;
import Icon from '../components/Icon' ;
2020-08-15 21:05:00 +12:00
import Button from '../components/Button' ;
2019-09-05 15:36:11 +12:00
import * as uiActions from '../services/ui/actions' ;
import * as pusherActions from '../services/pusher/actions' ;
import * as mopidyActions from '../services/mopidy/actions' ;
import * as spotifyActions from '../services/spotify/actions' ;
2019-10-30 06:42:11 +13:00
import * as snapcastActions from '../services/snapcast/actions' ;
2020-07-07 20:52:09 +12:00
import { I18n , i18n } from '../locale' ;
2019-09-05 15:36:11 +12:00
2019-09-10 06:59:44 +12:00
class Debug extends React . Component {
2019-09-05 15:36:11 +12:00
constructor ( props ) {
super ( props ) ;
this . state = {
mopidy _call : 'playlists.asList' ,
mopidy _data : '{}' ,
pusher _data : '{"method":"get_config"}' ,
2019-10-30 06:42:11 +13:00
snapcast _data : '{"method":"Server.GetStatus"}' ,
2019-09-05 15:36:11 +12:00
access _token : this . props . access _token ,
toggling _test _mode : false ,
} ;
}
componentDidMount ( ) {
2020-07-07 20:52:09 +12:00
const { uiActions : { setWindowTitle } } = this . props ;
setWindowTitle ( i18n ( 'debug.title' ) ) ;
2019-09-05 15:36:11 +12:00
}
2020-07-07 20:52:09 +12:00
onBack = ( ) => {
const { history } = this . props ;
history . push ( '/settings' ) ;
}
callMopidy = ( e ) => {
const { mopidyActions : { debug } } = this . props ;
const { mopidy _call , mopidy _data } = this . state ;
2019-09-05 15:36:11 +12:00
e . preventDefault ( ) ;
2020-07-07 20:52:09 +12:00
debug ( mopidy _call , JSON . parse ( mopidy _data ) ) ;
2019-09-05 15:36:11 +12:00
}
2020-07-07 20:52:09 +12:00
callPusher = ( e ) => {
const { pusherActions : { debug } } = this . props ;
const { pusher _data } = this . state ;
2019-09-05 15:36:11 +12:00
e . preventDefault ( ) ;
2020-07-07 20:52:09 +12:00
debug ( JSON . parse ( pusher _data ) ) ;
2019-09-05 15:36:11 +12:00
}
2020-07-07 20:52:09 +12:00
callSnapcast = ( e ) => {
const { snapcastActions : { debug } } = this . props ;
const { snapcast _data } = this . state ;
2019-10-30 06:42:11 +13:00
e . preventDefault ( ) ;
2020-07-07 20:52:09 +12:00
debug ( JSON . parse ( snapcast _data ) ) ;
2019-10-30 06:42:11 +13:00
}
2020-07-07 20:52:09 +12:00
toggleTestMode = ( e ) => {
const { uiActions : { set } , test _mode } = this . props ;
2019-09-05 15:36:11 +12:00
this . setState ( { toggling _test _mode : true } ) ;
2020-07-07 20:52:09 +12:00
set ( { test _mode : ! test _mode } ) ;
2019-09-05 15:36:11 +12:00
// Wait a second to allow state to update, and then refresh
setTimeout ( location . reload ( ) , 1000 ) ;
}
2020-07-07 20:52:09 +12:00
render = ( ) => {
const {
uiActions ,
spotifyActions ,
history ,
test _mode ,
debug _response ,
debug _info ,
log _actions ,
log _mopidy ,
log _pusher ,
log _snapcast ,
access _token ,
} = this . props ;
const {
toggling _test _mode ,
mopidy _call ,
mopidy _data ,
pusher _data ,
snapcast _data ,
} = this . state ;
2020-08-16 20:00:10 +12:00
2019-09-05 15:36:11 +12:00
const options = (
2020-08-16 20:00:10 +12:00
< Button
onClick = { this . onBack }
noHover
discrete
>
2019-09-10 06:59:44 +12:00
< Icon name = "keyboard_backspace" / >
2020-07-07 20:52:09 +12:00
< I18n path = "actions.back" / >
2020-08-16 20:00:10 +12:00
< / B u t t o n >
2019-09-05 15:36:11 +12:00
) ;
return (
< div className = "view debugger-view" >
2020-07-07 20:52:09 +12:00
< Header options = { options } uiActions = { uiActions } >
2019-09-05 15:36:11 +12:00
< Icon name = "settings" type = "material" / >
2020-07-07 20:52:09 +12:00
< I18n path = "debug.title" / >
2019-09-05 15:36:11 +12:00
< / H e a d e r >
< div className = "content-wrapper" >
2020-07-07 20:52:09 +12:00
< h4 className = "underline" > < I18n path = "debug.ui.title" / > < / h 4 >
2019-09-05 15:36:11 +12:00
< form >
< div className = "field checkbox" >
< div className = "name" > Test mode < / d i v >
< div className = "input" >
2020-08-16 20:00:10 +12:00
< Button
type = { test _mode ? 'destructive' : null }
working = { toggling _test _mode }
onClick = { this . toggleTestMode }
tracking = { { category : 'Debug' , action : 'TestMode' , label : test _mode ? 'Disable' : 'Enable' } }
>
< I18n path = { ` actions. ${ test _mode ? 'disable' : 'enable' } ` } / >
< / B u t t o n >
2019-09-05 15:36:11 +12:00
< / d i v >
< / d i v >
< div className = "field checkbox" >
2020-07-07 20:52:09 +12:00
< div className = "name" > < I18n path = "debug.debug.title" / > < / d i v >
2019-09-05 15:36:11 +12:00
< div className = "input" >
< label >
< input
type = "checkbox"
name = "debug_info"
2020-07-07 20:52:09 +12:00
checked = { debug _info }
onChange = { ( ) => uiActions . set ( { debug _info : ! debug _info } ) }
2019-09-05 15:36:11 +12:00
/ >
2020-07-07 20:52:09 +12:00
< span className = "label" > < I18n path = "debug.debug.overlay" / > < / s p a n >
2019-09-05 15:36:11 +12:00
< / l a b e l >
< / d i v >
< / d i v >
< div className = "field checkbox" >
2020-07-07 20:52:09 +12:00
< div className = "name" > < I18n path = "debug.logging.title" / > < / d i v >
2019-09-05 15:36:11 +12:00
< div className = "input" >
< label >
< input
type = "checkbox"
name = "log_actions"
2020-07-07 20:52:09 +12:00
checked = { log _actions }
onChange = { ( ) => uiActions . set ( { log _actions : ! log _actions } ) }
2019-09-05 15:36:11 +12:00
/ >
2020-07-07 20:52:09 +12:00
< span className = "label" > < I18n path = "debug.logging.actions" / > < / s p a n >
2019-09-05 15:36:11 +12:00
< / l a b e l >
< label >
< input
type = "checkbox"
name = "log_mopidy"
2020-07-07 20:52:09 +12:00
checked = { log _mopidy }
onChange = { ( ) => uiActions . set ( { log _mopidy : ! log _mopidy } ) }
2019-09-05 15:36:11 +12:00
/ >
2020-07-07 20:52:09 +12:00
< span className = "label" > < I18n path = "debug.logging.mopidy" / > < / s p a n >
2019-09-05 15:36:11 +12:00
< / l a b e l >
< label >
< input
type = "checkbox"
name = "log_pusher"
2020-07-07 20:52:09 +12:00
checked = { log _pusher }
onChange = { ( ) => uiActions . set ( { log _pusher : ! log _pusher } ) }
2019-09-05 15:36:11 +12:00
/ >
2020-07-07 20:52:09 +12:00
< span className = "label" > < I18n path = "debug.logging.pusher" / > < / s p a n >
2019-09-05 15:36:11 +12:00
< / l a b e l >
2019-10-25 15:47:25 +13:00
< label >
< input
type = "checkbox"
name = "log_pusher"
2020-07-07 20:52:09 +12:00
checked = { log _snapcast }
onChange = { ( ) => uiActions . set ( { log _snapcast : ! log _snapcast } ) }
2019-10-25 15:47:25 +13:00
/ >
2020-07-07 20:52:09 +12:00
< span className = "label" > < I18n path = "debug.logging.snapcast" / > < / s p a n >
2019-10-25 15:47:25 +13:00
< / l a b e l >
2019-09-05 15:36:11 +12:00
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" / >
< div className = "input" >
2020-08-15 21:05:00 +12:00
< Button
onClick = { ( ) => this . props . uiActions . createNotification ( { content : 'Test notification' } ) }
2020-08-16 20:00:10 +12:00
tracking = { { category : 'Debug' , action : 'Test notification' } }
2020-08-15 21:05:00 +12:00
>
< I18n path = "debug.create_notification" / >
< / B u t t o n >
< Button
2020-10-26 21:32:53 +13:00
onClick = {
( ) => this . props . uiActions . startProcess (
'TEST_PROCESS' ,
{ content : 'Test process' , remaining : 68 , total : 100 } ,
)
}
2020-08-16 20:00:10 +12:00
tracking = { { category : 'Debug' , action : 'Test process' } }
2020-08-15 21:05:00 +12:00
>
< I18n path = "debug.create_process" / >
< / B u t t o n >
< Button
onClick = { ( ) => this . props . pusherActions . request ( 'test' ) }
2020-08-16 20:00:10 +12:00
tracking = { { category : 'Debug' , action : 'Run test process' } }
2020-08-15 21:05:00 +12:00
>
< I18n path = "debug.run_test" / >
< / B u t t o n >
2019-09-05 15:36:11 +12:00
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Spotify < / h 4 >
< label className = "field" >
2020-07-07 20:52:09 +12:00
< div className = "name" > < I18n path = "debug.access_token" / > < / d i v >
2019-09-05 15:36:11 +12:00
< div className = "input" >
< input
type = "text"
2020-07-07 20:52:09 +12:00
onChange = { ( e ) => spotifyActions . authorizationGranted ( { access _token : e . target . value } ) }
value = { access _token }
2019-09-05 15:36:11 +12:00
/ >
< / d i v >
< / l a b e l >
2020-07-07 20:52:09 +12:00
< h4 className = "underline" > < I18n path = "services.mopidy.title" / > < / h 4 >
< form onSubmit = { this . callMopidy } >
2019-09-05 15:36:11 +12:00
< label className = "field" >
2020-07-07 20:52:09 +12:00
< div className = "name" > < I18n path = "debug.call" / > < / d i v >
2019-09-05 15:36:11 +12:00
< div className = "input" >
< input
type = "text"
onChange = { ( e ) => this . setState ( { mopidy _call : e . target . value } ) }
2020-07-07 20:52:09 +12:00
value = { mopidy _call }
2019-09-05 15:36:11 +12:00
/ >
< / d i v >
< / l a b e l >
< label className = "field" >
2020-07-07 20:52:09 +12:00
< div className = "name" > < I18n path = "debug.data" / > < / d i v >
2019-09-05 15:36:11 +12:00
< div className = "input" >
< textarea
onChange = { ( e ) => this . setState ( { mopidy _data : e . target . value } ) }
2020-07-07 20:52:09 +12:00
value = { mopidy _data }
2019-09-05 15:36:11 +12:00
/ >
< / d i v >
< / l a b e l >
< div className = "field" >
< div className = "name" / >
< div className = "input" >
2020-08-16 20:00:10 +12:00
< Button
submit
tracking = { { category : 'Debug' , action : 'Mopidy' , label : 'Send' } }
>
< I18n path = "actions.send" / >
< / B u t t o n >
2019-09-05 15:36:11 +12:00
< / d i v >
< / d i v >
< / f o r m >
2020-07-07 20:52:09 +12:00
< h4 className = "underline" > < I18n path = "services.pusher.title" / > < / h 4 >
< form onSubmit = { this . callPusher } >
2019-09-05 15:36:11 +12:00
< label className = "field" >
2020-07-07 20:52:09 +12:00
< div className = "name" > < I18n path = "debug.examples" / > < / d i v >
2019-09-05 15:36:11 +12:00
< div className = "input" >
< select onChange = { ( e ) => this . setState ( { pusher _data : e . target . value } ) } >
< option value = '{"method":"get_config"}' > Get config < / o p t i o n >
< option value = '{"method":"get_version"}' > Get version < / o p t i o n >
< option value = '{"method":"get_connections"}' > Get connections < / o p t i o n >
< option value = '{"method":"get_radio"}' > Get radio < / o p t i o n >
< option value = '{"method":"get_queue_metadata"}' > Get queue metadata < / o p t i o n >
< option value = '{"method":"broadcast","data":{"method":"notification","params":{"notification":{"type":"info","title":"Testing","content":"This is my message"}}}}' > Broadcast to all clients < / o p t i o n >
< option value = '{"method":"send_message","data":{"method":"notification","params":{"notification":{"type":"info","title":"Testing","content":"This is my message"}}}}' > Broadcast to one client < / o p t i o n >
< option value = '{"method":"set_username","data":{"connection_id":"CONNECTION_ID_HERE","username":"NewUsername"}}' > Change username < / o p t i o n >
< option value = '{"method":"refresh_spotify_token"}' > Refresh Spotify token < / o p t i o n >
< option value = '{"method":"broadcast","data":{"method":"reload","params":{}}}' > Forced reload for all connected clients < / o p t i o n >
< option value = '{"method":"perform_upgrade"}' > Perform upgrade ( beta ) < / o p t i o n >
< / s e l e c t >
< / d i v >
< / l a b e l >
< label className = "field" >
2020-07-07 20:52:09 +12:00
< div className = "name" > < I18n path = "debug.data" / > < / d i v >
2019-09-05 15:36:11 +12:00
< div className = "input" >
< textarea
onChange = { ( e ) => this . setState ( { pusher _data : e . target . value } ) }
2020-07-07 20:52:09 +12:00
value = { pusher _data }
2019-09-05 15:36:11 +12:00
/ >
< / d i v >
< / l a b e l >
< div className = "field" >
< div className = "name" / >
< div className = "input" >
2020-08-16 20:00:10 +12:00
< Button
submit
tracking = { { category : 'Debug' , action : 'Pusher' , label : 'Send' } }
>
< I18n path = "actions.send" / >
< / B u t t o n >
2019-09-05 15:36:11 +12:00
< / d i v >
< / d i v >
< / f o r m >
2020-07-07 20:52:09 +12:00
< h4 className = "underline" > < I18n path = "services.snapcast.title" / > < / h 4 >
2019-10-30 06:42:11 +13:00
< form onSubmit = { ( e ) => this . callSnapcast ( e ) } >
< label className = "field" >
2020-07-07 20:52:09 +12:00
< div className = "name" > < I18n path = "debug.data" / > < / d i v >
2019-10-30 06:42:11 +13:00
< div className = "input" >
< textarea
onChange = { ( e ) => this . setState ( { snapcast _data : e . target . value } ) }
2020-07-07 20:52:09 +12:00
value = { snapcast _data }
2019-10-30 06:42:11 +13:00
/ >
< / d i v >
< / l a b e l >
< div className = "field" >
< div className = "name" / >
< div className = "input" >
2020-08-16 20:00:10 +12:00
< Button
submit
tracking = { { category : 'Debug' , action : 'Snapcast' , label : 'Send' } }
>
< I18n path = "actions.send" / >
< / B u t t o n >
2019-10-30 06:42:11 +13:00
< / d i v >
< / d i v >
< / f o r m >
2020-07-07 20:52:09 +12:00
< h4 className = "underline" > < I18n path = "debug.response" / > < / h 4 >
2019-09-05 15:36:11 +12:00
< pre >
2020-07-07 20:52:09 +12:00
{ debug _response && JSON . stringify ( debug _response , null , 2 ) }
2019-09-05 15:36:11 +12:00
< / p r e >
< / d i v >
< / d i v >
) ;
}
2017-08-05 22:25:25 +12:00
}
2020-07-07 20:52:09 +12:00
const mapStateToProps = ( state ) => ( {
2019-09-05 15:36:11 +12:00
connection _id : state . pusher . connection _id ,
access _token : ( state . spotify . access _token ? state . spotify . access _token : '' ) ,
log _actions : ( state . ui . log _actions ? state . ui . log _actions : false ) ,
log _pusher : ( state . ui . log _pusher ? state . ui . log _pusher : false ) ,
log _mopidy : ( state . ui . log _mopidy ? state . ui . log _mopidy : false ) ,
2019-10-25 15:47:25 +13:00
log _snapcast : ( state . ui . log _snapcast ? state . ui . log _snapcast : false ) ,
2019-09-05 15:36:11 +12:00
test _mode : ( state . ui . test _mode ? state . ui . test _mode : false ) ,
debug _info : ( state . ui . debug _info ? state . ui . debug _info : false ) ,
debug _response : state . ui . debug _response ,
} ) ;
const mapDispatchToProps = ( dispatch ) => ( {
uiActions : bindActionCreators ( uiActions , dispatch ) ,
pusherActions : bindActionCreators ( pusherActions , dispatch ) ,
mopidyActions : bindActionCreators ( mopidyActions , dispatch ) ,
spotifyActions : bindActionCreators ( spotifyActions , dispatch ) ,
2019-10-30 06:42:11 +13:00
snapcastActions : bindActionCreators ( snapcastActions , dispatch ) ,
2019-09-05 15:36:11 +12:00
} ) ;
2019-09-10 06:59:44 +12:00
export default connect ( mapStateToProps , mapDispatchToProps ) ( Debug ) ;