@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.
- package/package.json +1 -1
- package/src/index.mjs +15 -10
package/package.json
CHANGED
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
+
for (const handler of connectErrorHandlers) {
|
|
34
|
+
handler(socket, err)
|
|
35
|
+
}
|
|
33
36
|
})
|
|
34
37
|
|
|
35
38
|
socket.on("disconnect", async () => {
|
|
36
|
-
|
|
39
|
+
for (const handler of disconnectHandlers) {
|
|
40
|
+
handler(socket)
|
|
41
|
+
}
|
|
37
42
|
})
|
|
38
43
|
|
|
39
44
|
function onConnect(func) {
|
|
40
|
-
|
|
45
|
+
connectHandlers.push(func)
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
function onConnectError(func) {
|
|
44
|
-
|
|
49
|
+
connectErrorHandlers.push(func)
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
function onDisconnect(func) {
|
|
48
|
-
|
|
53
|
+
disconnectHandlers.push(func)
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
// on receiving response from service request
|