From 7cafeae1c64c9436401964b4e2e2636b63d276c1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 20 Jan 2023 10:41:42 +0100 Subject: [PATCH] NS 15 support --- plugins/sync/build.gradle | 5 +---- .../sync/nsclient/services/NSClientService.kt | 22 +++++-------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/plugins/sync/build.gradle b/plugins/sync/build.gradle index 2cbb59d236..1194a86950 100644 --- a/plugins/sync/build.gradle +++ b/plugins/sync/build.gradle @@ -32,10 +32,7 @@ dependencies { testImplementation project(':plugins:aps') // NSClient, Tidepool - api("io.socket:socket.io-client:1.0.2") { - // excluding org.json which is provided by Android - exclude group: "org.json", module: "json" - } + api("io.socket:socket.io-client:2.1.0") api "com.squareup.okhttp3:okhttp:$okhttp3_version" api "com.squareup.okhttp3:logging-interceptor:$okhttp3_version" //api "com.squareup.retrofit2:retrofit:$retrofit2_version" diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/services/NSClientService.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/services/NSClientService.kt index e4a5df6141..24aeeaec0b 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/services/NSClientService.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/services/NSClientService.kt @@ -49,6 +49,7 @@ import info.nightscout.rx.events.EventConfigBuilderChange import info.nightscout.rx.events.EventDismissNotification import info.nightscout.rx.events.EventNSClientNewLog import info.nightscout.rx.events.EventNSClientRestart +import info.nightscout.rx.events.EventNewHistoryData import info.nightscout.rx.events.EventPreferenceChange import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag @@ -165,6 +166,10 @@ class NSClientService : DaggerService() { .toObservable(NSAuthAck::class.java) .observeOn(aapsSchedulers.io) .subscribe({ ack -> processAuthAck(ack) }, fabricPrivacy::logException) + disposable += rxBus + .toObservable(EventNewHistoryData::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ resend("NEW_DATA") }, fabricPrivacy::logException) } override fun onDestroy() { @@ -231,10 +236,6 @@ class NSClientService : DaggerService() { socket = IO.socket(nsURL, opt).also { socket -> socket.on(Socket.EVENT_CONNECT, onConnect) socket.on(Socket.EVENT_DISCONNECT, onDisconnect) - socket.on(Socket.EVENT_ERROR, onError) - socket.on(Socket.EVENT_CONNECT_ERROR, onError) - socket.on(Socket.EVENT_CONNECT_TIMEOUT, onError) - socket.on(Socket.EVENT_PING, onPing) rxBus.send(EventNSClientNewLog("NSCLIENT", "do connect")) socket.connect() socket.on("dataUpdate", onDataUpdate) @@ -300,7 +301,6 @@ class NSClientService : DaggerService() { @Synchronized fun destroy() { socket?.off(Socket.EVENT_CONNECT) socket?.off(Socket.EVENT_DISCONNECT) - socket?.off(Socket.EVENT_PING) socket?.off("dataUpdate") socket?.off("announcement") socket?.off("alarm") @@ -336,18 +336,6 @@ class NSClientService : DaggerService() { nsDevice = sp.getString("careportal_enteredby", "") } - private val onError = Emitter.Listener { args -> - var msg = "Unknown Error" - if (args.isNotEmpty() && args[0] != null) { - msg = args[0].toString() - } - rxBus.send(EventNSClientNewLog("ERROR", msg)) - } - private val onPing = Emitter.Listener { - rxBus.send(EventNSClientNewLog("PING", "received")) - // send data if there is something waiting - resend("Ping received") - } private val onAnnouncement = Emitter.Listener { args -> /*