Skip to content
Snippets Groups Projects
Unverified Commit ff7daa18 authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #2777 from paulkaplan/instrument-device-connections

Instrument device connection events
parents f50cf118 d80078a2
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ import React from 'react'; ...@@ -3,6 +3,7 @@ import React from 'react';
import bindAll from 'lodash.bindall'; import bindAll from 'lodash.bindall';
import ConnectionModalComponent, {PHASES} from '../components/connection-modal/connection-modal.jsx'; import ConnectionModalComponent, {PHASES} from '../components/connection-modal/connection-modal.jsx';
import VM from 'scratch-vm'; import VM from 'scratch-vm';
import analytics from '../lib/analytics';
class ConnectionModal extends React.Component { class ConnectionModal extends React.Component {
constructor (props) { constructor (props) {
...@@ -16,18 +17,13 @@ class ConnectionModal extends React.Component { ...@@ -16,18 +17,13 @@ class ConnectionModal extends React.Component {
'handleHelp' 'handleHelp'
]); ]);
this.state = { this.state = {
phase: PHASES.scanning phase: props.vm.getPeripheralIsConnected(props.extensionId) ?
PHASES.connected : PHASES.scanning
}; };
} }
componentDidMount () { componentDidMount () {
this.props.vm.on('PERIPHERAL_CONNECTED', this.handleConnected); this.props.vm.on('PERIPHERAL_CONNECTED', this.handleConnected);
this.props.vm.on('PERIPHERAL_ERROR', this.handleError); this.props.vm.on('PERIPHERAL_ERROR', this.handleError);
// Check if we're already connected
if (this.props.vm.getPeripheralIsConnected(this.props.extensionId)) {
this.handleConnected();
}
} }
componentWillUnmount () { componentWillUnmount () {
this.props.vm.removeListener('PERIPHERAL_CONNECTED', this.handleConnected); this.props.vm.removeListener('PERIPHERAL_CONNECTED', this.handleConnected);
...@@ -43,6 +39,11 @@ class ConnectionModal extends React.Component { ...@@ -43,6 +39,11 @@ class ConnectionModal extends React.Component {
this.setState({ this.setState({
phase: PHASES.connecting phase: PHASES.connecting
}); });
analytics.event({
category: 'extensions',
action: 'connecting',
label: this.props.extensionId
});
} }
handleDisconnect () { handleDisconnect () {
this.props.onStatusButtonUpdate(this.props.extensionId, 'not ready'); this.props.onStatusButtonUpdate(this.props.extensionId, 'not ready');
...@@ -68,6 +69,11 @@ class ConnectionModal extends React.Component { ...@@ -68,6 +69,11 @@ class ConnectionModal extends React.Component {
this.setState({ this.setState({
phase: PHASES.error phase: PHASES.error
}); });
analytics.event({
category: 'extensions',
action: 'connecting error',
label: this.props.extensionId
});
} }
} }
handleConnected () { handleConnected () {
...@@ -75,9 +81,19 @@ class ConnectionModal extends React.Component { ...@@ -75,9 +81,19 @@ class ConnectionModal extends React.Component {
this.setState({ this.setState({
phase: PHASES.connected phase: PHASES.connected
}); });
analytics.event({
category: 'extensions',
action: 'connected',
label: this.props.extensionId
});
} }
handleHelp () { handleHelp () {
window.open(this.props.helpLink, '_blank'); window.open(this.props.helpLink, '_blank');
analytics.event({
category: 'extensions',
action: 'help',
label: this.props.extensionId
});
} }
render () { render () {
return ( return (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment