fix(pi-family): per-tab client_id for the QEMU-Linux WebSocket
With the bare boardId as client_id, two tabs (or two users) on the same example shared one QEMU instance: serial output went to whichever socket connected last, keystrokes interleaved and one tab's stop killed the other's guest. Suffix the tab session id so each tab gets its own instance (stopped on its own disconnect, like the ESP32 workers).
This commit is contained in:
parent
cdf4aad4ae
commit
a766d0cde3
|
|
@ -27,6 +27,8 @@
|
|||
* { type: 'error', data: { message: string } }
|
||||
*/
|
||||
|
||||
import { getTabSessionId } from './Esp32Bridge';
|
||||
|
||||
const API_BASE = (): string => {
|
||||
// The desktop shell injects the sidecar URL at runtime (random port) via
|
||||
// window.__VELXIO_API_BASE__; honor it first so the QEMU-board WebSocket
|
||||
|
|
@ -92,8 +94,13 @@ export class RaspberryPi3Bridge {
|
|||
|
||||
const base = API_BASE();
|
||||
const wsProtocol = base.startsWith('https') ? 'wss:' : 'ws:';
|
||||
// Scope the backend client_id to THIS tab. With the bare boardId, two
|
||||
// tabs (or two users) opening the same example shared one QEMU
|
||||
// instance: serial output went to whichever WebSocket connected last,
|
||||
// keystrokes interleaved, and one tab's stop killed the other's guest.
|
||||
const clientId = `${this.boardId}--${getTabSessionId()}`;
|
||||
const wsUrl =
|
||||
base.replace(/^https?:/, wsProtocol) + `/simulation/ws/${encodeURIComponent(this.boardId)}`;
|
||||
base.replace(/^https?:/, wsProtocol) + `/simulation/ws/${encodeURIComponent(clientId)}`;
|
||||
|
||||
const socket = new WebSocket(wsUrl);
|
||||
this.socket = socket;
|
||||
|
|
|
|||
Loading…
Reference in New Issue