@lethevimlet/sshift 1.9.8 → 1.9.9

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.
@@ -44,7 +44,26 @@ function getTabOrder() {
44
44
  * @param {Array} order - Array of sessionIds
45
45
  */
46
46
  function setTabOrder(order) {
47
- tabOrder = order;
47
+ // Client-supplied: keep it an array of unique session-id strings, or a
48
+ // bad payload breaks every later connection (tabOrder.filter) until a
49
+ // restart. Server tabs the client did not list (e.g. one opened by the
50
+ // remote-control plugin a moment ago) are kept at the end, so a client
51
+ // with a stale view cannot hide a live tab from everyone.
52
+ if (!Array.isArray(order)) return;
53
+ const seen = new Set();
54
+ const next = [];
55
+ for (const id of order) {
56
+ if (typeof id !== 'string' || !id || seen.has(id)) continue;
57
+ seen.add(id);
58
+ next.push(id);
59
+ }
60
+ for (const id of tabOrder) {
61
+ if (!seen.has(id) && openTabs.has(id)) {
62
+ seen.add(id);
63
+ next.push(id);
64
+ }
65
+ }
66
+ tabOrder = next;
48
67
  }
49
68
 
50
69
  /**
@@ -79,6 +98,7 @@ function setCurrentLayout(layoutId) {
79
98
  * @param {Object} tabData - Tab data
80
99
  */
81
100
  function addTab(sessionId, tabData) {
101
+ recentlyClosed.delete(sessionId);
82
102
  openTabs.set(sessionId, tabData);
83
103
  if (!tabOrder.includes(sessionId)) {
84
104
  tabOrder.push(sessionId);
@@ -98,7 +118,26 @@ function getTab(sessionId) {
98
118
  * Remove a tab
99
119
  * @param {string} sessionId - Session ID
100
120
  */
121
+ // Sessions that ended while this process was running (closed tab, remote
122
+ // exit, dropped connection). A client that reconnects after a sleep and
123
+ // asks to join one of these must drop the tab, not recreate the SSH
124
+ // connection from its stored credentials (that is only right after a
125
+ // server restart, when the id is simply unknown).
126
+ const recentlyClosed = new Map(); // sessionId -> time
127
+ const RECENTLY_CLOSED_MAX = 1000;
128
+
129
+ function wasRecentlyClosed(sessionId) {
130
+ return recentlyClosed.has(sessionId);
131
+ }
132
+
101
133
  function removeTab(sessionId) {
134
+ if (openTabs.has(sessionId)) {
135
+ recentlyClosed.delete(sessionId);
136
+ recentlyClosed.set(sessionId, Date.now());
137
+ while (recentlyClosed.size > RECENTLY_CLOSED_MAX) {
138
+ recentlyClosed.delete(recentlyClosed.keys().next().value);
139
+ }
140
+ }
102
141
  openTabs.delete(sessionId);
103
142
  tabOrder = tabOrder.filter(id => id !== sessionId);
104
143
  // Clean up active tab references
@@ -300,6 +339,7 @@ module.exports = {
300
339
  addTab,
301
340
  getTab,
302
341
  removeTab,
342
+ wasRecentlyClosed,
303
343
  addSocketToTab,
304
344
  removeSocketFromTab,
305
345
  hasActiveSockets,