feat: Implement torch system via HTTP for multi-browser control

- Add /api/torch endpoints for torch state management
- Torch system uses HTTP polling instead of WebSocket
- Only browser with torch connects to MCP
- Other browsers disconnect and poll for torch state
- Auto-assign torch to first registered client
- Auto-reassign torch when holder disconnects

This approach requires no changes to WebMCP library.
This commit is contained in:
2026-02-14 16:32:52 -06:00
parent 647fb03516
commit fe99c9ff61
5 changed files with 394 additions and 115 deletions

View File

@@ -1,5 +1,4 @@
import { useCanvasStore } from '../stores/canvas'
import { useTorchStore } from '../stores/torch'
import { endpoints, isSecure, wsProtocol, hostname } from '../config/endpoints'
// WebMCP HTTP API base for direct token requests
@@ -118,43 +117,6 @@ function setupEventHandlers() {
updateConnectionInfo()
})
)
// Torch events
const torchStore = useTorchStore()
eventUnsubscribers.push(
webmcpInstance.on('clientId', (data: { id: string }) => {
console.log('[WebMCP] Client ID assigned:', data.id)
torchStore.setClientId(data.id)
})
)
eventUnsubscribers.push(
webmcpInstance.on('torchUpdate', (data: { holderId: string | null; clients: any[] }) => {
console.log('[WebMCP] Torch state updated:', data.holderId)
torchStore.setClients(data.clients)
})
)
eventUnsubscribers.push(
webmcpInstance.on('torchGranted', () => {
console.log('[WebMCP] Torch granted!')
torchStore.setRequesting(false)
})
)
eventUnsubscribers.push(
webmcpInstance.on('torchDenied', (data: { reason: string }) => {
console.warn('[WebMCP] Torch denied:', data.reason)
torchStore.setRequesting(false)
})
)
eventUnsubscribers.push(
webmcpInstance.on('torchReleased', () => {
console.log('[WebMCP] Torch released')
})
)
}
function updateConnectionInfo() {