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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user