Skip to content

Commit 24a6913

Browse files
committed
Revert WebSocket port range and retry configurations back to ports 55155 and 55156
- remove the separate 1s wait [Fragment] - remove port-range checking. Should only ever try 55155 and 55156, allowing up to 2 connected ws servers. [Accuracy boost] ├── apps │ ├── browser │ │ ├── README.md │ │ ├── src │ │ │ └── background │ │ │ ├── keep-alive.ts │ │ │ ├── main.ts │ │ │ ├── message-handler.ts │ │ │ └── websocket.ts │ │ └── webpack.config.ts │ └── editor │ ├── package.json │ ├── src │ │ ├── extension.ts │ │ ├── services │ │ │ ├── websocket-manager.ts │ │ │ └── websocket-server-process.ts │ │ └── utils │ │ └── shared-token.ts │ └── webpack.config.ts ├── docs │ └── privacy.mdx └── packages └── shared └── src ├── constants │ └── websocket.ts └── types └── websocket-message.ts
1 parent 69c94a6 commit 24a6913

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

‎apps/browser/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The extension functions with minimal permissions.
2828
- `storage` - Used to temporarily store prompts for [a content script](https://github.com/robertpiosik/CodeWebChat/tree/dev/apps/browser/src/content-scripts/send-prompt-content-script), and to save extension settings.
2929
- `alarms` (Chrome only) - Used to implement a keep-alive mechanism for the background service worker to ensure the WebSocket connection stays active.
3030

31-
The extension requests no host permissions. It connects to the local WebSocket server managed by the VS Code extension (`ws://localhost:55155`, or the next few ports up to `55164` when a forwarded remote port had to be shifted).
31+
The extension requests no host permissions. It connects to the local WebSocket server managed by the VS Code extension (`ws://localhost:55155`, or `55156` when a forwarded remote port had to be shifted).
3232

3333
Firefox only:
3434

‎apps/browser/src/background/websocket.ts‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@ import { DEFAULT_PORT, CLIENT_TYPE } from '@shared/constants/websocket'
44
import browser from 'webextension-polyfill'
55

66
// Remote setups (Remote-SSH, WSL, Dev Containers) may forward the server to
7-
// DEFAULT_PORT + n when the local DEFAULT_PORT is already occupied.
8-
const PORT_RANGE_SIZE = 10
9-
7+
// DEFAULT_PORT + 1 when the local DEFAULT_PORT is already occupied.
108
const ports_to_check = (): number[] => {
11-
const ports = []
12-
for (let i = 0; i < PORT_RANGE_SIZE; i++) {
13-
ports.push(DEFAULT_PORT + i)
14-
}
15-
return ports
9+
return [DEFAULT_PORT, DEFAULT_PORT + 1]
1610
}
1711

1812
const STALE_AFTER_MS = 20000
19-
const CONNECT_TIMEOUT_MS = 500 // a handshake that hangs (e.g. dead forwarded port) must not block the port
20-
const RETRY_AFTER_DROP_MS = 1000 // we had a live connection, retry quickly
21-
const RETRY_IDLE_MS = 5000 // nothing was ever listening, poll slowly
13+
const CONNECT_TIMEOUT_MS = 2000
14+
const RETRY_IDLE_MS = 5000
2215

2316
type Connection = {
2417
ws: WebSocket | null
@@ -163,7 +156,7 @@ export const connect_websocket = async (port: number): Promise<void> => {
163156
`Disconnected from VS Code on port ${port}, attempting to reconnect...`
164157
)
165158
}
166-
schedule_retry(port, was_opened ? RETRY_AFTER_DROP_MS : RETRY_IDLE_MS)
159+
schedule_retry(port, RETRY_IDLE_MS)
167160
}
168161
} catch {
169162
c.ws = null

‎docs/privacy.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ All your requests are sent directly to providers you set up with your own API ke
1818

1919
### Local browser communication
2020

21-
A local WebSockets server is run for bi-directional message passing on `localhost` ports 55155–55164.
21+
A local WebSockets server is run for bi-directional message passing on `localhost` ports 55155 and 55156.
2222

2323
### Source-available
2424

0 commit comments

Comments
 (0)