Skip to content

Commit

Permalink
Merge pull request #10 from bartbutenaers/Update-web-push-dependency-…
Browse files Browse the repository at this point in the history
…3.3.2-to-3.4.4

Update web push dependency 3.3.2 to 3.4.4
  • Loading branch information
webmaxru committed Aug 30, 2021
2 parents 5dd8c94 + 70382b9 commit 2646383
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"email": "salnikov@gmail.com"
},
"dependencies": {
"web-push": "3.3.2"
"web-push": "^3.4.5"
},
"description": "Web Push notifications for Node-RED",
"keywords": [
Expand All @@ -28,5 +28,5 @@
"web-push-notification": "web-push-notification.js"
}
},
"version": "0.0.3"
"version": "0.0.4"
}
11 changes: 11 additions & 0 deletions vapid-configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
publicKey: { value: "", required: true },
privateKey: { value: "", required: true },
gcmApiKey: { value: "" },
timeout: { value: 0 },
name: { value: "" }
},
label: function () {
return this.name || this.subject;
},
oneditprepare: function () {
var node = this;

// Older nodes (version 0.0.3 and below) have no timeout option, so set it to 0 (= no custom timeout)
if (this.timeout == undefined) {
$('#node-config-input-timeout').val(0);
}

$("#node-input-generateKeyPair").click(function () {
if ($("#node-config-input-publicKey").val() || $("#node-config-input-privateKey").val()) {
Expand Down Expand Up @@ -61,6 +67,10 @@
<label for="node-config-input-gcmApiKey"><i class="icon-tag"></i> GCM API Key (for older browsers)</label>
<input type="text" id="node-config-input-gcmApiKey" placeholder="The API key to send with the GCM request">
</div>
<div class="form-row">
<label for="node-config-input-timeout"><i class="icon-tag"></i> Timeout</label>
<input type="number" id="node-config-input-timeout">
</div>
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
Expand All @@ -71,6 +81,7 @@
<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>
<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>
<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>
<p>Optionally a timeout can be specified (in milliseconds). A timeout value of 0 is considered as no timeout.</p>
</script>


16 changes: 6 additions & 10 deletions vapid-configuration.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
module.exports = function (RED) {
function VapidConfigurationNode (config) {
RED.nodes.createNode(this, config)
this.subject = config.subject
this.publicKey = config.publicKey
this.privateKey = config.privateKey
this.gcmApiKey = config.gcmApiKey
}
RED.nodes.registerType('vapid-configuration', VapidConfigurationNode)
}
module.exports = function (RED) {
const webpush = require('web-push');

Expand All @@ -17,6 +7,12 @@ module.exports = function (RED) {
this.publicKey = config.publicKey
this.privateKey = config.privateKey
this.gcmApiKey = config.gcmApiKey
this.timeout = config.timeout

// Older nodes (version 0.0.3 and below) have no timeout option, so set it to 0 (= no custom timeout)
if (this.timeout == undefined) {
this.timeout = 0;
}
}
RED.nodes.registerType('vapid-configuration', VapidConfigurationNode)

Expand Down
5 changes: 5 additions & 0 deletions web-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module.exports = function (RED) {
if (node.vapidConfiguration.gcmApiKey) {
options['gcmAPIKey'] = node.vapidConfiguration.gcmApiKey
}

// Only apply the timeout when it is specified and greater than zero
if (node.vapidConfiguration.timeout && node.vapidConfiguration.timeout > 0) {
options['timeout'] = node.vapidConfiguration.timeout
}
}

if (msg.subscriptions && msg.subscriptions.length > 0) {
Expand Down

0 comments on commit 2646383

Please sign in to comment.