description |
---|
Event bus provides a way to subscribe to events from any of the services running. |
const eventBus = require('ocore/event_bus.js');
Headless wallet is needed for bots that hold private keys and can send transactions. This event is emitted when passphrase has been entered by bot admin and single wallet is loaded. Before that event, bot outputs device address, device pubkey and pairing key.
eventBus.on('headless_wallet_ready', () => {
});
This event is emitted when bot executes series database queries to upgrade the database to new version.
eventBus.on('started_db_upgrade', () => {
});
This event is emitted when bot finishes database upgrade.
eventBus.on('finished_db_upgrade', () => {
});
eventBus.on('connected', () => {
});
The url
parameter is protocol + domain + path (for example: wss://obyte.org/bb
).
eventBus.on('open-' + url, (error) => {
});
eventBus.on('connected_to_source', (new_ws) => {
});
eventBus.on('nonfatal_error', (msg, Error) => {
});
eventBus.on("validated-" + unit, (bValid) => {
});
eventBus.on('new_joint', (objJoint) => {
});
eventBus.on('mci_became_stable', (mci) => {
});
eventBus.on('new_my_transactions', (arrNewUnits) => {
});
eventBus.on('my_transactions_became_stable', (arrUnits) => {
});
eventBus.on('sequence_became_bad', (arrUniqueUnits) => {
});
eventBus.on('first_history_received', () => {
});
eventBus.on('maybe_new_transactions', () => {
});
eventBus.on("new_my_unit-" + unit, (objJoint) => {
});
eventBus.on("received_payment", (payer_device_address, assocAmountsByAsset, asset, message_counter, bToSharedAddress) => {
});
eventBus.on('my_stable-' + unit , () => {
});
eventBus.on('sync_idle' , () => {
});
eventBus.on('catching_up_done' , () => {
});
eventBus.on('catching_up_started' , () => {
});
eventBus.on('catchup_next_hash_tree' , () => {
});
eventBus.on('new_direct_private_chains' , (arrChains) => {
});
eventBus.on('unhandled_private_payments_left' , (rowsLength) => {
});
eventBus.on('peer_version', (ws, body) => {
});
This event is emitted when Hub sends message about new wallet version.
eventBus.on('new_version', (ws, body) => {
});
eventBus.on('receivedPushProjectNumber', (ws, body) => {
});
eventBus.on('client_logged_in', (ws) => {
});
eventBus.on("message_from_hub", (ws, subject, body) => {
});
eventBus.on("message_for_light", (ws, subject, body) => {
});
This event is emitted when wallet updated rates that they got from Hub.
const network = require('ocore/network.js');
eventBus.on("rates_updated", () => {
console.log(JSON.stringify(network.exchangeRates, null, 2));
});
eventBus.on('peer_sent_new_message', (ws, objDeviceMessage) => {
});
eventBus.on("enableNotification", (device_address, params) => {
});
eventBus.on("disableNotification", (device_address, params) => {
});
eventBus.on("create_new_wallet", (walletId, wallet_definition_template, arrDeviceAddresses, wallet_name, other_cosigners, is_single_address) => {
});
eventBus.on('wallet_completed', (walletId) => {
});
eventBus.on('wallet_declined', (wallet, rejector_device_address) => {
});
eventBus.on('wallet_approved', (wallet, device_address) => {
});
eventBus.on('new_wallet_address', (address) => {
});
eventBus.on("new_address-" + address, () => {
});
eventBus.on('saved_unit-' + unit, (objJoint) => {
});
This event is emitted when there is a pairing attempt, this enables bot to decide with the code if the pairing code is valid or not. If you would like to accept any pairing code then there is easier solution.
eventBus.on("pairing_attempt", (from_address, pairing_secret) => {
if (pairing_secret == "SOME_SECRET") {
eventBus.emit("paired", from_address, pairing_secret);
}
});
This event is emitted on successful pairing (also when user removed and re-added the bot).
eventBus.on("paired", (from_address, pairing_secret) => {
let device = require('ocore/device.js');
// say hi to anyone who pair with bot
device.sendMessageToDevice(from_address, 'text', 'Hi!');
});
eventBus.on('paired_by_secret-' + body, (from_address) => {
});
eventBus.on("removed_paired_device", (from_address) => {
});
eventBus.on('refresh_light_started', () => {
});
eventBus.on('refresh_light_done', () => {
});
This event is emitted when text message is received by bot.
eventBus.on("text", (from_address, body, message_counter) => {
let device = require('ocore/device.js');
// echo back the same message
device.sendMessageToDevice(from_address, 'text', 'ECHO: '+ body);
});
This event is emitted when object message is received by bot.
eventBus.on("object", (from_address, body, message_counter) => {
let device = require('ocore/device.js');
// echo back the same object back
device.sendMessageToDevice(from_address, 'object', body);
});
eventBus.on("chat_recording_pref", (from_address, body, message_counter) => {
});
eventBus.on("create_new_shared_address", (address_definition_template, assocMemberDeviceAddressesBySigningPaths) => {
});
eventBus.on("signing_request", (objAddress, address, objUnit, assocPrivatePayloads, from_address, signing_path) => {
});
eventBus.on("signature-" + device_address + "-" + address + "-" + signing_path + "-" + buf_to_sign.toString("base64"), (sig) => {
});
eventBus.on('refused_to_sign', (device_address) => {
});
eventBus.on('confirm_on_other_devices', () => {
});
eventBus.on('all_private_payments_handled', (from_address) => {
});
eventBus.on('all_private_payments_handled-' + first_chain_unit, () => {
});
You can add your own communication protocol on top of the Obyte one. See Request example there.
const network = require('ocore/network.js');
eventBus.on('custom_request', function(ws, params, tag) {
var response = 'put response here';
return network.sendResponse(ws, tag, response);
}
You can add your own communication protocol on top of the Obyte one. See JustSaying example there.
eventBus.on('custom_justsaying', function(ws, content) {
};
eventEmitter.once('ready', () => {
console.log("db is now ready");
});
ws.on('error', (error) => {
});