admin side scan connection

This commit is contained in:
Julian Krauser 2025-07-15 15:16:18 +02:00
parent ed947e5777
commit 3e47d3ebf6
3 changed files with 51 additions and 13 deletions

View file

@ -1,5 +1,8 @@
import { defineStore } from "pinia";
import { v4 as uuid } from "uuid";
import { SocketManager } from "../../socketManager";
import { SocketConnectionTypes } from "../../enums/socketEnum";
import { useNotificationStore } from "../notification";
export const useScannerStore = defineStore("scanner", {
state: () => {
@ -13,13 +16,40 @@ export const useScannerStore = defineStore("scanner", {
actions: {
startSession() {
if (this.inUse) return;
const notificationStore = useNotificationStore();
this.roomId = uuid();
this.inUse = true;
let connection = SocketManager.establishConnection(SocketConnectionTypes.scanner);
connection.on("connect", () => {
SocketManager.getConnection(SocketConnectionTypes.scanner)?.emit("session:create", this.roomId);
});
connection.on("status-session:create", () => {
notificationStore.push("Socket-Erfolg", `Scan-Session gestartet`, "success");
});
connection.on("status-session:close", () => {
notificationStore.push("Socket", `Scan-Session beendet`, "info");
SocketManager.getConnection(SocketConnectionTypes.scanner)?.disconnect();
});
connection.on("package-scanner_join", (socketId: string) => {
this.connectedDevices++;
notificationStore.push("Scan-Verbindung", `Neuer Scanner verbunden`, "info");
});
connection.on("package-scanner_leave", (socketId: string) => {
this.connectedDevices--;
notificationStore.push("Scan-Verbindung", `Scanner getrennt`, "info");
});
connection.on("package-scan_receive", (result: string) => {
this.results.push(result);
notificationStore.push("Scan", `Neuen Scan erhalten`, "info");
});
},
endSession() {
this.inUse = false;
this.roomId = undefined;
this.results = [];
SocketManager.getConnection(SocketConnectionTypes.scanner)?.emit("session:close");
},
removeElementFromResults(el: string) {
this.results = this.results.filter((result) => result !== el);