@iml1s/claw-link 0.2.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 +13 -4
- package/package.json +2 -2
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,11 +51,20 @@ 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
|
}
|
|
59
|
+
/** Returns current connection info for RPC callers / agent skills. */
|
|
60
|
+
getConnectionInfo() {
|
|
61
|
+
return {
|
|
62
|
+
connectionString: buildConnectionString(this.relayUrl, this.sessionId, this.gatewayToken),
|
|
63
|
+
sessionId: this.sessionId,
|
|
64
|
+
relayUrl: this.relayUrl,
|
|
65
|
+
relayConnected: this.relayWs?.readyState === ws_1.default.OPEN,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
59
68
|
connect() {
|
|
60
69
|
this.isDisconnecting = false;
|
|
61
70
|
console.log(`[RelayClient] Connecting to Relay Server at ${this.relayUrl}...`);
|
|
@@ -64,7 +73,7 @@ class RelayClient {
|
|
|
64
73
|
this.relayWs.on('open', () => {
|
|
65
74
|
console.log('[RelayClient] Connected to Relay Server.');
|
|
66
75
|
if (!this.hasPrintedQrCode) {
|
|
67
|
-
this.displayQrCode();
|
|
76
|
+
this.displayQrCode().catch(() => { });
|
|
68
77
|
this.hasPrintedQrCode = true;
|
|
69
78
|
}
|
|
70
79
|
this.ensureLocalGatewayConnected();
|
|
@@ -191,7 +200,7 @@ class RelayClient {
|
|
|
191
200
|
type: 'terminal',
|
|
192
201
|
small: true,
|
|
193
202
|
});
|
|
194
|
-
console.log(qrAscii);
|
|
203
|
+
console.log('\n' + qrAscii);
|
|
195
204
|
}
|
|
196
205
|
catch (e) {
|
|
197
206
|
console.log('(Failed to render QR code)');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iml1s/claw-link",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Cloud relay bridge plugin for OpenClaw — connects mobile devices to local gateways via a relay server.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
"typescript": "^5.0.0",
|
|
44
44
|
"vitest": "^2.1.8"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|