Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
Added support for MQTT (#765)
Browse files Browse the repository at this point in the history
Added support for MQTT with the existing events and messages.
To listen with mqtt simply change api.listen to api.listenMqtt
  • Loading branch information
HossamMohsen7 authored and Schmavery committed Dec 2, 2019
1 parent 89e9487 commit 22d1424
Show file tree
Hide file tree
Showing 7 changed files with 1,188 additions and 169 deletions.
17 changes: 17 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* [`api.getUserInfo`](#getUserInfo)
* [`api.handleMessageRequest`](#handleMessageRequest)
* [`api.listen`](#listen)
* [`api.listenMqtt`](#listenMqtt)
* [`api.logout`](#logout)
* [`api.markAsRead`](#markAsRead)
* [`api.markAsReadAll`](#markAsReadAll)
Expand Down Expand Up @@ -1308,6 +1309,22 @@ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, ap

---------------------------------------

<a name="listenMqtt"></a>
### api.listenMqtt(callback) (Experimental)
Same as [`api.listen`](#listen) but uses MQTT to recieve data.

Will call `callback` when a new message is received on this account.
By default this won't receive events (joining/leaving a chat, title change etc...) but it can be activated with `api.setOptions({listenEvents: true})`. This will by default ignore messages sent by the current account, you can enable listening to your own messages with `api.setOptions({selfListen: true})`. This returns `stopListening` that will stop the `listen` loop and is guaranteed to prevent any future calls to the callback given to `listenMqtt`. An immediate call to `stopListening` when an error occurs will prevent the listen function to continue.


__Arguments__

- `callback(error, message)`: A callback called every time the logged-in account receives a new message.

Messages and Events are the same as [`api.listen`](#listen)

---------------------------------------

<a name="logout"></a>
### api.logout([callback])

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function buildAPI(globalOptions, html, jar) {
'getUserInfo',
'handleMessageRequest',
'listen',
'listenMqtt',
'logout',
'markAsRead',
'markAsReadAll',
Expand Down
Loading

0 comments on commit 22d1424

Please sign in to comment.