@jcbuisson/express-x-client 2.1.0 → 2.1.5
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 +4 -24
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -24,20 +24,12 @@ export default function expressXClient(socket, options={}) {
|
|
|
24
24
|
|
|
25
25
|
socket.on("connect", async () => {
|
|
26
26
|
console.log("socket connected", socket.id)
|
|
27
|
-
// if (socketConnectionState.resolve) {
|
|
28
|
-
// socketConnectionState.resolve('ok')
|
|
29
|
-
// socketConnectionState.status = 'connected'
|
|
30
|
-
// }
|
|
31
27
|
if (connectHandler) connectHandler(socket)
|
|
32
28
|
})
|
|
33
29
|
|
|
34
|
-
socket.on("connect_error", async () => {
|
|
30
|
+
socket.on("connect_error", async (err) => {
|
|
35
31
|
console.log("socket connection error", socket.id)
|
|
36
|
-
|
|
37
|
-
// socketConnectionState.reject(err)
|
|
38
|
-
// socketConnectionState.status = 'error'
|
|
39
|
-
// }
|
|
40
|
-
if (connectErrorHandler) connectErrorHandler(socket)
|
|
32
|
+
if (connectErrorHandler) connectErrorHandler(socket, err)
|
|
41
33
|
})
|
|
42
34
|
|
|
43
35
|
socket.on("disconnect", async () => {
|
|
@@ -56,19 +48,6 @@ export default function expressXClient(socket, options={}) {
|
|
|
56
48
|
disconnectHandler = func
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
// async function socketConnection() {
|
|
61
|
-
// const promise = new Promise((resolve, reject) => {
|
|
62
|
-
// socketConnectionState.resolve = resolve
|
|
63
|
-
// socketConnectionState.reject = reject
|
|
64
|
-
// })
|
|
65
|
-
// return promise
|
|
66
|
-
// }
|
|
67
|
-
|
|
68
|
-
// function socketStatus() {
|
|
69
|
-
// return socketConnectionState.status
|
|
70
|
-
// }
|
|
71
|
-
|
|
72
51
|
// on receiving response from service request
|
|
73
52
|
socket.on('client-response', ({ uid, error, result }) => {
|
|
74
53
|
if (options.debug) console.log('client-response', uid, error, result)
|
|
@@ -143,12 +122,14 @@ export default function expressXClient(socket, options={}) {
|
|
|
143
122
|
if (options.debug) console.log('app-event', type, value)
|
|
144
123
|
if (!type2appHandler[type]) type2appHandler[type] = {}
|
|
145
124
|
const handler = type2appHandler[type]
|
|
125
|
+
console.log('handler', handler)
|
|
146
126
|
if (handler) handler(value)
|
|
147
127
|
})
|
|
148
128
|
|
|
149
129
|
// add a handler for application-wide events
|
|
150
130
|
function on(type, handler) {
|
|
151
131
|
type2appHandler[type] = handler
|
|
132
|
+
console.log('type2appHandler[type]', type2appHandler[type])
|
|
152
133
|
}
|
|
153
134
|
|
|
154
135
|
return {
|
|
@@ -160,4 +141,3 @@ export default function expressXClient(socket, options={}) {
|
|
|
160
141
|
on,
|
|
161
142
|
}
|
|
162
143
|
}
|
|
163
|
-
|