Added transmit frontend call
This commit is contained in:
36
www/main.js
36
www/main.js
@ -1 +1,37 @@
|
||||
async function POST(path, data={}) {
|
||||
return new Promise(function (onSuccess, onError) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', path, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
onSuccess(xhr);
|
||||
} else {
|
||||
onError(xhr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = () => onError(xhr);
|
||||
xhr.send(JSON.stringify(data));
|
||||
});
|
||||
}
|
||||
|
||||
function assert(condition, message) {
|
||||
if (!condition) {
|
||||
throw message || "Assertion failed";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function transmit(transmitterID, channel, action, intensity=0, lucalEncoded=false) {
|
||||
assert(typeof transmitterID === 'number');
|
||||
assert(typeof channel === 'number');
|
||||
assert(['shock', 'vibrate', 'beep'].includes(action));
|
||||
assert(typeof intensity === 'number');
|
||||
assert(typeof lucalEncoded === 'boolean');
|
||||
POST('/transmit', {transmitterID: transmitterID, channel: channel, action: action, intensity: intensity, lucalEncoded: lucalEncoded});
|
||||
}
|
||||
|
||||
console.debug('Main loaded!');
|
||||
|
||||
Reference in New Issue
Block a user