[feature] integrated Logger

This commit is contained in:
Janis
2023-06-29 21:17:30 +02:00
parent 033cd77e04
commit e411c1c126
2 changed files with 7 additions and 8 deletions

View File

@@ -35,7 +35,7 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler {
}
reconnect() {
console.log("Reconnecting...")
Logger.log("Reconnecting...")
this.ws.close();
this.ws = new WebSocket(`ws://localhost:${this.remoteAppPort}`);
@@ -47,8 +47,7 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler {
// Connect to TS5 client
connect() {
console.log('Connecting to TS5 client...');
console.log(localStorage.getItem("apiKey"))
Logger.log('Connecting to TS5 client...');
// Create authentication payload
const initalPayload: IAuthSenderPayload = {
@@ -66,17 +65,17 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler {
this.ws.onopen = () => {
// Send authentication payload to TS5 client
console.log("Sending auth payload...")
this.ws.send(JSON.stringify(initalPayload));
Logger.wsSent(initalPayload);
};
this.ws.onclose = (event) => {
console.log("WebSocket connection closed", event);
Logger.log("WebSocket connection closed", event);
// If the connection was closed before authentication, remove the API key from local storage
// OBS weirdly caches the localstorage and is very stubborn about clearing it (even when clicken "Clear Cache")
if (!this.authenticated) {
console.log("WebSocket connection closed before authentication");
Logger.log("WebSocket connection closed before authentication");
localStorage.removeItem("apiKey");
}
@@ -90,7 +89,7 @@ export class TS5ConnectionHandler implements ITS5ConnectionHandler {
this.ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data)
Logger.wsRecieved(data)
switch (data.type) {
case "auth":

View File

@@ -15,7 +15,7 @@ export default class Logger {
}
// Log message received from the websocket to the console
public static wsReicved(data: object, message: string | undefined = undefined): void {
public static wsReceived(data: object, message: string | undefined = undefined): void {
console.log(`%c[WS Recieved] ${message ?? ""}`.trim(), "color: #8258c7", data);
}