BUILD114 — исправление Agent / Mapping / Settings
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
panelOpen: false,
|
||||
loading: false,
|
||||
timer: null,
|
||||
fastRefreshTimers: [],
|
||||
message: "",
|
||||
messageError: false,
|
||||
testOpenDeviceId: "",
|
||||
@@ -82,14 +83,44 @@
|
||||
}));
|
||||
}
|
||||
|
||||
function mergeDevicePayload(payload) {
|
||||
if (!payload || !payload.device_id) return;
|
||||
const index = state.devices.findIndex((item) => item.device_id === payload.device_id);
|
||||
const previous = index >= 0 ? state.devices[index] : {};
|
||||
const merged = { ...previous, ...payload };
|
||||
if (merged.paired_to_me) merged.pair_state = "mine";
|
||||
else if (merged.paired) merged.pair_state = "busy";
|
||||
else merged.pair_state = "free";
|
||||
if (index >= 0) state.devices.splice(index, 1, merged);
|
||||
else state.devices.unshift(merged);
|
||||
}
|
||||
|
||||
function scheduleFastRefresh() {
|
||||
state.fastRefreshTimers.forEach((timerId) => clearTimeout(timerId));
|
||||
state.fastRefreshTimers = [0, 250, 1000].map((delay) => setTimeout(() => {
|
||||
load(true).catch(() => {});
|
||||
}, delay));
|
||||
}
|
||||
|
||||
function refreshMappingInBackground(deviceId, assignment = null) {
|
||||
if (!deviceId || !assignment?.delivered) return;
|
||||
api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/apply-mapping`, { method: "POST" })
|
||||
.then(() => load(true))
|
||||
.catch((error) => console.warn("Could not refresh vMix Mapping after Agent selection", error));
|
||||
}
|
||||
|
||||
async function bindSelectedDevice(deviceId) {
|
||||
selectLocalDevice(deviceId);
|
||||
const token = currentSessionToken();
|
||||
if (!token) return null;
|
||||
return api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/select-session`, {
|
||||
const result = await api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/select-session`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ session_token: token }),
|
||||
// Agent selection must never wait for a full Mapping push. The session/match
|
||||
// assignment is committed first; Mapping is refreshed asynchronously below.
|
||||
body: JSON.stringify({ session_token: token, apply_mapping: false }),
|
||||
});
|
||||
refreshMappingInBackground(deviceId, result?.assignment || null);
|
||||
return result;
|
||||
}
|
||||
|
||||
function setMessage(text, error = false) {
|
||||
@@ -144,18 +175,25 @@
|
||||
render();
|
||||
try {
|
||||
if (action === "pair") {
|
||||
await api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/pair`, {
|
||||
const paired = await api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/pair`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ make_active: true }),
|
||||
});
|
||||
mergeDevicePayload(paired);
|
||||
render();
|
||||
await bindSelectedDevice(deviceId);
|
||||
scheduleFastRefresh();
|
||||
setMessage("Agent прикреплён и выбран для этой панели");
|
||||
} else if (action === "activate") {
|
||||
await api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/activate`, { method: "POST" });
|
||||
const activated = await api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/activate`, { method: "POST" });
|
||||
mergeDevicePayload(activated);
|
||||
render();
|
||||
await bindSelectedDevice(deviceId);
|
||||
scheduleFastRefresh();
|
||||
setMessage("Agent включён и выбран для этой панели");
|
||||
} else if (action === "select") {
|
||||
await bindSelectedDevice(deviceId);
|
||||
scheduleFastRefresh();
|
||||
setMessage("Эта панель теперь управляет выбранным Agent");
|
||||
} else if (action === "deactivate") {
|
||||
await api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/deactivate`, { method: "POST" });
|
||||
@@ -175,8 +213,15 @@
|
||||
} else if (action === "unpair") {
|
||||
if (!window.confirm("Отвязать этот agent от вашего аккаунта?")) return;
|
||||
await api(`/api/hockey/agents/devices/${encodeURIComponent(deviceId)}/pair`, { method: "DELETE" });
|
||||
const existing = state.devices.find((item) => item.device_id === deviceId);
|
||||
if (existing) mergeDevicePayload({
|
||||
...existing,
|
||||
paired: false, paired_to_me: false, active_for_account: false, pair_state: "free",
|
||||
current_match_id: "", assignment_id: "", owner: "",
|
||||
});
|
||||
if (state.testOpenDeviceId === deviceId) state.testOpenDeviceId = "";
|
||||
if (state.selectedDeviceId === deviceId) selectLocalDevice("");
|
||||
scheduleFastRefresh();
|
||||
setMessage("Agent отвязан");
|
||||
}
|
||||
await load(true);
|
||||
@@ -346,5 +391,5 @@
|
||||
load(true);
|
||||
state.timer = window.setInterval(() => {
|
||||
if (!document.hidden) load();
|
||||
}, 3000);
|
||||
}, 1500);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user