minor changes
This commit is contained in:
parent
4f2a43451c
commit
966223bc0f
2 changed files with 14 additions and 11 deletions
|
|
@ -7,7 +7,7 @@ function WebSocketClient(url) {
|
|||
let connecting = false;
|
||||
let backoff = 250;
|
||||
const init = () => {
|
||||
console.error(timestamp(), '::SimplyWS:: connecting');
|
||||
console.error(`::SimplyWS:: [${timestamp()}] connecting`);
|
||||
connecting = false;
|
||||
if (client !== undefined) {
|
||||
client.removeAllListeners();
|
||||
|
|
@ -18,17 +18,17 @@ function WebSocketClient(url) {
|
|||
clearTimeout(timeout);
|
||||
timeout = undefined;
|
||||
}
|
||||
timeout = setTimeout(() => client.terminate(), 35000);
|
||||
timeout = setTimeout(() => client.terminate(), 350000);
|
||||
};
|
||||
client.on('ping', () => {
|
||||
console.log(timestamp(), '::SimplyWS:: pinged');
|
||||
console.log(`::SimplyWS:: [${timestamp()}] pinged`);
|
||||
heartbeat();
|
||||
});
|
||||
client.on('open', (e) => {
|
||||
if (typeof this.onOpen === 'function') {
|
||||
this.onOpen();
|
||||
} else {
|
||||
console.log(timestamp(), '::SimplyWS:: opened');
|
||||
console.log(`::SimplyWS:: [${timestamp()}] opened`);
|
||||
console.log(e);
|
||||
}
|
||||
heartbeat();
|
||||
|
|
@ -37,7 +37,7 @@ function WebSocketClient(url) {
|
|||
if (typeof this.onMessage === 'function') {
|
||||
this.onMessage(e);
|
||||
} else {
|
||||
console.log(timestamp(), '::SimplyWS:: messaged');
|
||||
console.log(`::SimplyWS:: [${timestamp()}] messaged`);
|
||||
}
|
||||
heartbeat();
|
||||
});
|
||||
|
|
@ -51,7 +51,7 @@ function WebSocketClient(url) {
|
|||
} else if (typeof this.onClose === 'function') {
|
||||
this.onClose();
|
||||
} else {
|
||||
console.error(timestamp(), '::SimplyWS:: closed');
|
||||
console.error(`::SimplyWS:: [${timestamp()}] closed`);
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
|
@ -65,7 +65,7 @@ function WebSocketClient(url) {
|
|||
} else if (typeof this.onError === 'function') {
|
||||
this.onError(e);
|
||||
} else {
|
||||
console.error(timestamp(), '::SimplyWS : errored');
|
||||
console.error(`::SimplyWS:: [${timestamp()}] errored`);
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
11
index.js
11
index.js
|
|
@ -9,8 +9,8 @@ const pkHeader = {
|
|||
'Authorization': config.pk_token
|
||||
}
|
||||
|
||||
let cache = {}
|
||||
let e
|
||||
let cache = {}
|
||||
main = async () => {
|
||||
openWebSocket()
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ generateResponse = async (target, data) => {
|
|||
case "customStatus":
|
||||
// find the "primary" fronter to move to the first element in the list
|
||||
let primary = await findPrimary()
|
||||
if (primary) {
|
||||
if (primary && fronters.length > 1) {
|
||||
if (fronters.indexOf(primary) > 0) {
|
||||
fronters.splice(fronters.indexOf(primary), 1)
|
||||
fronters.unshift(primary)
|
||||
|
|
@ -215,9 +215,12 @@ determineAction = async (eventData, frontData = []) => {
|
|||
cache.frontHistory = frontHistory
|
||||
}
|
||||
|
||||
// get the difference between cached history and current front
|
||||
let diff = calculateDiff(cache.frontHistory, frontData)
|
||||
// we handle one thing at a time, although this should be expanded since you can modify multiple custom statuses at once
|
||||
if (diff.length == 1) {
|
||||
if (diff[0].content.member) {
|
||||
// if there's an endTime, it was a removal event
|
||||
if (diff[0].content.endTime) {
|
||||
action = 'remove'
|
||||
}
|
||||
else if (diff[0].content.customStatus) {
|
||||
|
|
@ -232,7 +235,7 @@ determineAction = async (eventData, frontData = []) => {
|
|||
}
|
||||
}
|
||||
else {
|
||||
console.log('::SimplyWS:: Unrecognized diff: ' + JSON.stringify(diff))
|
||||
console.error('::SimplyWS:: Unrecognized diff: ' + JSON.stringify(diff))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue