Skip to content

Commit c702833

Browse files
committed
maint(push kit): Remove unused desktop notification code. Use pat-push instead.
1 parent ef00c42 commit c702833

File tree

1 file changed

+2
-55
lines changed

1 file changed

+2
-55
lines changed

src/core/push_kit.js

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* This pattern expects the following meta tags to be available in the page to get the necessary configuration
2525
* - patterns-push-url containing a url pointing to a message queue server. Eg. ws://127.0.0.1:15674/ws
26-
* - patterns-push-exchange-base-name containing a text prefix. It will append _event and _notification to that prefix and attempt to contact these two message exchanges.
26+
* - patterns-push-exchange containing the exchange nanem to subscribe to.
2727
* - patterns-push-filter containing a topic filter including dot-seperated namespaces and wildcards. A commonly used filter value would be the currently logged in user. This will subscribe only to updates for this specific user.
2828
* - patterns-push-login containing the name of a read only user on the message queue server used to connect.
2929
* - patterns-push-password containing the password of a read only user on the message queue server used to connect.
@@ -37,14 +37,12 @@ const push_kit = {
3737
async init() {
3838
const url = document.querySelector("meta[name=patterns-push-url]")?.content;
3939
const exchange = document.querySelector("meta[name=patterns-push-exchange]")?.content; // prettier-ignore
40-
const exchange_notification = document.querySelector("meta[name=patterns-notification-exchange]")?.content; // prettier-ignore
4140

42-
if (!url || (!exchange && !exchange_notification)) {
41+
if (!url || !exchange) {
4342
return;
4443
}
4544

4645
const topicfilter = document.querySelector("meta[name=patterns-push-filter]")?.content; // prettier-ignore
47-
const topicfilter_notification = document.querySelector("meta[name=patterns-notification-filter]")?.content; // prettier-ignore
4846
const user_login = document.querySelector("meta[name=patterns-push-login]")?.content; // prettier-ignore
4947
const user_pass = document.querySelector("meta[name=patterns-push-password]")?.content; // prettier-ignore
5048

@@ -70,15 +68,6 @@ const push_kit = {
7068
this.on_push_marker.bind(this)
7169
);
7270
}
73-
if (exchange_notification) {
74-
// TODO: should we distinguish for desktop notifications via routing_key.
75-
// TODO: check following:
76-
// Only one subscription per connection is allowed. Otherwise the connection will terminate right away again.
77-
client.subscribe(
78-
`/exchange/${exchange_notification}/${topicfilter_notification}.#`,
79-
this.on_desktop_notification.bind(this)
80-
);
81-
}
8271
};
8372

8473
client.onStompError = (frame) => {
@@ -99,48 +88,6 @@ const push_kit = {
9988
new CustomEvent("push", { detail: { body: message.body } })
10089
);
10190
},
102-
103-
on_desktop_notification(message) {
104-
logger.debug("Received desktop notification: ", message);
105-
if (!message || !message.body) {
106-
return;
107-
}
108-
this.create_notification(message.body);
109-
},
110-
111-
create_notification(text) {
112-
const img = document.querySelector("meta[name=desktop-notification-image]")?.content; // prettier-ignore
113-
114-
// Let's check if the browser supports notifications
115-
if (!("Notification" in window)) {
116-
logger.error("This browser does not support notifications.");
117-
return;
118-
}
119-
120-
// If not yet permitted, we need to ask the user for permission.
121-
// Note, Chrome does not implement the permission static property
122-
// So we have to check for NOT 'denied' instead of 'default'
123-
if (!(Notification.permission in ["denied", "granted"])) {
124-
Notification.requestPermission((permission) => {
125-
// Whatever the user answers, we make sure Chrome stores the information
126-
if (!("permission" in Notification)) {
127-
Notification.permission = permission;
128-
}
129-
});
130-
}
131-
132-
// Let's check if the user is okay to get some notification
133-
if (Notification.permission === "granted") {
134-
// If it's okay let's create a notification
135-
const message = {
136-
body: text,
137-
};
138-
if (img) {
139-
message.icon = img;
140-
}
141-
new Notification("Update", message);
142-
}
143-
},
14491
};
14592

14693
push_kit.init();

0 commit comments

Comments
 (0)