diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/BaseProtocolDecoder.java | 27 | ||||
-rw-r--r-- | src/org/traccar/ExtendedObjectDecoder.java | 5 | ||||
-rw-r--r-- | src/org/traccar/web/WebServer.java | 2 |
3 files changed, 27 insertions, 7 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index ea0905bf2..8748a9be6 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -23,6 +23,7 @@ import org.traccar.model.Position; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -165,13 +166,31 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } @Override - protected void onMessageEvent(Channel channel, SocketAddress remoteAddress, Object msg) { + protected void onMessageEvent( + Channel channel, SocketAddress remoteAddress, Object originalMessage, Object decodedMessage) { if (Context.getStatisticsManager() != null) { Context.getStatisticsManager().registerMessageReceived(); } - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); - if (deviceSession != null) { - Context.getConnectionManager().updateDevice(deviceSession.getDeviceId(), Device.STATUS_ONLINE, new Date()); + Position position = null; + if (decodedMessage != null) { + if (decodedMessage instanceof Position) { + position = (Position) decodedMessage; + } else if (decodedMessage instanceof Collection) { + Collection positions = (Collection) decodedMessage; + if (!positions.isEmpty()) { + position = (Position) positions.iterator().next(); + } + } + } + if (position != null) { + Context.getConnectionManager().updateDevice( + position.getDeviceId(), Device.STATUS_ONLINE, new Date()); + } else { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession != null) { + Context.getConnectionManager().updateDevice( + deviceSession.getDeviceId(), Device.STATUS_ONLINE, new Date()); + } } } diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java index ec03afa60..268e6f688 100644 --- a/src/org/traccar/ExtendedObjectDecoder.java +++ b/src/org/traccar/ExtendedObjectDecoder.java @@ -56,7 +56,7 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler { MessageEvent e = (MessageEvent) evt; Object originalMessage = e.getMessage(); Object decodedMessage = decode(e.getChannel(), e.getRemoteAddress(), originalMessage); - onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage); // call after decode + onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage, decodedMessage); if (originalMessage == decodedMessage) { ctx.sendUpstream(evt); } else { @@ -77,7 +77,8 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler { } } - protected void onMessageEvent(Channel channel, SocketAddress remoteAddress, Object msg) { + protected void onMessageEvent( + Channel channel, SocketAddress remoteAddress, Object originalMessage, Object decodedMessage) { } protected Object handleEmptyMessage(Channel channel, SocketAddress remoteAddress, Object msg) { diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index 8201f8d16..4dd37f4cc 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -102,7 +102,7 @@ public class WebServer { ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase(config.getString("web.path")); if (config.getBoolean("web.debug")) { - resourceHandler.setWelcomeFiles(new String[] {"debug.html"}); + resourceHandler.setWelcomeFiles(new String[] {"debug.html", "index.html"}); resourceHandler.setMinMemoryMappedContentLength(-1); // avoid locking files on Windows } else { resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"}); |