pushy-electron 1.0.12 → 1.0.14

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 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.d.ts CHANGED
@@ -6,9 +6,13 @@ declare namespace Pushy {
6
6
 
7
7
  type Listener<T> = (data: T) => void
8
8
 
9
+ type ConnectivityListener<T> = (connected: boolean, error: T) => void
10
+
9
11
  function listen(): void
10
12
 
11
13
  function setNotificationListener<T>(l: Listener<T>): void
14
+
15
+ function setConnectivityListener<T>(l: ConnectivityListener<T>): void
12
16
 
13
17
  function register(opts: { appId: string }): Promise<DeviceToken>
14
18
 
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') {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushy-electron",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "main": "lib/Pushy.js",
7
7
  "typings": "lib/Pushy.d.ts",
8
8
  "//": "Also update version in config.js",
9
- "version": "1.0.12",
9
+ "version": "1.0.14",
10
10
  "scripts": {
11
11
  "dev": "electron electron.js"
12
12
  },
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) {