aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api/AsyncSocket.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-06-29 20:51:13 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-06-29 20:51:13 -0700
commit49724e51630410e9a2c99a27ec7963a315f6575e (patch)
treec2802a9d0b71c2d1502e4004497b77f66970e7cf /src/main/java/org/traccar/api/AsyncSocket.java
parent419cc923e428dcd68ca92906bf6511cbd574b8c2 (diff)
downloadtrackermap-server-49724e51630410e9a2c99a27ec7963a315f6575e.tar.gz
trackermap-server-49724e51630410e9a2c99a27ec7963a315f6575e.tar.bz2
trackermap-server-49724e51630410e9a2c99a27ec7963a315f6575e.zip
WebSocket connection keepalive
Diffstat (limited to 'src/main/java/org/traccar/api/AsyncSocket.java')
-rw-r--r--src/main/java/org/traccar/api/AsyncSocket.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/api/AsyncSocket.java b/src/main/java/org/traccar/api/AsyncSocket.java
index b2ff5031a..b1853822d 100644
--- a/src/main/java/org/traccar/api/AsyncSocket.java
+++ b/src/main/java/org/traccar/api/AsyncSocket.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2021 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,6 +64,11 @@ public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.U
}
@Override
+ public void onKeepalive() {
+ sendData(new HashMap<>());
+ }
+
+ @Override
public void onUpdateDevice(Device device) {
Map<String, Collection<?>> data = new HashMap<>();
data.put(KEY_DEVICES, Collections.singletonList(device));
@@ -85,7 +90,7 @@ public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.U
}
private void sendData(Map<String, Collection<?>> data) {
- if (!data.isEmpty() && isConnected()) {
+ if (isConnected()) {
try {
getRemote().sendString(Context.getObjectMapper().writeValueAsString(data), null);
} catch (JsonProcessingException e) {