biz-a-cli 2.3.56 → 2.3.57
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/bin/hubEvent.js +30 -5
- package/package.json +1 -1
package/bin/hubEvent.js
CHANGED
|
@@ -8,18 +8,23 @@ import { Transform } from 'node:stream'
|
|
|
8
8
|
// import { pipeline } from 'node:stream'
|
|
9
9
|
|
|
10
10
|
const IDLE_SOCKET_TIMEOUT_MILLISECONDS = 1000 * 30;
|
|
11
|
+
const DISCONNECT_REASON_BY_SOCKET_SERVER = 'io server disconnect'
|
|
11
12
|
|
|
12
13
|
export const socketAgent = isUsingHttps=>(isUsingHttps==true) ? tls : net
|
|
13
14
|
|
|
15
|
+
const getIdText = id=>id ? id+' ' : ''
|
|
16
|
+
|
|
14
17
|
export const streamEvent = async (socket, argv) => new Promise((resolve, reject) => {
|
|
18
|
+
let id
|
|
15
19
|
|
|
16
20
|
const connectCb = () => {
|
|
21
|
+
id = socket.id
|
|
17
22
|
socket.emit('createTunnel', argv['subdomain'], (err) => {
|
|
18
23
|
if (err) {
|
|
19
|
-
console.log(new Date()
|
|
24
|
+
console.log(`${new Date()}: ${getIdText(id)}connection error to BizA Server. Error : ${err}`);
|
|
20
25
|
reject(err);
|
|
21
26
|
} else {
|
|
22
|
-
console.log(`${new Date()}:
|
|
27
|
+
console.log(`${new Date()}: ${getIdText(id)}connected to BizA Server at ${argv.server} using sub domain "${argv['subdomain']}"`)
|
|
23
28
|
resolve(argv['server'].toString());
|
|
24
29
|
}
|
|
25
30
|
});
|
|
@@ -109,6 +114,18 @@ export const streamEvent = async (socket, argv) => new Promise((resolve, reject)
|
|
|
109
114
|
socket.on('connect', connectCb);
|
|
110
115
|
socket.on('incomingClient', incomingHubCb)
|
|
111
116
|
socket.on('cli-req', cliReqCb);
|
|
117
|
+
|
|
118
|
+
socket.on('disconnect', reason=>{
|
|
119
|
+
console.log(`${new Date()}: ${getIdText(id)}disconnected from BizA Server. Reason: ${reason}`)
|
|
120
|
+
id = undefined
|
|
121
|
+
if (reason.toLowerCase()===DISCONNECT_REASON_BY_SOCKET_SERVER) {
|
|
122
|
+
socket.connect()
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
socket.io.on('reconnect', ()=>{
|
|
127
|
+
console.log(`${new Date()}: ${getIdText(id)}reconnecting to BizA Server`)
|
|
128
|
+
})
|
|
112
129
|
})
|
|
113
130
|
|
|
114
131
|
export const hubEvent = (socket, argv, notifier)=>{
|
|
@@ -116,13 +133,17 @@ export const hubEvent = (socket, argv, notifier)=>{
|
|
|
116
133
|
socket.on('connect', ()=>{
|
|
117
134
|
id = socket.id
|
|
118
135
|
notifier(argv['hub'])
|
|
119
|
-
console.log(`${new Date()}:
|
|
136
|
+
console.log(`${new Date()}: ${getIdText(id)}connected to BizA Hub at ${argv['hub']} using sub domain "${argv['subdomain']}"`)
|
|
120
137
|
})
|
|
121
138
|
socket.on('disconnect', (reason)=>{
|
|
122
139
|
notifier('')
|
|
123
|
-
console.log(`${new Date()}: ${id
|
|
140
|
+
console.log(`${new Date()}: ${getIdText(id)}disconnected from BizA Hub. Reason: ${reason}`)
|
|
141
|
+
id = undefined
|
|
142
|
+
if (reason.toLowerCase()===DISCONNECT_REASON_BY_SOCKET_SERVER) {
|
|
143
|
+
socket.connect()
|
|
144
|
+
}
|
|
124
145
|
})
|
|
125
|
-
const logError = msg=>{console.log(`${new Date()}: ${id
|
|
146
|
+
const logError = msg=>{console.log(`${new Date()}: ${getIdText(id)}connection error to BizA Hub. Error : ${msg}`)}
|
|
126
147
|
socket.on('connect_error', (error)=>{
|
|
127
148
|
notifier('')
|
|
128
149
|
logError(error.message)
|
|
@@ -131,6 +152,10 @@ export const hubEvent = (socket, argv, notifier)=>{
|
|
|
131
152
|
notifier('')
|
|
132
153
|
logError(error)
|
|
133
154
|
})
|
|
155
|
+
socket.io.on('reconnect', ()=>{
|
|
156
|
+
notifier('')
|
|
157
|
+
console.log(`${new Date()}: ${getIdText(id)}reconnecting to BizA Hub`)
|
|
158
|
+
})
|
|
134
159
|
apiRequestListener(socket, argv)
|
|
135
160
|
}
|
|
136
161
|
|