aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/notificators
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-07-12 09:45:09 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-07-12 09:45:09 -0700
commit4f6e68ad5a14b128258e68fd819406dbea585d7f (patch)
tree7bed07184154f7f637576b3cd617a2edc568e817 /src/main/java/org/traccar/notificators
parentde45d40884d58e4d0e2b2a65b8827bb35634894e (diff)
downloadtraccar-server-4f6e68ad5a14b128258e68fd819406dbea585d7f.tar.gz
traccar-server-4f6e68ad5a14b128258e68fd819406dbea585d7f.tar.bz2
traccar-server-4f6e68ad5a14b128258e68fd819406dbea585d7f.zip
Add Traccar push notificator
Diffstat (limited to 'src/main/java/org/traccar/notificators')
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorFirebase.java18
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTraccar.java13
2 files changed, 25 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java
index 75d325de2..8a3deee92 100644
--- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java
+++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 2020 Anton Tananaev (anton@traccar.org)
* Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,9 +32,8 @@ public class NotificatorFirebase extends Notificator {
private static final Logger LOGGER = LoggerFactory.getLogger(NotificatorFirebase.class);
- private static final String URL = "https://fcm.googleapis.com/fcm/send";
-
- private String key;
+ private final String url;
+ private final String key;
public static class Notification {
@JsonProperty("body")
@@ -49,7 +48,14 @@ public class NotificatorFirebase extends Notificator {
}
public NotificatorFirebase() {
- key = Context.getConfig().getString("notificator.firebase.key");
+ this(
+ "https://fcm.googleapis.com/fcm/send",
+ Context.getConfig().getString("notificator.firebase.key"));
+ }
+
+ protected NotificatorFirebase(String url, String key) {
+ this.url = url;
+ this.key = key;
}
@Override
@@ -64,7 +70,7 @@ public class NotificatorFirebase extends Notificator {
message.tokens = user.getString("notificationTokens").split("[, ]");
message.notification = notification;
- Context.getClient().target(URL).request()
+ Context.getClient().target(url).request()
.header("Authorization", "key=" + key)
.async().post(Entity.json(message), new InvocationCallback<Object>() {
@Override
diff --git a/src/main/java/org/traccar/notificators/NotificatorTraccar.java b/src/main/java/org/traccar/notificators/NotificatorTraccar.java
new file mode 100644
index 000000000..2b75d60e4
--- /dev/null
+++ b/src/main/java/org/traccar/notificators/NotificatorTraccar.java
@@ -0,0 +1,13 @@
+package org.traccar.notificators;
+
+import org.traccar.Context;
+
+public class NotificatorTraccar extends NotificatorFirebase {
+
+ public NotificatorTraccar() {
+ super(
+ "https://www.traccar.org/push/",
+ Context.getConfig().getString("notificator.traccar.key"));
+ }
+
+}