diff --git a/pom.xml b/pom.xml index c619893..408df04 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ de.77zzcx7.push-service push-service-parent - 4-SNAPSHOT + 4 pom A micro service to send push notifications push-service-parent diff --git a/push-service-client-lib/pom.xml b/push-service-client-lib/pom.xml index f1fe09f..ae2c139 100644 --- a/push-service-client-lib/pom.xml +++ b/push-service-client-lib/pom.xml @@ -7,7 +7,7 @@ push-service-parent de.77zzcx7.push-service - 4-SNAPSHOT + 4 push-service-client-lib @@ -42,11 +42,7 @@ org.springframework.boot spring-boot-maven-plugin - - exec + true diff --git a/push-service-client-lib/src/main/java/de/pushservice/client/PushServiceClientApplication.java b/push-service-client-lib/src/main/java/de/pushservice/client/PushServiceClientApplication.java deleted file mode 100644 index ac96a1c..0000000 --- a/push-service-client-lib/src/main/java/de/pushservice/client/PushServiceClientApplication.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.pushservice.client; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -/** - * Not used but required by the spring boot maven plugin during repackage - */ -@SpringBootApplication -public class PushServiceClientApplication extends SpringBootServletInitializer { - public static void main(String[] args) { - SpringApplication.run(PushServiceClientApplication.class); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(PushServiceClientApplication.class); - } -} \ No newline at end of file diff --git a/push-service-client-lib/src/main/java/de/pushservice/client/dto/PayloadDto.java b/push-service-client-lib/src/main/java/de/pushservice/client/dto/PayloadDto.java index 978d62b..68cdfad 100644 --- a/push-service-client-lib/src/main/java/de/pushservice/client/dto/PayloadDto.java +++ b/push-service-client-lib/src/main/java/de/pushservice/client/dto/PayloadDto.java @@ -18,6 +18,7 @@ public class PayloadDto { private String icon; private int[] vibration; private long timestamp; + private String tag; public PayloadDto(String title) { this.title = title; @@ -67,4 +68,12 @@ public class PayloadDto { public String toString() { return ReflectionToStringBuilder.toString(this); } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/push-service-client-lib/src/main/resources/static/push-service-client-service-worker.js b/push-service-client-lib/src/main/resources/static/push-service-client-service-worker.js index 658be18..06de934 100644 --- a/push-service-client-lib/src/main/resources/static/push-service-client-service-worker.js +++ b/push-service-client-lib/src/main/resources/static/push-service-client-service-worker.js @@ -9,6 +9,27 @@ self.addEventListener('push', function(event) { icon: payload.icon, vibrate: payload.vibration, timestamp: payload.timestamp, + tag: payload.tag }) ); +}); + +self.addEventListener('notificationclick', function(event) { + event.notification.close(); + + event.waitUntil(clients.matchAll({ + type: "window" + }).then(function(clientList) { + for (var i = 0; i < clientList.length; i++) { + var client = clientList[i]; + + if (client.url.includes(new URL(self.registration.scope).pathname) && 'focus' in client) { + return client.focus(); + } + } + + if (clients.openWindow) { + return clients.openWindow(new URL(self.registration.scope).pathname); + } + })); }); \ No newline at end of file diff --git a/push-service-server/pom.xml b/push-service-server/pom.xml index 6fa3d75..4800ee4 100644 --- a/push-service-server/pom.xml +++ b/push-service-server/pom.xml @@ -7,7 +7,7 @@ push-service-parent de.77zzcx7.push-service - 4-SNAPSHOT + 4 push-service-server diff --git a/push-service-server/src/main/java/de/pushservice/server/service/ExternalPushServiceResponseHandler.java b/push-service-server/src/main/java/de/pushservice/server/service/ExternalPushServiceResponseHandler.java index 1ac6dc0..ff70de7 100644 --- a/push-service-server/src/main/java/de/pushservice/server/service/ExternalPushServiceResponseHandler.java +++ b/push-service-server/src/main/java/de/pushservice/server/service/ExternalPushServiceResponseHandler.java @@ -59,6 +59,13 @@ public class ExternalPushServiceResponseHandler { updateSubscription(subscription); break; + case 403: // Forbidden + // also "SENDER_ID_MISMATCH" - may happen if the VAPID keys were changed -> subscription needs to be removed + // AND CLIENT NEEDS TO RE-SUBSCRIBE (not sure how to control that from here, though) + LOGGER.error(String.format("Received 403 for endpoint %s", subscription.getEndpoint())); + + deleteSubscription(subscription); + break; case 404: // Not found // Subscription expired or endpoint is wrong -> subscription needs to be removed LOGGER.info(String.format("Received 404 for endpoint %s", subscription.getEndpoint())); @@ -80,6 +87,8 @@ public class ExternalPushServiceResponseHandler { updateSubscription(subscription); break; default: + LOGGER.error(String.format("Unhandled HTTP response code: %s for endpoint %s", + response.getStatusLine().getStatusCode(), subscription.getEndpoint())); } } catch (InterruptedException ire) { LOGGER.error(String.format("Thread interrupted for endpoint %s", subscription.getEndpoint()));