Skip to content

Commit 667bb5b

Browse files
author
Kwon Hyungjoo
committed
Add new methods, property and the test.
Change handelMessage into method. Add reconnecting property, getLastMessageId and removeOutgoingMessage methods because it is on MQTT.js API document. Add new test using getLastMessageId.
1 parent 199609d commit 667bb5b

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

index.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@ class AsyncClient {
99
this._client = client;
1010
}
1111

12-
set handleMessage (newHandler) {
13-
this._client.handleMessage = newHandler;
14-
}
15-
16-
get handleMessage () {
17-
return this._client.handleMessage;
18-
}
19-
2012
get connected () {
2113
return this._client.connected;
2214
}
2315

16+
get reconnecting () {
17+
return this._client.reconnecting;
18+
}
19+
2420
publish (...args) {
2521
return new Promise((resolve, reject) => {
2622
this._client.publish(...args, (err, result) => {
@@ -69,10 +65,18 @@ class AsyncClient {
6965
return this._client.eventNames(...args);
7066
}
7167

68+
getLastMessageId (...args) {
69+
return this._client.getLastMessageId(...args);
70+
}
71+
7272
getMaxListeners (...args) {
7373
return this._client.getMaxListeners(...args);
7474
}
7575

76+
handleMessage (...args) {
77+
return this._client.handleMessage(...args);
78+
}
79+
7680
listenerCount (...args) {
7781
return this._client.listenerCount(...args);
7882
}
@@ -101,6 +105,10 @@ class AsyncClient {
101105
return this._client.prependOnceListener(...args);
102106
}
103107

108+
rawListeners (...args) {
109+
return this._client.rawListeners(...args);
110+
}
111+
104112
removeAllListeners (...args) {
105113
return this._client.removeAllListeners(...args);
106114
}
@@ -109,13 +117,14 @@ class AsyncClient {
109117
return this._client.removeListener(...args);
110118
}
111119

120+
removeOutgoingMessage (...args) {
121+
return this._client.removeOutgoingMessage(...args);
122+
}
123+
112124
setMaxListeners (...args) {
113125
return this._client.setMaxListeners(...args);
114126
}
115127

116-
rawListeners (...args) {
117-
return this._client.rawListeners(...args);
118-
}
119128
}
120129

121130

test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ function runTests () {
104104
return client.end();
105105
});
106106
});
107+
108+
test('Calling getLastMessageId should return number after published', t => {
109+
t.plan(1);
110+
111+
const client = AsyncMQTT.connect(SERVER_URL);
112+
113+
client.publish('example', 'test', {
114+
qos: 1
115+
}).then(() => {
116+
t.ok('number' === typeof client.getLastMessageId(), 'Message id is number');
117+
return client.end();
118+
});
119+
});
107120
}
108121

109122
// Taken from MQTT.js tests

0 commit comments

Comments
 (0)