mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
[MIRROR] Add Multishock integration (#11003)
Co-authored-by: ShadowLarkens <shadowlarkens@gmail.com>
This commit is contained in:
committed by
GitHub
parent
76c9d5e08a
commit
74d886613b
79
html/shock.js
Normal file
79
html/shock.js
Normal file
@@ -0,0 +1,79 @@
|
||||
let webSocket;
|
||||
let authKey;
|
||||
let lastCall;
|
||||
|
||||
const reactRoot = document.getElementById("react-root");
|
||||
if (reactRoot) {
|
||||
reactRoot.innerHTML = "<h1>You shouldn't see this window, update your skin.</h1>";
|
||||
}
|
||||
|
||||
Byond.subscribeTo("estop", function () {
|
||||
if (webSocket) {
|
||||
webSocket.close();
|
||||
} else {
|
||||
Byond.sendMessage("disconnected");
|
||||
}
|
||||
})
|
||||
|
||||
Byond.subscribeTo("connect", function (data) {
|
||||
if (webSocket) {
|
||||
webSocket.close();
|
||||
}
|
||||
webSocket = new WebSocket(`ws://localhost:${data.port}`);
|
||||
webSocket.sendJson = (data) => {
|
||||
webSocket.send(JSON.stringify(data));
|
||||
};
|
||||
authKey = JSON.parse(window.hubStorage.getItem("virgo-shocker-authkey"));
|
||||
webSocket.onopen = (ev) => {
|
||||
Byond.sendMessage("connected");
|
||||
};
|
||||
webSocket.onerror = (ev) => {
|
||||
Byond.sendMessage("error", ev);
|
||||
};
|
||||
webSocket.onclose = (ev) => {
|
||||
Byond.sendMessage("disconnected");
|
||||
}
|
||||
webSocket.onmessage = (ev) => {
|
||||
Byond.sendMessage("incomingMessage", { data: ev.data, lastCall });
|
||||
};
|
||||
});
|
||||
|
||||
Byond.subscribeTo("enumerateShockers", function () {
|
||||
if (!webSocket) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastCall = "get_devices";
|
||||
webSocket.sendJson({
|
||||
cmd: "get_devices",
|
||||
auth_key: authKey,
|
||||
});
|
||||
});
|
||||
|
||||
// data: {
|
||||
// "intensity": 10, // 1 - 100 - int
|
||||
// "duration": 1, // 0.1 - 15 - float
|
||||
// "shocker_ids": [], // [] - List of shocker ids
|
||||
// "warning": false, // true, false - will send a vibrate with the same intensity and duration
|
||||
// },
|
||||
Byond.subscribeTo("shock", function (data) {
|
||||
if (!webSocket) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastCall = "operate";
|
||||
webSocket.sendJson({
|
||||
"cmd": "operate",
|
||||
"value": {
|
||||
"intensity": data.intensity, // 1 - 100 - int
|
||||
"duration": data.duration, // 0.1 - 15 - float
|
||||
"shocker_option": "all", // all, random
|
||||
"action": "shock", // shock, vibrate, beep, end
|
||||
"shocker_ids": data.shocker_ids, // [] - List of shocker ids
|
||||
"device_ids": [], // [] - list of pishock client ids, if one of these is provided it will activate all shockers associated with it
|
||||
"warning": data.warning, // true, false - will send a vibrate with the same intensity and duration
|
||||
"held": false, // true, false - for continuous commands
|
||||
},
|
||||
"auth_key": authKey,
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user