aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/BasePipelineFactory.java2
-rw-r--r--src/main/java/org/traccar/handler/events/BaseEventHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/events/MediaEventHandler.java47
-rw-r--r--src/main/java/org/traccar/model/Event.java3
4 files changed, 51 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/BasePipelineFactory.java b/src/main/java/org/traccar/BasePipelineFactory.java
index 915c3f7ea..fb48f81d1 100644
--- a/src/main/java/org/traccar/BasePipelineFactory.java
+++ b/src/main/java/org/traccar/BasePipelineFactory.java
@@ -49,6 +49,7 @@ import org.traccar.handler.events.FuelDropEventHandler;
import org.traccar.handler.events.GeofenceEventHandler;
import org.traccar.handler.events.IgnitionEventHandler;
import org.traccar.handler.events.MaintenanceEventHandler;
+import org.traccar.handler.events.MediaEventHandler;
import org.traccar.handler.events.MotionEventHandler;
import org.traccar.handler.events.OverspeedEventHandler;
@@ -141,6 +142,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
ComputedAttributesHandler.class,
WebDataHandler.class,
DefaultDataHandler.class,
+ MediaEventHandler.class,
CommandResultEventHandler.class,
OverspeedEventHandler.class,
BehaviorEventHandler.class,
diff --git a/src/main/java/org/traccar/handler/events/BaseEventHandler.java b/src/main/java/org/traccar/handler/events/BaseEventHandler.java
index f7199f6dc..271aaa35d 100644
--- a/src/main/java/org/traccar/handler/events/BaseEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/BaseEventHandler.java
@@ -36,7 +36,7 @@ public abstract class BaseEventHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
Map<Event, Position> events = analyzePosition(position);
- if (events != null) {
+ if (events != null && !events.isEmpty()) {
notificationManager.updateEvents(events);
}
return position;
diff --git a/src/main/java/org/traccar/handler/events/MediaEventHandler.java b/src/main/java/org/traccar/handler/events/MediaEventHandler.java
new file mode 100644
index 000000000..5b9013fad
--- /dev/null
+++ b/src/main/java/org/traccar/handler/events/MediaEventHandler.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.handler.events;
+
+import io.netty.channel.ChannelHandler;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
+
+import javax.inject.Inject;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@ChannelHandler.Sharable
+public class MediaEventHandler extends BaseEventHandler {
+
+ @Inject
+ public MediaEventHandler() {
+ }
+
+ @Override
+ protected Map<Event, Position> analyzePosition(Position position) {
+ return Stream.of(Position.KEY_IMAGE, Position.KEY_VIDEO, Position.KEY_AUDIO)
+ .filter(position::hasAttribute)
+ .map(type -> {
+ Event event = new Event(Event.TYPE_MEDIA, position);
+ event.set("media", type);
+ event.set("file", position.getString(type));
+ return event;
+ })
+ .collect(Collectors.toMap(event -> event, event -> position));
+ }
+
+}
diff --git a/src/main/java/org/traccar/model/Event.java b/src/main/java/org/traccar/model/Event.java
index 6e3953fda..f00a0e5f1 100644
--- a/src/main/java/org/traccar/model/Event.java
+++ b/src/main/java/org/traccar/model/Event.java
@@ -62,10 +62,9 @@ public class Event extends Message {
public static final String TYPE_IGNITION_OFF = "ignitionOff";
public static final String TYPE_MAINTENANCE = "maintenance";
-
public static final String TYPE_TEXT_MESSAGE = "textMessage";
-
public static final String TYPE_DRIVER_CHANGED = "driverChanged";
+ public static final String TYPE_MEDIA = "media";
private Date eventTime;