@iml1s/claw-link 0.3.0 → 0.4.0
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/dist/openclaw-plugin.js +35 -1
- package/dist/relay-client.js +2 -2
- package/package.json +1 -1
package/dist/openclaw-plugin.js
CHANGED
|
@@ -55,8 +55,42 @@ const plugin = {
|
|
|
55
55
|
// Config file not readable — token will be omitted from QR code
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
// Persist session_id across gateway restarts so mobile app
|
|
59
|
+
// can reconnect without re-scanning the QR code.
|
|
60
|
+
let persistedSessionId;
|
|
61
|
+
try {
|
|
62
|
+
const os = require('os');
|
|
63
|
+
const path = require('path');
|
|
64
|
+
const fs = require('fs');
|
|
65
|
+
const sessionPath = path.join(os.homedir(), '.openclaw', 'claw-link-session.json');
|
|
66
|
+
if (fs.existsSync(sessionPath)) {
|
|
67
|
+
const raw = fs.readFileSync(sessionPath, 'utf-8');
|
|
68
|
+
const data = JSON.parse(raw);
|
|
69
|
+
if (data?.sessionId) {
|
|
70
|
+
persistedSessionId = data.sessionId;
|
|
71
|
+
logger.info('[claw-link] Reusing persisted session_id: ' + persistedSessionId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// File not readable — will generate a new session_id
|
|
77
|
+
}
|
|
58
78
|
logger.info('[claw-link] Starting Cloud Relay bridge...');
|
|
59
|
-
client = new relay_client_js_1.RelayClient(relayUrl, gatewayToken);
|
|
79
|
+
client = new relay_client_js_1.RelayClient(relayUrl, gatewayToken, persistedSessionId);
|
|
80
|
+
// Persist the session_id for next restart
|
|
81
|
+
if (!persistedSessionId) {
|
|
82
|
+
try {
|
|
83
|
+
const os = require('os');
|
|
84
|
+
const path = require('path');
|
|
85
|
+
const fs = require('fs');
|
|
86
|
+
const sessionPath = path.join(os.homedir(), '.openclaw', 'claw-link-session.json');
|
|
87
|
+
fs.writeFileSync(sessionPath, JSON.stringify({ sessionId: client.getConnectionInfo().sessionId }, null, 2));
|
|
88
|
+
logger.info('[claw-link] Saved new session_id to ' + sessionPath);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
logger.warn('[claw-link] Could not persist session_id:', e);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
60
94
|
client.connect();
|
|
61
95
|
},
|
|
62
96
|
stop(_ctx) {
|
package/dist/relay-client.js
CHANGED
|
@@ -51,8 +51,8 @@ class RelayClient {
|
|
|
51
51
|
gatewayToken;
|
|
52
52
|
isDisconnecting = false;
|
|
53
53
|
hasPrintedQrCode = false;
|
|
54
|
-
constructor(relayUrl = 'wss://claw-cloud-relay-374931447815.asia-east1.run.app/register', gatewayToken) {
|
|
55
|
-
this.sessionId = (0, node_crypto_1.randomUUID)();
|
|
54
|
+
constructor(relayUrl = 'wss://claw-cloud-relay-374931447815.asia-east1.run.app/register', gatewayToken, persistedSessionId) {
|
|
55
|
+
this.sessionId = persistedSessionId ?? (0, node_crypto_1.randomUUID)();
|
|
56
56
|
this.relayUrl = relayUrl;
|
|
57
57
|
this.gatewayToken = gatewayToken;
|
|
58
58
|
}
|
package/package.json
CHANGED