Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ connected producers in the same workspace.
- **COMPAS: Clear Live Viewer** — clear that workspace and its replay history.
- **COMPAS: Restart Live Server** — apply host or port changes immediately.

### Extension API

Other extensions can discover the live server without asking the user to pin a
port. `compasThreejs.getLiveEndpoint` starts the server if it is not already
running and resolves to its WebSocket endpoint, or to `undefined` if it could
not be started:

```ts
const endpoint = await vscode.commands.executeCommand<string | undefined>(
"compasThreejs.getLiveEndpoint",
);
// "ws://127.0.0.1:54321/ws"
```

This exists because the port is normally ephemeral and otherwise appears only in
the status bar and the clipboard snippet, neither of which another extension can
read. The workspace to publish into is readable from
`compasThreejs.live.workspace`.

### Settings

- `compasThreejs.live.enabled` — start the server after VS Code starts.
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"onCommand:compasThreejs.openLiveViewer",
"onCommand:compasThreejs.copyConnectionSnippet",
"onCommand:compasThreejs.restartLiveServer",
"onCommand:compasThreejs.clearLiveViewer"
"onCommand:compasThreejs.clearLiveViewer",
"onCommand:compasThreejs.getLiveEndpoint"
],
"main": "./dist/extension.js",
"contributes": {
Expand All @@ -59,6 +60,10 @@
"command": "compasThreejs.clearLiveViewer",
"title": "COMPAS: Clear Live Viewer",
"icon": "$(clear-all)"
},
{
"command": "compasThreejs.getLiveEndpoint",
"title": "COMPAS: Get Live Server Endpoint"
}
],
"customEditors": [
Expand Down Expand Up @@ -119,6 +124,10 @@
},
{
"command": "compasThreejs.clearLiveViewer"
},
{
"command": "compasThreejs.getLiveEndpoint",
"when": "false"
}
]
}
Expand Down
14 changes: 14 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ export function activate(context: vscode.ExtensionContext): void {
}
},
),
// Public API for other extensions: the live server's WebSocket endpoint,
// starting the server if it is not already running. The port is normally
// ephemeral and is otherwise only visible in the status bar text and the
// clipboard snippet, neither of which another extension can read.
// Returns undefined if the server could not be started.
vscode.commands.registerCommand(
"compasThreejs.getLiveEndpoint",
async (): Promise<string | undefined> => {
if (!(await ensureServer(false))) {
return undefined;
}
return server.endpoint;
},
),
vscode.commands.registerCommand(
"compasThreejs.copyConnectionSnippet",
async () => {
Expand Down
Loading