Skip to content

Commit f932a03

Browse files
committed
Refactored Java code
Fixed bug of not working qos and retain options on send message
1 parent 983d25d commit f932a03

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

android/src/main/java/com/tuanpm/RCTMqtt/RCTMqtt.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public void onSuccess(IMqttToken asyncActionToken)
302302
public void onFailure(IMqttToken asyncActionToken,
303303
Throwable exception)
304304
{
305-
log("Disconnect failed" + exception);
305+
log(new StringBuilder("Disconnect failed").append(exception).toString());
306306
}
307307
};
308308

@@ -349,8 +349,6 @@ public void onFailure(IMqttToken asyncActionToken,
349349
}
350350

351351
/**
352-
* TODO: WTF!? why don't use qos and retain
353-
*
354352
* @param topic
355353
* @param payload
356354
* @param qos
@@ -361,11 +359,12 @@ public void publish(final String topic,
361359
final int qos,
362360
final boolean retain)
363361
{
364-
byte[] encodedPayload;
365362
try
366363
{
367-
encodedPayload = payload.getBytes("UTF-8");
364+
byte[] encodedPayload = payload.getBytes("UTF-8");
368365
MqttMessage message = new MqttMessage(encodedPayload);
366+
message.setQos(qos);
367+
message.setRetained(retain);
369368
client.publish(topic, message);
370369
}
371370
catch (UnsupportedEncodingException | MqttException e)
@@ -386,7 +385,7 @@ public void connectionLost(Throwable cause)
386385
// Called when the connection to the server has been lost.
387386
// An application may choose to implement reconnection
388387
// logic at this point. This sample simply exits.
389-
log("Connection to lost! " + cause);
388+
log(new StringBuilder("Connection to lost! ").append(cause).toString());
390389
WritableMap params = Arguments.createMap();
391390
params.putString("event", "closed");
392391
params.putString("message", "Connection to lost!");

android/src/main/java/com/tuanpm/RCTMqtt/RCTMqttModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public RCTMqttModule(ReactApplicationContext reactContext)
2828
{
2929
super(reactContext);
3030
_reactContext = reactContext;
31-
clients = new HashMap<Integer, RCTMqtt>();
31+
clients = new HashMap<>();
3232
}
3333

3434
public static int randInt(int min,

0 commit comments

Comments
 (0)