@jcbuisson/express-x-client 1.6.0 → 1.6.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.mjs +11 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x-client",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "type": "module",
5
5
  "description": "Client library for ExpressX framework",
6
6
  "main": "src/index.mjs",
package/src/index.mjs CHANGED
@@ -7,6 +7,7 @@ export default function expressXClient(socket, options={}) {
7
7
  const action2service2handlers = {}
8
8
  const type2appHandlers = {}
9
9
  let onConnectionCallback = null
10
+ let onReconnectionCallback = null
10
11
  let onDisconnectionCallback = null
11
12
  let nodeCnxId
12
13
 
@@ -14,6 +15,10 @@ export default function expressXClient(socket, options={}) {
14
15
  onConnectionCallback = callback
15
16
  }
16
17
 
18
+ const setReconnectionCallback = (callback) => {
19
+ onReconnectionCallback = callback
20
+ }
21
+
17
22
  const setDisconnectionCallback = (callback) => {
18
23
  onDisconnectionCallback = callback
19
24
  }
@@ -59,9 +64,11 @@ export default function expressXClient(socket, options={}) {
59
64
  if (onConnectionCallback) onConnectionCallback(connectionId)
60
65
  })
61
66
 
62
- socket.on("cnx-transfer-ack", async (connectionId) => {
63
- if (options.debug) console.log('cnx-transfer-ack', connectionId)
64
- _setCnxId(connectionId)
67
+ socket.on("cnx-transfer-ack", async (connection) => {
68
+ if (options.debug) console.log('cnx-transfer-ack', connection)
69
+ _setCnxId(connection.id)
70
+ // call user-defined reconnection callback
71
+ if (onReconnectionCallback) onReconnectionCallback(connection)
65
72
  })
66
73
 
67
74
 
@@ -186,6 +193,7 @@ export default function expressXClient(socket, options={}) {
186
193
 
187
194
  return {
188
195
  setConnectionCallback,
196
+ setReconnectionCallback,
189
197
  setDisconnectionCallback,
190
198
  service,
191
199
  on,