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 connecting = false;
|
||||||
let backoff = 250;
|
let backoff = 250;
|
||||||
const init = () => {
|
const init = () => {
|
||||||
console.error(timestamp(), '::SimplyWS:: connecting');
|
console.error(`::SimplyWS:: [${timestamp()}] connecting`);
|
||||||
connecting = false;
|
connecting = false;
|
||||||
if (client !== undefined) {
|
if (client !== undefined) {
|
||||||
client.removeAllListeners();
|
client.removeAllListeners();
|
||||||
|
|
@ -18,17 +18,17 @@ function WebSocketClient(url) {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = undefined;
|
timeout = undefined;
|
||||||
}
|
}
|
||||||
timeout = setTimeout(() => client.terminate(), 35000);
|
timeout = setTimeout(() => client.terminate(), 350000);
|
||||||
};
|
};
|
||||||
client.on('ping', () => {
|
client.on('ping', () => {
|
||||||
console.log(timestamp(), '::SimplyWS:: pinged');
|
console.log(`::SimplyWS:: [${timestamp()}] pinged`);
|
||||||
heartbeat();
|
heartbeat();
|
||||||
});
|
});
|
||||||
client.on('open', (e) => {
|
client.on('open', (e) => {
|
||||||
if (typeof this.onOpen === 'function') {
|
if (typeof this.onOpen === 'function') {
|
||||||
this.onOpen();
|
this.onOpen();
|
||||||
} else {
|
} else {
|
||||||
console.log(timestamp(), '::SimplyWS:: opened');
|
console.log(`::SimplyWS:: [${timestamp()}] opened`);
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
heartbeat();
|
heartbeat();
|
||||||
|
|
@ -37,7 +37,7 @@ function WebSocketClient(url) {
|
||||||
if (typeof this.onMessage === 'function') {
|
if (typeof this.onMessage === 'function') {
|
||||||
this.onMessage(e);
|
this.onMessage(e);
|
||||||
} else {
|
} else {
|
||||||
console.log(timestamp(), '::SimplyWS:: messaged');
|
console.log(`::SimplyWS:: [${timestamp()}] messaged`);
|
||||||
}
|
}
|
||||||
heartbeat();
|
heartbeat();
|
||||||
});
|
});
|
||||||
|
|
@ -51,7 +51,7 @@ function WebSocketClient(url) {
|
||||||
} else if (typeof this.onClose === 'function') {
|
} else if (typeof this.onClose === 'function') {
|
||||||
this.onClose();
|
this.onClose();
|
||||||
} else {
|
} else {
|
||||||
console.error(timestamp(), '::SimplyWS:: closed');
|
console.error(`::SimplyWS:: [${timestamp()}] closed`);
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -65,7 +65,7 @@ function WebSocketClient(url) {
|
||||||
} else if (typeof this.onError === 'function') {
|
} else if (typeof this.onError === 'function') {
|
||||||
this.onError(e);
|
this.onError(e);
|
||||||
} else {
|
} else {
|
||||||
console.error(timestamp(), '::SimplyWS : errored');
|
console.error(`::SimplyWS:: [${timestamp()}] errored`);
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
11
index.js
11
index.js
|
|
@ -9,8 +9,8 @@ const pkHeader = {
|
||||||
'Authorization': config.pk_token
|
'Authorization': config.pk_token
|
||||||
}
|
}
|
||||||
|
|
||||||
let cache = {}
|
|
||||||
let e
|
let e
|
||||||
|
let cache = {}
|
||||||
main = async () => {
|
main = async () => {
|
||||||
openWebSocket()
|
openWebSocket()
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +117,7 @@ generateResponse = async (target, data) => {
|
||||||
case "customStatus":
|
case "customStatus":
|
||||||
// find the "primary" fronter to move to the first element in the list
|
// find the "primary" fronter to move to the first element in the list
|
||||||
let primary = await findPrimary()
|
let primary = await findPrimary()
|
||||||
if (primary) {
|
if (primary && fronters.length > 1) {
|
||||||
if (fronters.indexOf(primary) > 0) {
|
if (fronters.indexOf(primary) > 0) {
|
||||||
fronters.splice(fronters.indexOf(primary), 1)
|
fronters.splice(fronters.indexOf(primary), 1)
|
||||||
fronters.unshift(primary)
|
fronters.unshift(primary)
|
||||||
|
|
@ -215,9 +215,12 @@ determineAction = async (eventData, frontData = []) => {
|
||||||
cache.frontHistory = frontHistory
|
cache.frontHistory = frontHistory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the difference between cached history and current front
|
||||||
let diff = calculateDiff(cache.frontHistory, frontData)
|
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.length == 1) {
|
||||||
if (diff[0].content.member) {
|
// if there's an endTime, it was a removal event
|
||||||
|
if (diff[0].content.endTime) {
|
||||||
action = 'remove'
|
action = 'remove'
|
||||||
}
|
}
|
||||||
else if (diff[0].content.customStatus) {
|
else if (diff[0].content.customStatus) {
|
||||||
|
|
@ -232,7 +235,7 @@ determineAction = async (eventData, frontData = []) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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