aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-06-03 10:57:09 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-06-03 10:57:09 +1200
commit9ecabbef669cbd1a91490f4872d4c220b54e37a4 (patch)
tree7d2afe2b865dc5f9f10faa5ce7d213a219afa82a /src
parent06a746b44dae69b0c84a5302f92a1bcbe2dc827f (diff)
parent0271fa29703f24df24756c117209b9b04e127fc3 (diff)
downloadtrackermap-server-9ecabbef669cbd1a91490f4872d4c220b54e37a4.tar.gz
trackermap-server-9ecabbef669cbd1a91490f4872d4c220b54e37a4.tar.bz2
trackermap-server-9ecabbef669cbd1a91490f4872d4c220b54e37a4.zip
Merge pull request #1992 from Abyss777/master
Show events in web interface with toasts
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BaseEventHandler.java2
-rw-r--r--src/org/traccar/api/AsyncSocket.java30
-rw-r--r--src/org/traccar/database/ConnectionManager.java8
3 files changed, 27 insertions, 13 deletions
diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java
index fde57748c..3e3317f0a 100644
--- a/src/org/traccar/BaseEventHandler.java
+++ b/src/org/traccar/BaseEventHandler.java
@@ -25,7 +25,7 @@ public abstract class BaseEventHandler extends BaseDataHandler {
Event event = analizePosition(position);
if (event != null) {
- Context.getConnectionManager().updateEvent(event);
+ Context.getConnectionManager().updateEvent(event, position);
}
return position;
}
diff --git a/src/org/traccar/api/AsyncSocket.java b/src/org/traccar/api/AsyncSocket.java
index 2259f840f..d1e5594f4 100644
--- a/src/org/traccar/api/AsyncSocket.java
+++ b/src/org/traccar/api/AsyncSocket.java
@@ -28,6 +28,8 @@ import javax.json.Json;
import javax.json.JsonObjectBuilder;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.UpdateListener {
@@ -45,7 +47,9 @@ public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.U
public void onWebSocketConnect(Session session) {
super.onWebSocketConnect(session);
- sendData(KEY_POSITIONS, Context.getConnectionManager().getInitialState(userId));
+ Map<String, Collection<?>> data = new HashMap<>();
+ data.put(KEY_POSITIONS, Context.getConnectionManager().getInitialState(userId));
+ sendData(data);
Context.getConnectionManager().addListener(userId, this);
}
@@ -59,25 +63,35 @@ public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.U
@Override
public void onUpdateDevice(Device device) {
- sendData(KEY_DEVICES, Collections.singletonList(device));
+ Map<String, Collection<?>> data = new HashMap<>();
+ data.put(KEY_DEVICES, Collections.singletonList(device));
+ sendData(data);
}
@Override
public void onUpdatePosition(Position position) {
- sendData(KEY_POSITIONS, Collections.singletonList(position));
+ Map<String, Collection<?>> data = new HashMap<>();
+ data.put(KEY_POSITIONS, Collections.singletonList(position));
+ sendData(data);
}
@Override
- public void onUpdateEvent(Event event) {
- sendData(KEY_EVENTS, Collections.singletonList(event));
+ public void onUpdateEvent(Event event, Position position) {
+ Map<String, Collection<?>> data = new HashMap<>();
+ data.put(KEY_EVENTS, Collections.singletonList(event));
+ if (position != null) {
+ data.put(KEY_POSITIONS, Collections.singletonList(position));
+ }
+ sendData(data);
}
- private void sendData(String key, Collection<?> data) {
+ private void sendData(Map<String, Collection<?>> data) {
if (!data.isEmpty() && isConnected()) {
JsonObjectBuilder json = Json.createObjectBuilder();
- json.add(key, JsonConverter.arrayToJson(data));
+ for (Map.Entry<String, Collection<?>> entry : data.entrySet()) {
+ json.add(entry.getKey(), JsonConverter.arrayToJson(entry.getValue()));
+ }
getRemote().sendString(json.build().toString(), null);
}
}
-
}
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index 9e0da8485..ec5903548 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -94,7 +94,7 @@ public class ConnectionManager {
if (status.equals(Device.STATUS_ONLINE)) {
event.setType(Event.TYPE_DEVICE_ONLINE);
}
- updateEvent(event);
+ updateEvent(event, null);
}
device.setStatus(status);
@@ -147,7 +147,7 @@ public class ConnectionManager {
}
}
- public synchronized void updateEvent(Event event) {
+ public synchronized void updateEvent(Event event, Position position) {
long deviceId = event.getDeviceId();
try {
Context.getDataManager().addEvent(event);
@@ -157,7 +157,7 @@ public class ConnectionManager {
for (long userId : Context.getPermissionsManager().getDeviceUsers(deviceId)) {
if (listeners.containsKey(userId)) {
for (UpdateListener listener : listeners.get(userId)) {
- listener.onUpdateEvent(event);
+ listener.onUpdateEvent(event, position);
}
}
}
@@ -183,7 +183,7 @@ public class ConnectionManager {
public interface UpdateListener {
void onUpdateDevice(Device device);
void onUpdatePosition(Position position);
- void onUpdateEvent(Event event);
+ void onUpdateEvent(Event event, Position position);
}
public synchronized void addListener(long userId, UpdateListener listener) {