1
0

Push service release version 4

This commit is contained in:
2020-12-25 01:10:32 +01:00
parent 4c58aa3ed0
commit 02fa209012
7 changed files with 43 additions and 29 deletions

View File

@@ -17,7 +17,7 @@
<groupId>de.77zzcx7.push-service</groupId> <groupId>de.77zzcx7.push-service</groupId>
<artifactId>push-service-parent</artifactId> <artifactId>push-service-parent</artifactId>
<version>4-SNAPSHOT</version> <version>4</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<description>A micro service to send push notifications</description> <description>A micro service to send push notifications</description>
<name>push-service-parent</name> <name>push-service-parent</name>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<artifactId>push-service-parent</artifactId> <artifactId>push-service-parent</artifactId>
<groupId>de.77zzcx7.push-service</groupId> <groupId>de.77zzcx7.push-service</groupId>
<version>4-SNAPSHOT</version> <version>4</version>
</parent> </parent>
<artifactId>push-service-client-lib</artifactId> <artifactId>push-service-client-lib</artifactId>
@@ -42,11 +42,7 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration> <configuration>
<!-- <skip>true</skip>
Setting the classifier of the spring-boot uber JAR to exec will keep the verbatim JAR file
as actual distributed artifact required for users to include the beans
-->
<classifier>exec</classifier>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@@ -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);
}
}

View File

@@ -18,6 +18,7 @@ public class PayloadDto {
private String icon; private String icon;
private int[] vibration; private int[] vibration;
private long timestamp; private long timestamp;
private String tag;
public PayloadDto(String title) { public PayloadDto(String title) {
this.title = title; this.title = title;
@@ -67,4 +68,12 @@ public class PayloadDto {
public String toString() { public String toString() {
return ReflectionToStringBuilder.toString(this); return ReflectionToStringBuilder.toString(this);
} }
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
} }

View File

@@ -9,6 +9,27 @@ self.addEventListener('push', function(event) {
icon: payload.icon, icon: payload.icon,
vibrate: payload.vibration, vibrate: payload.vibration,
timestamp: payload.timestamp, 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);
}
}));
}); });

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<artifactId>push-service-parent</artifactId> <artifactId>push-service-parent</artifactId>
<groupId>de.77zzcx7.push-service</groupId> <groupId>de.77zzcx7.push-service</groupId>
<version>4-SNAPSHOT</version> <version>4</version>
</parent> </parent>
<artifactId>push-service-server</artifactId> <artifactId>push-service-server</artifactId>

View File

@@ -59,6 +59,13 @@ public class ExternalPushServiceResponseHandler {
updateSubscription(subscription); updateSubscription(subscription);
break; 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 case 404: // Not found
// Subscription expired or endpoint is wrong -> subscription needs to be removed // Subscription expired or endpoint is wrong -> subscription needs to be removed
LOGGER.info(String.format("Received 404 for endpoint %s", subscription.getEndpoint())); LOGGER.info(String.format("Received 404 for endpoint %s", subscription.getEndpoint()));
@@ -80,6 +87,8 @@ public class ExternalPushServiceResponseHandler {
updateSubscription(subscription); updateSubscription(subscription);
break; break;
default: default:
LOGGER.error(String.format("Unhandled HTTP response code: %s for endpoint %s",
response.getStatusLine().getStatusCode(), subscription.getEndpoint()));
} }
} catch (InterruptedException ire) { } catch (InterruptedException ire) {
LOGGER.error(String.format("Thread interrupted for endpoint %s", subscription.getEndpoint())); LOGGER.error(String.format("Thread interrupted for endpoint %s", subscription.getEndpoint()));