2017-08-05 22:25:25 +12:00
import React , { PropTypes } from 'react'
import { connect } from 'react-redux'
import { Link , hashHistory } from 'react-router'
import { bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'
import SpotifyAuthenticationFrame from '../components/SpotifyAuthenticationFrame'
import ConfirmationButton from '../components/ConfirmationButton'
import PusherConnectionList from '../components/PusherConnectionList'
import URISchemesList from '../components/URISchemesList'
import VersionManager from '../components/VersionManager'
import Header from '../components/Header'
import Thumbnail from '../components/Thumbnail'
2018-03-25 10:20:17 +13:00
import Snapcast from '../components/Snapcast'
2017-08-05 22:25:25 +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'
class Debug extends React . Component {
2017-10-10 13:05:28 +13:00
constructor ( props ) {
2017-08-05 22:25:25 +12:00
super ( props ) ;
this . state = {
mopidy _call : 'playlists.asList' ,
mopidy _data : '{}' ,
pusher _data : '{"method":"get_config"}' ,
access _token : this . props . access _token
}
}
callMopidy ( e ) {
e . preventDefault ( )
2017-10-10 13:05:28 +13:00
this . props . mopidyActions . debug ( this . state . mopidy _call , JSON . parse ( this . state . mopidy _data ) )
2017-08-05 22:25:25 +12:00
}
callPusher ( e ) {
e . preventDefault ( )
2017-10-10 13:05:28 +13:00
this . props . pusherActions . debug ( JSON . parse ( this . state . pusher _data ) )
2017-08-05 22:25:25 +12:00
}
render ( ) {
var options = (
< span >
< button className = "no-hover" onClick = { e => hashHistory . push ( global . baseURL + 'settings' ) } >
< FontAwesome name = "reply" / > & nbsp ;
Back
< / b u t t o n >
< / s p a n >
)
return (
< div className = "view debugger-view" >
< Header icon = "cog" title = "Debugger" options = { options } uiActions = { this . props . uiActions } / >
< div className = "content-wrapper" >
< h4 className = "underline" > User interface < / h 4 >
< form >
< div className = "field checkbox" >
< div className = "name" > Debug < / d i v >
< div className = "input" >
2017-09-03 21:00:17 +12:00
< label >
< input
type = "checkbox"
name = "debug_info"
checked = { this . props . test _mode }
onChange = { e => this . props . uiActions . set ( { test _mode : ! this . props . test _mode } ) } / >
< span className = "label" > Test mode < / s p a n >
< / l a b e l >
2017-08-05 22:25:25 +12:00
< label >
< input
type = "checkbox"
name = "debug_info"
checked = { this . props . debug _info }
onChange = { e => this . props . uiActions . set ( { debug _info : ! this . props . debug _info } ) } / >
2017-09-03 21:00:17 +12:00
< span className = "label" > Debug info < / s p a n >
2017-08-05 22:25:25 +12:00
< / l a b e l >
< / d i v >
< / d i v >
< div className = "field checkbox" >
< div className = "name" > Logging < / d i v >
< div className = "input" >
< label >
< input
type = "checkbox"
name = "log_actions"
checked = { this . props . log _actions }
onChange = { e => this . props . uiActions . set ( { log _actions : ! this . props . log _actions } ) } / >
< span className = "label" > Log actions < / s p a n >
< / l a b e l >
< label >
< input
type = "checkbox"
name = "log_mopidy"
checked = { this . props . log _mopidy }
onChange = { e => this . props . uiActions . set ( { log _mopidy : ! this . props . log _mopidy } ) } / >
< span className = "label" > Log Mopidy < / s p a n >
< / l a b e l >
< label >
< input
type = "checkbox"
name = "log_pusher"
checked = { this . props . log _pusher }
onChange = { e => this . props . uiActions . set ( { log _pusher : ! this . props . log _pusher } ) } / >
< span className = "label" > Log Pusher < / s p a n >
< / l a b e l >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > < / d i v >
< div className = "input" >
2018-02-23 09:35:38 +13:00
< a className = "button secondary" onClick = { e => this . props . uiActions . createNotification ( { content : 'Test notification' } ) } > Create notification < / a >
2017-09-08 07:57:48 +12:00
< a className = "button secondary" onClick = { e => this . props . uiActions . startProcess ( 'test_process' , 'Test process' , { total : 100 , remaining : 17 } ) } > Start process < / a >
2018-02-28 09:15:34 +13:00
< a className = "button secondary" onClick = { e => this . props . uiActions . processFinishing ( 'test_process' ) } > Stop process < / a >
2017-08-05 22:25:25 +12:00
< / d i v >
< / d i v >
< / f o r m >
2018-03-25 10:20:17 +13:00
< h4 className = "underline" > Snapcast ( beta ) < / h 4 >
< div className = "field" >
< Snapcast / >
< / d i v >
2017-08-05 22:25:25 +12:00
< h4 className = "underline" > Spotify < / h 4 >
< div className = "field" >
< div className = "name" > Access token < / d i v >
< div className = "input" >
< input
type = "text"
2017-08-06 20:22:16 +12:00
onChange = { e => this . props . spotifyActions . authorizationGranted ( { access _token : e . target . value } ) }
2017-08-05 22:25:25 +12:00
value = { this . state . access _token } / >
< / d i v >
< / d i v >
< h4 className = "underline" > Mopidy < / h 4 >
< form onSubmit = { ( e ) => this . callMopidy ( e ) } >
< div className = "field" >
< div className = "name" > Call < / d i v >
< div className = "input" >
< input
type = "text"
onChange = { e => this . setState ( { mopidy _call : e . target . value } ) }
value = { this . state . mopidy _call } / >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > Data < / d i v >
< div className = "input" >
< textarea
onChange = { e => this . setState ( { mopidy _data : e . target . value } ) }
value = { this . state . mopidy _data } >
< / t e x t a r e a >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > < / d i v >
< div className = "input" >
< button type = "submit" className = "secondary" > Send < / b u t t o n >
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Pusher < / h 4 >
< form onSubmit = { ( e ) => this . callPusher ( e ) } >
< div className = "field" >
< div className = "name" > Examples < / d i v >
< 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 >
2018-03-26 10:36:13 +13:00
< 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 >
2017-08-05 22:25:25 +12:00
< 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":"perform_upgrade"}' > Perform upgrade ( beta ) < / o p t i o n >
2017-10-04 16:47:15 +13:00
< option value = '{"method":"proxy_request","data":{"url":"https://jsonplaceholder.typicode.com/posts/1"}}' > Proxy request < / o p t i o n >
2017-08-05 22:25:25 +12:00
< / s e l e c t >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > Data < / d i v >
< div className = "input" >
< textarea
onChange = { e => this . setState ( { pusher _data : e . target . value } ) }
value = { this . state . pusher _data } >
< / t e x t a r e a >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" > < / d i v >
< div className = "input" >
< button type = "submit" className = "secondary" > Send < / b u t t o n >
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Response < / h 4 >
< pre >
{ this . props . debug _response ? JSON . stringify ( this . props . debug _response , null , 2 ) : null }
< / p r e >
< / d i v >
< / d i v >
) ;
}
}
/ * *
* Export our component
*
* We also integrate our global store , using connect ( )
* * /
const mapStateToProps = ( state , ownProps ) => {
return {
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 ) ,
2017-09-03 21:00:17 +12:00
test _mode : ( state . ui . test _mode ? state . ui . test _mode : false ) ,
2017-08-05 22:25:25 +12:00
debug _info : ( state . ui . debug _info ? state . ui . debug _info : false ) ,
debug _response : state . ui . debug _response
}
}
const mapDispatchToProps = ( dispatch ) => {
return {
uiActions : bindActionCreators ( uiActions , dispatch ) ,
pusherActions : bindActionCreators ( pusherActions , dispatch ) ,
mopidyActions : bindActionCreators ( mopidyActions , dispatch ) ,
spotifyActions : bindActionCreators ( spotifyActions , dispatch )
}
}
export default connect ( mapStateToProps , mapDispatchToProps ) ( Debug )