mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-31 08:21:59 +02:00
Move "clapper_src" dir to "src"
The "clapper_src" directory name was unusual. This was done to make it work as a widget for other apps. Now that this functionality got removed it can be named simply "src" as recommended by guidelines.
This commit is contained in:
30
src/webHelpers.js
Normal file
30
src/webHelpers.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const { Soup } = imports.gi;
|
||||
const ByteArray = imports.byteArray;
|
||||
const Debug = imports.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];
|
||||
}
|
Reference in New Issue
Block a user