@nickname4th/pura-cli 0.1.3 → 0.1.4

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/package.json +1 -1
  2. package/server/dist/hub.js +26 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nickname4th/pura-cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "LAN Android device mirroring hub and developer CLI for distributed teams.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -83,6 +83,7 @@ export function installHubRoutes(app) {
83
83
  clients: new Set()
84
84
  };
85
85
  sessions.set(session.id, session);
86
+ scheduleHubSessionStopIfIdle(session);
86
87
  res.json({
87
88
  session: {
88
89
  ...body.session,
@@ -260,6 +261,10 @@ export function attachHubVideoClient(sessionId, client) {
260
261
  return;
261
262
  }
262
263
  session.clients.add(client);
264
+ if (session.stopTimer) {
265
+ clearTimeout(session.stopTimer);
266
+ session.stopTimer = undefined;
267
+ }
263
268
  const waitTimer = setTimeout(() => {
264
269
  if (!session.stream || session.stream.readyState !== WebSocket.OPEN) {
265
270
  client.close(1011, "agent stream unavailable");
@@ -268,6 +273,7 @@ export function attachHubVideoClient(sessionId, client) {
268
273
  client.on("close", () => {
269
274
  clearTimeout(waitTimer);
270
275
  session.clients.delete(client);
276
+ scheduleHubSessionStopIfIdle(session);
271
277
  });
272
278
  }
273
279
  async function captureRemoteScreenshot(deviceId) {
@@ -297,6 +303,10 @@ async function deleteHubSessionsForDevice(deviceId) {
297
303
  }));
298
304
  }
299
305
  function closeHubSession(session) {
306
+ if (session.stopTimer) {
307
+ clearTimeout(session.stopTimer);
308
+ session.stopTimer = undefined;
309
+ }
300
310
  if (session.stream && session.stream.readyState === WebSocket.OPEN) {
301
311
  session.stream.close(1001, "session ended");
302
312
  }
@@ -304,6 +314,22 @@ function closeHubSession(session) {
304
314
  client.close(1001, "session ended");
305
315
  }
306
316
  }
317
+ function scheduleHubSessionStopIfIdle(session) {
318
+ if (session.clients.size > 0 || session.stopTimer)
319
+ return;
320
+ session.stopTimer = setTimeout(() => {
321
+ if (session.clients.size > 0)
322
+ return;
323
+ sessions.delete(session.id);
324
+ closeHubSession(session);
325
+ const agent = agents.get(session.agentId);
326
+ if (agent) {
327
+ void sendAgentRequest(agent, "delete-session", {
328
+ body: { sessionId: session.agentSessionId }
329
+ }).catch(() => undefined);
330
+ }
331
+ }, 5000);
332
+ }
307
333
  function listHubDevices() {
308
334
  pruneAgents();
309
335
  return [...agents.values()].flatMap((agent) => agent.devices.map((device) => ({