feat: Introduce TinyMqttClient interface and implementation, update auth store for MQTT connection management

This commit is contained in:
2026-02-08 23:59:48 +07:00
parent 66028d934a
commit 85af2da6ad
6 changed files with 38 additions and 45 deletions

View File

@@ -195,20 +195,11 @@ const createAppRouter = () => {
router.beforeEach((to, from, next) => {
const auth = useAuthStore();
const head = inject(headSymbol);
let client: any;
(head as any).push(to.meta.head || {});
if (to.matched.some((record) => record.meta.requiresAuth)) {
if (!auth.user) {
if(client?.disconnect) (client as any)?.disconnect();
next({ name: "login" });
} else {
client = new TinyMqttClient(
'wss://broker.emqx.io:8084/mqtt',
[['ecos1231231'+auth.user.id+'#'].join("/")],
(topic, msg) => console.log(`Tín hiệu nhận được [${topic}]:`, msg)
);
client.connect();
next();
}
} else {