pushy-electron 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/electron.js +12 -0
- package/lib/Pushy.js +14 -0
- package/npm-shrinkwrap.json +1 -1
- package/package.json +1 -1
- package/util/mqtt.js +9 -0
package/electron.js
CHANGED
|
@@ -29,6 +29,18 @@ function createWindow() {
|
|
|
29
29
|
// Display an alert with the "message" payload value
|
|
30
30
|
Pushy.alert(win, 'Received notification: ' + data.message);
|
|
31
31
|
});
|
|
32
|
+
|
|
33
|
+
// Listen for connectivity events
|
|
34
|
+
Pushy.setConnectivityListener((connected, error) => {
|
|
35
|
+
// Log error message if present
|
|
36
|
+
if (error) {
|
|
37
|
+
console.log('Connection error: ' + error);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Log connected boolean status
|
|
41
|
+
console.log('Connected: ' + connected);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
32
44
|
});
|
|
33
45
|
|
|
34
46
|
// Load the index.html of the app
|
package/lib/Pushy.js
CHANGED
|
@@ -15,6 +15,11 @@ module.exports = {
|
|
|
15
15
|
this.notificationListener = listener;
|
|
16
16
|
},
|
|
17
17
|
|
|
18
|
+
setConnectivityListener(listener) {
|
|
19
|
+
// Store reference to listener
|
|
20
|
+
this.connectivityListener = listener;
|
|
21
|
+
},
|
|
22
|
+
|
|
18
23
|
onNotification(payload) {
|
|
19
24
|
// No listener configured yet?
|
|
20
25
|
if (!this.notificationListener)
|
|
@@ -24,6 +29,15 @@ module.exports = {
|
|
|
24
29
|
this.notificationListener(payload);
|
|
25
30
|
},
|
|
26
31
|
|
|
32
|
+
onConnectivityChanged(connected, error) {
|
|
33
|
+
// No listener configured yet?
|
|
34
|
+
if (!this.connectivityListener)
|
|
35
|
+
return;
|
|
36
|
+
|
|
37
|
+
// Invoke listener
|
|
38
|
+
this.connectivityListener(connected, error);
|
|
39
|
+
},
|
|
40
|
+
|
|
27
41
|
async register(options) {
|
|
28
42
|
// Make sure options is an object
|
|
29
43
|
if (!options || typeof options !== 'object') {
|
package/npm-shrinkwrap.json
CHANGED
package/package.json
CHANGED
package/util/mqtt.js
CHANGED
|
@@ -34,16 +34,25 @@ module.exports = {
|
|
|
34
34
|
onError(err) {
|
|
35
35
|
// Log to ipcMain console
|
|
36
36
|
console.log('[Pushy] MQTT Error\n', err);
|
|
37
|
+
|
|
38
|
+
// Invoke connectivity listener (in renderer process)
|
|
39
|
+
this.Pushy.onConnectivityChanged(this.client.connected, err);
|
|
37
40
|
},
|
|
38
41
|
|
|
39
42
|
onClose() {
|
|
40
43
|
// Log to ipcMain console
|
|
41
44
|
console.log(`[Pushy] Disconnected from server`);
|
|
45
|
+
|
|
46
|
+
// Invoke connectivity listener (in renderer process)
|
|
47
|
+
this.Pushy.onConnectivityChanged(this.client.connected);
|
|
42
48
|
},
|
|
43
49
|
|
|
44
50
|
onConnect() {
|
|
45
51
|
// Log to ipcMain console
|
|
46
52
|
console.log(`[Pushy] Connected successfully (device token ${localStorage.get(config.storageKeys.token)})`);
|
|
53
|
+
|
|
54
|
+
// Invoke connectivity listener (in renderer process)
|
|
55
|
+
this.Pushy.onConnectivityChanged(this.client.connected);
|
|
47
56
|
},
|
|
48
57
|
|
|
49
58
|
onMessage(topic, message) {
|