-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix-wait-for-auth.js
More file actions
57 lines (43 loc) · 1.84 KB
/
fix-wait-for-auth.js
File metadata and controls
57 lines (43 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require('fs');
let content = fs.readFileSync('lib/central/central-connector.js', 'utf8');
// Don't send registration on 'open', wait for server acknowledgment
const oldOpen = ` this.ws.on('open', () => {
console.log('[Central] WebSocket opened, sending registration...');
console.log('[Central] Connected to central server');
this.connected = true;
this.reconnectAttempts = 0;
// Start heartbeat
this.startHeartbeat();
// Send initial registration (with small delay to ensure server is ready)
setTimeout(() => {
console.log('[Central] Registration message sent');
this.sendRegistration();
}, 100);
});`;
const newOpen = ` this.ws.on('open', () => {
console.log('[Central] Connected to central server');
console.log('[Central] Waiting for authentication confirmation...');
this.connected = true;
this.reconnectAttempts = 0;
// Start heartbeat
this.startHeartbeat();
// Registration will be sent when we receive 'authenticated' message
});`;
content = content.replace(oldOpen, newOpen);
// Handle the 'authenticated' message
const oldHandle = ` async handleMessage(message) {
const { type, id, command, params, signature } = message;
switch (type) {
case 'ping':`;
const newHandle = ` async handleMessage(message) {
const { type, id, command, params, signature } = message;
switch (type) {
case 'authenticated':
console.log('[Central] Authentication confirmed, sending registration...');
this.sendRegistration();
console.log('[Central] Registration sent');
break;
case 'ping':`;
content = content.replace(oldHandle, newHandle);
fs.writeFileSync('lib/central/central-connector.js', content);
console.log('✓ Fixed registration handshake');