Skip to content

Commit 5658191

Browse files
committed
Fix update token
1 parent 44d5793 commit 5658191

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

arduino-iot-client-mqtt/arduino-iot-client-mqtt.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ class ArduinoClientMqtt {
234234

235235
// Re-subscribe to all topics subscribed before the reconnection
236236
Object.values(this.subscribedTopics).forEach((subscribeParams) => {
237-
subscribe(subscribeParams.topic, subscribeParams.cb);
237+
this.subscribe(subscribeParams.topic, subscribeParams.cb);
238238
});
239239

240-
if (typeof this.connectionOptions.onConnected === 'function') {
240+
if (typeof this.opts.onConnected === 'function') {
241241
// Call the connection callback (with the reconnection param set to true)
242-
this.connectionOptions.onConnected(true);
242+
this.opts.onConnected(true);
243243
}
244244

245245
// Exit the infinite loop

utils/arduino-connection-manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,14 @@ function findUser(clientId) {
175175

176176
async function updateToken(connectionConfig){
177177
try{
178-
var user = findUser(clientId);
178+
var user = findUser(connectionConfig.credentials.clientid);
179179
if(user !== -1){
180180
var tokenInfo= await getToken(connectionConfig);
181181
if(tokenInfo !==undefined){
182182
connections[user].token= tokenInfo.token;
183183
connections[user].expires_token_ts=tokenInfo.expires_in;
184+
connections[user].clientMqtt.updateToken(tokenInfo.token);
185+
connections[user].clientHttp.updateToken(tokenInfo.token);
184186
connections[user].timeoutUpdateToken = setTimeout(() => { updateToken(connectionConfig) }, tokenInfo.expires_in * 1000);
185187
}else{
186188
connections[user].timeoutUpdateToken = setTimeout(() => { updateToken(connectionConfig) }, 1000);

0 commit comments

Comments
 (0)