|
@@ -11,10 +11,14 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
|
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
|
|
|
|
|
import cn.org.bjca.trust.android.lib.im.cfg.Constant;
|
|
|
+import cn.org.bjca.trust.android.lib.im.common.json.GsonImplHelp;
|
|
|
+import cn.org.bjca.trust.android.lib.im.im.bean.PacketMessage;
|
|
|
import cn.org.bjca.trust.android.lib.im.im.kit.IMInterface;
|
|
|
import cn.org.bjca.trust.android.lib.im.im.opt.ImConnectOptions;
|
|
|
+import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
|
|
import cn.org.bjca.trust.android.lib.im.kit.IMSDKListener;
|
|
|
import cn.org.bjca.trust.android.lib.im.kit.MsgListener;
|
|
|
+import kotlin.text.Charsets;
|
|
|
|
|
|
public class ImManager implements IMInterface {
|
|
|
private final String TAG = "ImManager";
|
|
@@ -69,10 +73,11 @@ public class ImManager implements IMInterface {
|
|
|
status = 0;
|
|
|
if (reconnect) return;
|
|
|
try {
|
|
|
- mqttClient.subscribe(Constant.getSdkAppID() + "/message" + Constant.getUserId(), 2);
|
|
|
- mqttClient.subscribe(Constant.getSdkAppID() + "/pang" + Constant.getUserId(), 2);
|
|
|
- mqttClient.subscribe(Constant.getSdkAppID() + "/login" + Constant.getUserId(), 2);
|
|
|
- mqttClient.subscribe(Constant.getSdkAppID() + "/data" + Constant.getUserId(), 2);
|
|
|
+ mqttClient.subscribe(Constant.getSdkAppID() + "/message:" + Constant.getUserId(), 2);
|
|
|
+ mqttClient.subscribe(Constant.getSdkAppID() + "/pang:" + Constant.getUserId(), 2);
|
|
|
+ mqttClient.subscribe(Constant.getSdkAppID() + "/connect:" + Constant.getUserId(), 2);
|
|
|
+ mqttClient.subscribe(Constant.getSdkAppID() + "/result:" + Constant.getUserId(), 2);
|
|
|
+ mqttClient.subscribe(Constant.getSdkAppID() + "/notice:" + Constant.getUserId(), 2);
|
|
|
} catch (MqttException e) {
|
|
|
Log.e(TAG, "=====>connectComplete", e);
|
|
|
}
|
|
@@ -87,7 +92,7 @@ public class ImManager implements IMInterface {
|
|
|
|
|
|
@Override
|
|
|
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
|
|
- Log.e("======>messageArrived", topic + "::" + message.getPayload().toString());
|
|
|
+ Log.e("======>messageArrived", topic + "::" + new String(message.getPayload(), Charsets.UTF_8));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -134,4 +139,22 @@ public class ImManager implements IMInterface {
|
|
|
public boolean isConnecting() {
|
|
|
return this.status == 1;
|
|
|
}
|
|
|
+
|
|
|
+ private void sendPacketMessage(PacketMessage message, IMSDKCallback callback) {
|
|
|
+ if (null == connectOptions) {
|
|
|
+ if (null != callback) callback.failed(204, "未登录");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!isConnect() || isConnecting()) {
|
|
|
+ if (null != callback) callback.failed(205, "im未连接");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String msg = GsonImplHelp.get().toJson(message);
|
|
|
+ try {
|
|
|
+ mqttClient.publish("server", msg.getBytes(Charsets.UTF_8), 2, false);
|
|
|
+ } catch (MqttException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|