|
|
@@ -12,22 +12,22 @@ import com.grkj.iscs.util.log.LogUtil
|
|
|
object StompApi {
|
|
|
|
|
|
fun refuseStomp(ctx: Context, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
|
|
|
-// stomp(ctx, UrlConsts.MQ_VHOST_REFUSE, "machine.${ctx.serialNo()}", callback)
|
|
|
+ stomp(ctx, "", callback)
|
|
|
}
|
|
|
|
|
|
|
|
|
- private fun stomp(ctx: Context, vhost: String, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
|
|
|
+ private fun stomp(ctx: Context, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
|
|
|
Executor.runOnMain {
|
|
|
ctx.addNetObserver(object : OnceNetObserver() {
|
|
|
override fun onNetAvailable() {
|
|
|
- onNetAvailable(ctx, vhost, destinationInfix, callback)
|
|
|
+ onNetAvailable(ctx, destinationInfix, callback)
|
|
|
ctx.removeNetObserver(this)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun onNetAvailable(ctx: Context, vhost: String, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
|
|
|
+ private fun onNetAvailable(ctx: Context, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
|
|
|
// PlatformRepository(ctx).getPlatformId().observeForever { platformId ->
|
|
|
// if (platformId != null) {
|
|
|
// Authorization.requestToken(ctx) { token ->
|
|
|
@@ -39,26 +39,29 @@ object StompApi {
|
|
|
// LogUtil.w("platformId = null")
|
|
|
// }
|
|
|
// }
|
|
|
+ connectStompServer(ctx, destinationInfix, callback)
|
|
|
}
|
|
|
|
|
|
- private fun connectStompServer(ctx: Context, vhost: String, destinationInfix: String, platformId: String, token: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
|
|
|
+ private fun connectStompServer(ctx: Context, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
|
|
|
LogUtil.i("开始连接 STOMP 服务")
|
|
|
- Stomp.over(OkHttps.webSocket(Constants.WEB_SOCKET).heatbeat(20, 20))
|
|
|
+// Stomp.over(OkHttps.webSocket(Constants.WEB_SOCKET).heatbeat(20, 20))
|
|
|
+ Stomp.over(OkHttps.webSocket(Constants.WEB_SOCKET))
|
|
|
.setOnConnected {
|
|
|
- callback(it, "/p-${platformId}-a.${destinationInfix}")
|
|
|
+ callback(it, "/p--a.${destinationInfix}")
|
|
|
}
|
|
|
.setOnDisconnected {
|
|
|
if (it.code != 1000) {
|
|
|
LogUtil.i("Websockt 已断开:${it.code}: ${it.reason},10 秒后重连...")
|
|
|
Executor.delayOnIO({
|
|
|
- stomp(ctx, vhost, destinationInfix, callback)
|
|
|
+ stomp(ctx, destinationInfix, callback)
|
|
|
}, 10000)
|
|
|
}
|
|
|
}
|
|
|
- .connect(listOf(
|
|
|
- Header("login", token),
|
|
|
- Header("host", vhost)
|
|
|
- ))
|
|
|
+ .connect()
|
|
|
+// .connect(listOf(
|
|
|
+// Header("login", token),
|
|
|
+// Header("host", vhost)
|
|
|
+// ))
|
|
|
}
|
|
|
|
|
|
|