@jcbuisson/express-x-client 2.1.5 → 2.1.6

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 +15 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x-client",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "type": "module",
5
5
  "description": "Client library for ExpressX framework",
6
6
  "main": "src/index.mjs",
package/src/index.mjs CHANGED
@@ -17,35 +17,40 @@ export default function expressXClient(socket, options={}) {
17
17
  const waitingPromisesByUid = {}
18
18
  const action2service2handlers = {}
19
19
  const type2appHandler = {}
20
- // const socketConnectionState = {}
21
- let connectHandler = null
22
- let connectErrorHandler = null
23
- let disconnectHandler = null
20
+ const connectHandlers = []
21
+ const connectErrorHandlers = []
22
+ const disconnectHandlers = []
24
23
 
25
24
  socket.on("connect", async () => {
26
25
  console.log("socket connected", socket.id)
27
- if (connectHandler) connectHandler(socket)
26
+ for (const handler of connectHandlers) {
27
+ handler(socket)
28
+ }
28
29
  })
29
30
 
30
31
  socket.on("connect_error", async (err) => {
31
32
  console.log("socket connection error", socket.id)
32
- if (connectErrorHandler) connectErrorHandler(socket, err)
33
+ for (const handler of connectErrorHandlers) {
34
+ handler(socket, err)
35
+ }
33
36
  })
34
37
 
35
38
  socket.on("disconnect", async () => {
36
- if (disconnectHandler) disconnectHandler(socket)
39
+ for (const handler of disconnectHandlers) {
40
+ handler(socket)
41
+ }
37
42
  })
38
43
 
39
44
  function onConnect(func) {
40
- connectHandler = func
45
+ connectHandlers.push(func)
41
46
  }
42
47
 
43
48
  function onConnectError(func) {
44
- connectErrorHandler = func
49
+ connectErrorHandlers.push(func)
45
50
  }
46
51
 
47
52
  function onDisconnect(func) {
48
- disconnectHandler = func
53
+ disconnectHandlers.push(func)
49
54
  }
50
55
 
51
56
  // on receiving response from service request