Skip to content

Commit 2646383

Browse files
authored
Merge pull request #10 from bartbutenaers/Update-web-push-dependency-3.3.2-to-3.4.4
Update web push dependency 3.3.2 to 3.4.4
2 parents 5dd8c94 + 70382b9 commit 2646383

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"email": "[email protected]"
55
},
66
"dependencies": {
7-
"web-push": "3.3.2"
7+
"web-push": "^3.4.5"
88
},
99
"description": "Web Push notifications for Node-RED",
1010
"keywords": [
@@ -28,5 +28,5 @@
2828
"web-push-notification": "web-push-notification.js"
2929
}
3030
},
31-
"version": "0.0.3"
31+
"version": "0.0.4"
3232
}

vapid-configuration.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
publicKey: { value: "", required: true },
77
privateKey: { value: "", required: true },
88
gcmApiKey: { value: "" },
9+
timeout: { value: 0 },
910
name: { value: "" }
1011
},
1112
label: function () {
1213
return this.name || this.subject;
1314
},
1415
oneditprepare: function () {
1516
var node = this;
17+
18+
// Older nodes (version 0.0.3 and below) have no timeout option, so set it to 0 (= no custom timeout)
19+
if (this.timeout == undefined) {
20+
$('#node-config-input-timeout').val(0);
21+
}
1622

1723
$("#node-input-generateKeyPair").click(function () {
1824
if ($("#node-config-input-publicKey").val() || $("#node-config-input-privateKey").val()) {
@@ -61,6 +67,10 @@
6167
<label for="node-config-input-gcmApiKey"><i class="icon-tag"></i> GCM API Key (for older browsers)</label>
6268
<input type="text" id="node-config-input-gcmApiKey" placeholder="The API key to send with the GCM request">
6369
</div>
70+
<div class="form-row">
71+
<label for="node-config-input-timeout"><i class="icon-tag"></i> Timeout</label>
72+
<input type="number" id="node-config-input-timeout">
73+
</div>
6474
<div class="form-row">
6575
<label for="node-config-input-name"><i class="icon-tag"></i> Name</label>
6676
<input type="text" id="node-config-input-name" placeholder="Name">
@@ -71,6 +81,7 @@
7181
<p>Configuration for VAPID. You can generate the key pair using the <i>"Generate VAPID keypair"</i> button or online here: <a href="https://web-push-codelab.glitch.me/" target="_blank">https://web-push-codelab.glitch.me</a>.</p>
7282
<p>Read more about the VAPID specification here: <a href="https://tools.ietf.org/html/rfc8292" target="_blank">https://tools.ietf.org/html/rfc8292</a>.</p>
7383
<p>For Chrome prior to version 52 and some old browsers, you're also still required to include a <code>gcm_sender_id</code> in your web app's manifest.json.</p>
84+
<p>Optionally a timeout can be specified (in milliseconds). A timeout value of 0 is considered as no timeout.</p>
7485
</script>
7586

7687

vapid-configuration.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
module.exports = function (RED) {
2-
function VapidConfigurationNode (config) {
3-
RED.nodes.createNode(this, config)
4-
this.subject = config.subject
5-
this.publicKey = config.publicKey
6-
this.privateKey = config.privateKey
7-
this.gcmApiKey = config.gcmApiKey
8-
}
9-
RED.nodes.registerType('vapid-configuration', VapidConfigurationNode)
10-
}
111
module.exports = function (RED) {
122
const webpush = require('web-push');
133

@@ -17,6 +7,12 @@ module.exports = function (RED) {
177
this.publicKey = config.publicKey
188
this.privateKey = config.privateKey
199
this.gcmApiKey = config.gcmApiKey
10+
this.timeout = config.timeout
11+
12+
// Older nodes (version 0.0.3 and below) have no timeout option, so set it to 0 (= no custom timeout)
13+
if (this.timeout == undefined) {
14+
this.timeout = 0;
15+
}
2016
}
2117
RED.nodes.registerType('vapid-configuration', VapidConfigurationNode)
2218

web-push.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ module.exports = function (RED) {
2727
if (node.vapidConfiguration.gcmApiKey) {
2828
options['gcmAPIKey'] = node.vapidConfiguration.gcmApiKey
2929
}
30+
31+
// Only apply the timeout when it is specified and greater than zero
32+
if (node.vapidConfiguration.timeout && node.vapidConfiguration.timeout > 0) {
33+
options['timeout'] = node.vapidConfiguration.timeout
34+
}
3035
}
3136

3237
if (msg.subscriptions && msg.subscriptions.length > 0) {

0 commit comments

Comments
 (0)