mirror of
https://github.com/DerTyp7/teamspeak-obs-overlay.git
synced 2025-10-29 12:52:09 +01:00
[feature] now resetting everything on reconnect
This commit is contained in:
16
js/app.js
16
js/app.js
@@ -1,4 +1,4 @@
|
||||
function connectToTeamSpeak() {
|
||||
function main() {
|
||||
const ws = new WebSocket("ws://localhost:5899");
|
||||
const paylaod = {
|
||||
type: "auth",
|
||||
@@ -13,6 +13,9 @@ function connectToTeamSpeak() {
|
||||
},
|
||||
};
|
||||
|
||||
clientList.clear();
|
||||
channelList.clear();
|
||||
|
||||
ws.onopen = (event) => {
|
||||
// Send payload to TS5 client
|
||||
ws.send(JSON.stringify(paylaod));
|
||||
@@ -20,7 +23,7 @@ function connectToTeamSpeak() {
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
let data = JSON.parse(event.data);
|
||||
|
||||
console.log(data);
|
||||
switch (data.type) {
|
||||
case "auth":
|
||||
handleAuthMessage(data);
|
||||
@@ -34,6 +37,8 @@ function connectToTeamSpeak() {
|
||||
case "talkStatusChanged":
|
||||
handleTalkStatusChanged(data);
|
||||
break;
|
||||
case "clientSelfPropertyUpdated":
|
||||
ws.close();
|
||||
default:
|
||||
console.log(`No handler for event type: ${data.type}`);
|
||||
break;
|
||||
@@ -45,12 +50,13 @@ function connectToTeamSpeak() {
|
||||
|
||||
ws.onerror = (err) => {
|
||||
console.error(err);
|
||||
connectToTeamSpeak(); // Reconnected
|
||||
ws.close();
|
||||
return;
|
||||
};
|
||||
|
||||
ws.onclose = (event) => {
|
||||
console.log("Disconnected: " + event.reason);
|
||||
connectToTeamSpeak(); // Reconnected
|
||||
main(); // Reconnected
|
||||
};
|
||||
}
|
||||
connectToTeamSpeak();
|
||||
main();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
function handleAuthMessage(data) {
|
||||
console.log("Handling auth message");
|
||||
channelList.items = parseChannelInfos(
|
||||
data.payload.connections[0].channelInfos
|
||||
channelList.setItems(
|
||||
parseChannelInfos(data.payload.connections[0].channelInfos)
|
||||
);
|
||||
clientList.setItems(
|
||||
parseClientInfos(data.payload.connections[0].clientInfos)
|
||||
);
|
||||
clientList.items = parseClientInfos(data.payload.connections[0].clientInfos);
|
||||
thisClient = clientList.getById(data.payload.connections[0].clientId);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,4 +50,19 @@ class List {
|
||||
clear() {
|
||||
this.items = [];
|
||||
}
|
||||
|
||||
setItems(items) {
|
||||
// Never tested
|
||||
let duplicateFound = false;
|
||||
items.forEach((e1, i) => {
|
||||
items.forEach((e2, j) => {
|
||||
if (e1.id === e2.id && i != j) {
|
||||
duplicateFound = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!duplicateFound) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user