@jcbuisson/express-x-client 1.0.4 → 1.0.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
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcbuisson/express-x-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "src/
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git@gitlab.com:buisson31/express-x.git"
|
|
8
|
+
"url": "git@gitlab.com:buisson31/express-x-client.git"
|
|
9
9
|
},
|
|
10
10
|
"author": "Jean-Christophe Buisson <buisson@enseeiht.fr> (jcbuisson.dev)",
|
|
11
11
|
"license": "MIT",
|
|
@@ -5,24 +5,30 @@ function expressxClient(socket) {
|
|
|
5
5
|
|
|
6
6
|
const waitingPromises = {}
|
|
7
7
|
const action2service2handlers = {}
|
|
8
|
+
let onConnectionCallback = null
|
|
9
|
+
let onDisconnectionCallback = null
|
|
10
|
+
|
|
11
|
+
const setConnectionCallback = (callback) => {
|
|
12
|
+
onConnectionCallback = callback
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const setDisconnectionCallback = (callback) => {
|
|
16
|
+
onDisconnectionCallback = callback
|
|
17
|
+
}
|
|
8
18
|
|
|
9
19
|
// on connection
|
|
10
20
|
socket.on("connected", async (connectionId) => {
|
|
11
21
|
console.log('connected', connectionId)
|
|
12
|
-
|
|
13
|
-
// TODO: configurable
|
|
14
|
-
const accessToken = window.sessionStorage.getItem('feathers-jwt')
|
|
15
|
-
if (accessToken) {
|
|
16
|
-
// disconnect/reconnect: reauthenticate
|
|
17
|
-
console.log('reauthenticate with', accessToken)
|
|
18
|
-
serviceMethodRequest('authenticate', 'reauthenticate', accessToken)
|
|
19
|
-
}
|
|
22
|
+
if (onConnectionCallback) onConnectionCallback(connectionId)
|
|
20
23
|
})
|
|
21
24
|
|
|
22
25
|
// on receiving response from service request
|
|
23
26
|
socket.on('client-response', ({ uid, error, result }) => {
|
|
24
|
-
console.log('client-response', uid, error, result)
|
|
27
|
+
// console.log('client-response', uid, error, result)
|
|
25
28
|
if (!uid in waitingPromises) return // ???
|
|
29
|
+
|
|
30
|
+
// ANNULER TIMER
|
|
31
|
+
|
|
26
32
|
const [resolve, reject] = waitingPromises[uid]
|
|
27
33
|
if (error) {
|
|
28
34
|
reject(error)
|
|
@@ -44,6 +50,9 @@ function expressxClient(socket) {
|
|
|
44
50
|
const uid = v4()
|
|
45
51
|
const promise = new Promise((resolve, reject) => {
|
|
46
52
|
waitingPromises[uid] = [resolve, reject]
|
|
53
|
+
|
|
54
|
+
// CREER TIMER
|
|
55
|
+
|
|
47
56
|
})
|
|
48
57
|
socket.emit('client-request', {
|
|
49
58
|
uid,
|
|
@@ -63,11 +72,11 @@ function expressxClient(socket) {
|
|
|
63
72
|
serviceHandlers[name] = handler
|
|
64
73
|
},
|
|
65
74
|
}
|
|
66
|
-
// use a
|
|
75
|
+
// use a Proxy to allow for any method name for a service
|
|
67
76
|
const handler = {
|
|
68
77
|
get(service, action) {
|
|
69
78
|
if (!(action in service)) {
|
|
70
|
-
// newly used property
|
|
79
|
+
// newly used property `action`: define it as a service method request function
|
|
71
80
|
service[action] = (...args) => serviceMethodRequest(name, action, ...args)
|
|
72
81
|
}
|
|
73
82
|
return service[action]
|
|
@@ -76,14 +85,10 @@ function expressxClient(socket) {
|
|
|
76
85
|
return new Proxy(service, handler)
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
function logout() {
|
|
80
|
-
// TODO: configurable
|
|
81
|
-
window.sessionStorage.removeItem('feathers-jwt')
|
|
82
|
-
}
|
|
83
|
-
|
|
84
88
|
return {
|
|
89
|
+
setConnectionCallback,
|
|
90
|
+
setDisconnectionCallback,
|
|
85
91
|
service,
|
|
86
|
-
logout,
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
94
|
|