Skip to content
CheshireCaat edited this page Sep 9, 2023 · 8 revisions

Subscribe to script events

You can subscribe to certain events that come from the script. Events can be very different - new messages in the log, notifications about the start and stop of threads and browsers etc.

To do this, you can add event handler using client.on('messageReceived', listener):

const BasRemoteClient = require('bas-remote-node');

const client = new BasRemoteClient({scriptName: 'TestRemoteControl'});

// Add event handler for log messages.
client.on('messageReceived', ({ type, data }) => {
    // Process only log event.
    if (type === 'log') {
        // Retrieve log text.
        const { text } = data;

        // Output text to the console.
        console.log(`[Log] - ${text}`);
    }
});

// Add event handler for threads.
client.on('messageReceived', ({ type, data }) => {
    if (type === 'thread_start') {
        console.log('[Thread] - started');
    }
    if (type === 'thread_end') {
        console.log('[Thread] - ended');
    }
});

await client.start();
// Perform any actions here.
Clone this wiki locally