Files
clapper/clapper_src/webHelpers.js
Rafostar 3452990c28 Use "const" where possible
Increase readability by using "const" for identifiers that will not be reassigned
2021-01-05 20:13:53 +01:00

31 lines
649 B
JavaScript

const { Soup } = imports.gi;
const ByteArray = imports.byteArray;
const Debug = imports.clapper_src.debug;
const { debug } = Debug;
function parseData(dataType, bytes)
{
if(dataType !== Soup.WebsocketDataType.TEXT) {
debug('ignoring non-text WebSocket message');
return [false];
}
let parsedMsg = null;
const msg = bytes.get_data();
try {
parsedMsg = JSON.parse(ByteArray.toString(msg));
}
catch(err) {
debug(err);
}
if(!parsedMsg || !parsedMsg.action) {
debug('no "action" in parsed WebSocket message');
return [false];
}
return [true, parsedMsg];
}