@1presence/bridge 0.1.13 → 0.1.14

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.
Files changed (2) hide show
  1. package/dist/index.js +33 -0
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -108,12 +108,44 @@ async function handleMessage(conversationId, text, sessionId, ws, auth) {
108
108
  });
109
109
  }
110
110
  // ─── WebSocket connection ─────────────────────────────────────────────────────
111
+ const PING_INTERVAL_MS = 30_000;
112
+ const PONG_TIMEOUT_MS = 10_000;
111
113
  function connect(auth, retryDelay = 1000) {
112
114
  const ws = new ws_1.default(GATEWAY_WS, {
113
115
  headers: { Authorization: `Bearer ${auth.token}` },
114
116
  });
117
+ let pingTimer = null;
118
+ let pongTimer = null;
119
+ function startPing() {
120
+ pingTimer = setInterval(() => {
121
+ if (ws.readyState !== ws_1.default.OPEN)
122
+ return;
123
+ ws.ping();
124
+ pongTimer = setTimeout(() => {
125
+ console.log('[bridge] pong timeout — reconnecting…');
126
+ ws.terminate();
127
+ }, PONG_TIMEOUT_MS);
128
+ }, PING_INTERVAL_MS);
129
+ }
130
+ function stopPing() {
131
+ if (pingTimer) {
132
+ clearInterval(pingTimer);
133
+ pingTimer = null;
134
+ }
135
+ if (pongTimer) {
136
+ clearTimeout(pongTimer);
137
+ pongTimer = null;
138
+ }
139
+ }
140
+ ws.on('pong', () => {
141
+ if (pongTimer) {
142
+ clearTimeout(pongTimer);
143
+ pongTimer = null;
144
+ }
145
+ });
115
146
  ws.on('open', () => {
116
147
  console.log('✓ Bridge connected. Local Mode active on all your devices.\n');
148
+ startPing();
117
149
  });
118
150
  ws.on('message', (raw) => {
119
151
  let msg;
@@ -134,6 +166,7 @@ function connect(auth, retryDelay = 1000) {
134
166
  });
135
167
  });
136
168
  ws.on('close', (code) => {
169
+ stopPing();
137
170
  if (code === 4001) {
138
171
  console.error('Authentication failed — clearing cached credentials. Please restart the bridge.');
139
172
  (0, auth_1.clearAuth)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1presence/bridge",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Run 1Presence on your Mac and use your Claude.ai Pro subscription from any device",
5
5
  "bin": {
6
6
  "1presence-bridge": "dist/index.js"
@@ -11,6 +11,7 @@
11
11
  "README.md"
12
12
  ],
13
13
  "scripts": {
14
+ "prepack": "tsc",
14
15
  "build": "tsc",
15
16
  "dev": "tsx src/index.ts",
16
17
  "start": "node dist/index.js"