Once user grants permission for hosting page to communicate with API TrezorConnect will emits events about device state. Events can be distinguished by "type" field of event object (TODO structure) Constants of all types can be imported from package
ES6
import TrezorConnect, { DEVICE_EVENT, DEVICE } from 'trezor-connect';
TrezorConnect.on(DEVICE_EVENT, (event) => {
if (event.type === DEVICE.CONNECT) {
} else if (event.type === DEVICE.DISCONNECT) {
}
});
CommonJS
var TrezorConnect = require('trezor-connect').default;
var DEVICE_EVENT = require('trezor-connect').DEVICE_EVENT;
var DEVICE = require('trezor-connect').DEVICE;
TrezorConnect.on(DEVICE_EVENT, (event) => {
if (event.type === DEVICE.CONNECT) {
} else if (event.type === DEVICE.DISCONNECT) {
}
});
Inline
window.TrezorConnect.on('DEVICE_EVENT', (event) => {
if (event.type === 'device-connect') {
} else if (event.type === 'device-disconnect') {
}
});
device-connect
device-disconnect
device-changed