2016-11-22 21:19:08 +01:00
import React from 'react' ;
import lbry from '../lbry.js' ;
import LoadScreen from './load_screen.js' ;
2017-05-17 10:10:25 +02:00
export class SplashScreen extends React . Component {
2017-06-06 06:21:55 +02:00
static propTypes = {
message : React . PropTypes . string ,
onLoadDone : React . PropTypes . func
} ;
2017-05-17 10:10:25 +02:00
2017-06-06 06:21:55 +02:00
constructor ( props ) {
super ( props ) ;
2017-05-17 10:10:25 +02:00
2017-06-06 06:21:55 +02:00
this . state = {
details : _ _ ( 'Starting daemon' ) ,
message : _ _ ( 'Connecting' ) ,
isLagging : false
} ;
}
2017-05-17 10:10:25 +02:00
2017-06-06 06:21:55 +02:00
updateStatus ( ) {
lbry . status ( ) . then ( status => {
this . _updateStatusCallback ( status ) ;
} ) ;
}
2017-05-17 10:10:25 +02:00
2017-06-06 06:21:55 +02:00
_updateStatusCallback ( status ) {
const startupStatus = status . startup _status ;
if ( startupStatus . code == 'started' ) {
// Wait until we are able to resolve a name before declaring
// that we are done.
// TODO: This is a hack, and the logic should live in the daemon
// to give us a better sense of when we are actually started
this . setState ( {
message : _ _ ( 'Testing Network' ) ,
details : _ _ ( 'Waiting for name resolution' ) ,
isLagging : false
} ) ;
2016-04-14 08:27:06 +02:00
2017-06-06 06:21:55 +02:00
lbry . resolve ( { uri : 'lbry://one' } ) . then ( ( ) => {
this . props . onLoadDone ( ) ;
} ) ;
return ;
}
this . setState ( {
details : startupStatus . message + ( startupStatus . is _lagging ? '' : '...' ) ,
isLagging : startupStatus . is _lagging
} ) ;
setTimeout ( ( ) => {
this . updateStatus ( ) ;
} , 500 ) ;
}
2017-05-17 10:10:25 +02:00
2017-06-06 06:21:55 +02:00
componentDidMount ( ) {
lbry
. connect ( )
. then ( ( ) => {
this . updateStatus ( ) ;
} )
. catch ( ( ) => {
this . setState ( {
isLagging : true ,
message : _ _ ( 'Connection Failure' ) ,
details : _ _ (
'Try closing all LBRY processes and starting again. If this still happpens, your anti-virus software or firewall may be preventing LBRY from connecting. Contact hello@lbry.io if you think this is a software bug.'
)
} ) ;
} ) ;
}
2017-05-17 10:10:25 +02:00
2017-06-06 06:21:55 +02:00
render ( ) {
return (
< LoadScreen
message = { this . state . message }
details = { this . state . details }
isWarning = { this . state . isLagging }
/ >
) ;
}
2017-05-17 10:10:25 +02:00
}
2016-11-22 21:19:08 +01:00
export default SplashScreen ;