Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contact_change_state event. #722

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ class Client extends EventEmitter {
this.emit(Events.BATTERY_CHANGED, { battery, plugged });
});

await page.exposeFunction('onChatStateChangedEvent', (state) => {
/**
* Emitted when the chat changes its state
* @event Client#contact_change_state
* @param {string} {COMPOSING|RECORDING|AVAILABLE} Indicates state of chat.
* COMPOSING - contact composing message.
* RECORDING - contact recording audio message.
* AVAILABLE - contact stops composing/recording and available
* @param {object} Object containing Contact ID
*/
this.emit(Events.CONTACT_STATE_CHANGED, state.type.toUpperCase(), state.id);
});

await page.evaluate(() => {
window.Store.Msg.on('add', (msg) => { if (msg.isNewMsg) window.onAddMessageEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
Expand All @@ -379,6 +392,7 @@ class Client extends EventEmitter {
window.Store.Msg.on('remove', (msg) => { if (msg.isNewMsg) window.onRemoveMessageEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); });
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
window.Store.Presence.on('change:chatstate.type', (state) => { window.onChatStateChangedEvent(state); });
});

/**
Expand Down
3 changes: 2 additions & 1 deletion src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ exports.Events = {
QR_RECEIVED: 'qr',
DISCONNECTED: 'disconnected',
STATE_CHANGED: 'change_state',
BATTERY_CHANGED: 'change_battery'
BATTERY_CHANGED: 'change_battery',
CONTACT_STATE_CHANGED: 'contact_change_state'
};

/**
Expand Down