thinknagent 0.1.3 → 0.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/lib/agent.js +2 -1
- package/lib/connect.js +28 -23
- package/package.json +1 -1
package/lib/agent.js
CHANGED
|
@@ -64,8 +64,9 @@ class Agent {
|
|
|
64
64
|
this.logs = new LogWatcher({ connection: this.conn, logPaths: logs });
|
|
65
65
|
this.logs.start();
|
|
66
66
|
});
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
this.conn.socket.on('agent:send_metrics_now', () => {
|
|
69
|
+
console.log('[agent] send_metrics_now received — polling now');
|
|
69
70
|
this.metrics.pollNow();
|
|
70
71
|
});
|
|
71
72
|
|
package/lib/connect.js
CHANGED
|
@@ -31,22 +31,26 @@ class Connection {
|
|
|
31
31
|
const cfg = store.read();
|
|
32
32
|
|
|
33
33
|
this.socket = io(`${this.serverUrl}${NAMESPACE}`, {
|
|
34
|
-
reconnection:
|
|
35
|
-
reconnectionDelay:
|
|
34
|
+
reconnection: true,
|
|
35
|
+
reconnectionDelay: RECONNECT_DELAY,
|
|
36
36
|
reconnectionAttempts: Infinity,
|
|
37
|
-
auth: {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
auth: (cb) => {
|
|
38
|
+
// ← YE CHANGE KARO — har reconnect pe fresh config read karo
|
|
39
|
+
const freshCfg = store.read();
|
|
40
|
+
cb({
|
|
41
|
+
agentId: freshCfg.agentId,
|
|
42
|
+
agentToken: freshCfg.agentToken || null,
|
|
43
|
+
name: freshCfg.name,
|
|
44
|
+
hostname: require('os').hostname(),
|
|
45
|
+
version: require('../package.json').version,
|
|
46
|
+
roomId: freshCfg.roomId || null,
|
|
47
|
+
});
|
|
44
48
|
}
|
|
45
49
|
});
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
this._bind();
|
|
52
|
+
return this.socket;
|
|
53
|
+
}
|
|
50
54
|
|
|
51
55
|
_bind() {
|
|
52
56
|
const s = this.socket;
|
|
@@ -61,17 +65,18 @@ class Connection {
|
|
|
61
65
|
});
|
|
62
66
|
|
|
63
67
|
// Server says: "Owner approved, here is your token + assigned role"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
s.on('agent:approved', ({ agentToken, role, roomId }) => {
|
|
69
|
+
store.set('agentToken', agentToken);
|
|
70
|
+
store.set('agentId', this.agentId);
|
|
71
|
+
store.set('role', role);
|
|
72
|
+
store.set('roomId', roomId);
|
|
73
|
+
this.agentToken = agentToken;
|
|
74
|
+
this.role = role;
|
|
75
|
+
console.log(`[thinknagent] Approved! Reconnecting with token...`);
|
|
76
|
+
|
|
77
|
+
// ← YE ADD KARO — disconnect karo, socket.io auto-reconnect karega naye token ke saath
|
|
78
|
+
this.socket.disconnect();
|
|
79
|
+
});
|
|
75
80
|
// Server says: "Owner rejected this agent"
|
|
76
81
|
s.on('agent:rejected', ({ reason }) => {
|
|
77
82
|
console.error(`[thinknagent] Registration rejected: ${reason}`);
|