TODO: changes for cabana to replace the demo route with a retropilot drive specific configuration.
parent
83059a62bf
commit
24e3bedd12
|
@ -152,8 +152,8 @@ export default class CanExplorer extends Component {
|
|||
} else if (this.props.isDemo) {
|
||||
// is demo!
|
||||
|
||||
const logUrls = demoLogUrls;
|
||||
const route = demoRoute;
|
||||
const logUrls = global.retropilotLoaded ? global.retropilotLogUrls : demoLogUrls;
|
||||
const route = global.retropilotLoaded ? global.retropilotRoute : demoRoute;
|
||||
|
||||
this.setState({
|
||||
logUrls,
|
||||
|
|
20
src/init.js
20
src/init.js
|
@ -10,6 +10,7 @@ import {
|
|||
persistGithubAuthToken
|
||||
} from './api/localstorage';
|
||||
import { demoProps } from './demo';
|
||||
import { loadRetropilotDrive } from './retropilotloader';
|
||||
|
||||
async function authenticate() {
|
||||
if (window.location && window.location.pathname === AuthConfig.AUTH_PATH) {
|
||||
|
@ -110,8 +111,21 @@ export default function init() {
|
|||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
authenticate().then(() => {
|
||||
resolve(props);
|
||||
});
|
||||
|
||||
authenticate()
|
||||
.then(() => {
|
||||
const retropilotHost = getUrlParameter('retropilotHost') || '';
|
||||
const driveIdentifier = getUrlParameter('retropilotIdentifier') || '';
|
||||
const seekTime = getUrlParameter('seekTime') || 0;
|
||||
return loadRetropilotDrive(retropilotHost, driveIdentifier, seekTime);
|
||||
})
|
||||
.then(() => {
|
||||
if (global.retropilotLoaded) {
|
||||
Object.assign(props, global.retropilotProps);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
resolve(props);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
import Moment from 'moment';
|
||||
import CorollaDBC from './corolla-dbc';
|
||||
|
||||
export async function loadRetropilotDrive(retropilotHost, driveIdentifier, seekTime) {
|
||||
if (driveIdentifier == null || !driveIdentifier.length) {
|
||||
global.retropilotLoaded = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch(retropilotHost + 'useradmin/cabana_drive/' + encodeURIComponent(driveIdentifier));
|
||||
let retropilotDrive;
|
||||
try {
|
||||
retropilotDrive = await response.json();
|
||||
} catch (exception) {}
|
||||
|
||||
if (!retropilotDrive || !retropilotDrive.logUrls) {
|
||||
alert(retropilotDrive && retropilotDrive.status ? retropilotDrive.status : 'fetching retropilot drive failed!');
|
||||
global.retropilotLoaded = false;
|
||||
return;
|
||||
}
|
||||
global.retropilotLogUrls = retropilotDrive.logUrls;
|
||||
|
||||
global.retropilotProps = {
|
||||
autoplay: true,
|
||||
startTime: seekTime,
|
||||
segments: global.retropilotLogUrls.length,
|
||||
isDemo: true,
|
||||
max: global.retropilotLogUrls.length,
|
||||
name: retropilotDrive.driveIdentifier,
|
||||
dongleId: retropilotDrive.dongleId,
|
||||
dbc: CorollaDBC,
|
||||
dbcFilename: 'toyota_nodsu_pt_generated.dbc'
|
||||
};
|
||||
|
||||
global.retropilotRoute = {
|
||||
fullname: retropilotDrive.name,
|
||||
proclog: global.retropilotProps.max,
|
||||
start_time: Moment(global.retropilotProps.name, 'YYYY-MM-DD--H-m-s'),
|
||||
url: retropilotDrive.driveUrl
|
||||
};
|
||||
|
||||
global.retropilotLoaded = global.retropilotProps.max > 0;
|
||||
}
|
Loading…
Reference in New Issue