mirror of
https://github.com/DerTyp7/teamspeak-obs-overlay.git
synced 2025-10-29 21:02:10 +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 ws = new WebSocket("ws://localhost:5899");
|
||||||
const paylaod = {
|
const paylaod = {
|
||||||
type: "auth",
|
type: "auth",
|
||||||
@@ -13,6 +13,9 @@ function connectToTeamSpeak() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
clientList.clear();
|
||||||
|
channelList.clear();
|
||||||
|
|
||||||
ws.onopen = (event) => {
|
ws.onopen = (event) => {
|
||||||
// Send payload to TS5 client
|
// Send payload to TS5 client
|
||||||
ws.send(JSON.stringify(paylaod));
|
ws.send(JSON.stringify(paylaod));
|
||||||
@@ -20,7 +23,7 @@ function connectToTeamSpeak() {
|
|||||||
|
|
||||||
ws.onmessage = (event) => {
|
ws.onmessage = (event) => {
|
||||||
let data = JSON.parse(event.data);
|
let data = JSON.parse(event.data);
|
||||||
|
console.log(data);
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "auth":
|
case "auth":
|
||||||
handleAuthMessage(data);
|
handleAuthMessage(data);
|
||||||
@@ -34,6 +37,8 @@ function connectToTeamSpeak() {
|
|||||||
case "talkStatusChanged":
|
case "talkStatusChanged":
|
||||||
handleTalkStatusChanged(data);
|
handleTalkStatusChanged(data);
|
||||||
break;
|
break;
|
||||||
|
case "clientSelfPropertyUpdated":
|
||||||
|
ws.close();
|
||||||
default:
|
default:
|
||||||
console.log(`No handler for event type: ${data.type}`);
|
console.log(`No handler for event type: ${data.type}`);
|
||||||
break;
|
break;
|
||||||
@@ -45,12 +50,13 @@ function connectToTeamSpeak() {
|
|||||||
|
|
||||||
ws.onerror = (err) => {
|
ws.onerror = (err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
connectToTeamSpeak(); // Reconnected
|
ws.close();
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = (event) => {
|
ws.onclose = (event) => {
|
||||||
console.log("Disconnected: " + event.reason);
|
console.log("Disconnected: " + event.reason);
|
||||||
connectToTeamSpeak(); // Reconnected
|
main(); // Reconnected
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
connectToTeamSpeak();
|
main();
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
function handleAuthMessage(data) {
|
function handleAuthMessage(data) {
|
||||||
console.log("Handling auth message");
|
console.log("Handling auth message");
|
||||||
channelList.items = parseChannelInfos(
|
channelList.setItems(
|
||||||
data.payload.connections[0].channelInfos
|
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);
|
thisClient = clientList.getById(data.payload.connections[0].clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,4 +50,19 @@ class List {
|
|||||||
clear() {
|
clear() {
|
||||||
this.items = [];
|
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