panel.widgets socket creation
This commit is contained in:
@@ -9,9 +9,10 @@ import { activeUserOffline, activeUsers, } from '../services/users/user-controll
|
||||
import { deleteZone, setZone } from '../services/lines/zone-controller.ts';
|
||||
import { addPanel, panelDelete } from '../services/visualization/panel-Services.ts';
|
||||
import { addWidget, Widgetdelete } from '../services/visualization/widget-Services.ts';
|
||||
import { addfloat } from '../services/visualization/floatWidgetService.ts';
|
||||
import { addfloat, deletefloat } from '../services/visualization/floatWidget-Service.ts';
|
||||
import { addTemplate } from '../services/visualization/templateServices.ts';
|
||||
import { deleteAssetModel, setAssetModel } from '../services/assets/asset-Controller.ts';
|
||||
import { add3Dwidget } from '../services/visualization/3dWidget-Service.ts';
|
||||
|
||||
|
||||
|
||||
@@ -546,7 +547,7 @@ const panelHandleEvent = async (event: string, socket: Socket, data: any, namesp
|
||||
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||
// console.log('emitTarget: ', emitTarget);
|
||||
if (organization) {
|
||||
socket.emit(responseEvent, {
|
||||
socket.to(organization).emit(responseEvent, {
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
data: result.data,
|
||||
@@ -674,6 +675,70 @@ const floatHandleEvent = async (event: string, socket: Socket, data: any, namesp
|
||||
}
|
||||
break
|
||||
}
|
||||
case EVENTS.deleteFloat: {
|
||||
const result = await deletefloat(data)
|
||||
if (result) {
|
||||
// console.log('result?.success: ', result.organization);
|
||||
const responseEvent = EVENTS.floatDeleteRespones
|
||||
// console.log('responseEvent: ', responseEvent);
|
||||
const organization = result?.organization
|
||||
// console.log('organization: ', organization);
|
||||
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||
// console.log('emitTarget: ', emitTarget);
|
||||
if (organization) {
|
||||
socket.to(organization).emit(responseEvent, {
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
data: result.data,
|
||||
error: result.error || null,
|
||||
socketId: socket.id,
|
||||
organization,
|
||||
});
|
||||
} else {
|
||||
console.warn(`Organization missing in response for event: ${event}`);
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
const templateHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
||||
// console.log('data: ', data);
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let result;
|
||||
switch (event) {
|
||||
case EVENTS.addTemplate: {
|
||||
result = await addTemplate(data);
|
||||
|
||||
if (result) {
|
||||
const responseEvent = EVENTS.templateUpdateRespones
|
||||
const organization = result?.organization
|
||||
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||
if (organization) {
|
||||
socket.to(organization).emit(responseEvent, {
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
data: result.data,
|
||||
error: result.error || null,
|
||||
socketId: socket.id,
|
||||
organization,
|
||||
});
|
||||
} else {
|
||||
console.warn(`Organization missing in response for event: ${event}`);
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
// case EVENTS.deleteWidget: {
|
||||
// const result = await Widgetdelete(data)
|
||||
// if (result) {
|
||||
@@ -706,7 +771,7 @@ const floatHandleEvent = async (event: string, socket: Socket, data: any, namesp
|
||||
}
|
||||
|
||||
}
|
||||
const templateHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
||||
const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
||||
// console.log('data: ', data);
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
@@ -715,11 +780,11 @@ const templateHandleEvent = async (event: string, socket: Socket, data: any, nam
|
||||
|
||||
let result;
|
||||
switch (event) {
|
||||
case EVENTS.addTemplate: {
|
||||
result = await addTemplate(data);
|
||||
case EVENTS.add3DWidget: {
|
||||
result = await add3Dwidget(data);
|
||||
|
||||
if (result) {
|
||||
const responseEvent = EVENTS.templateUpdateRespones
|
||||
const responseEvent = EVENTS.widget3DUpdateRespones
|
||||
const organization = result?.organization
|
||||
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||
@@ -877,7 +942,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
line: io.of("/line"),
|
||||
zone: io.of("/zone"),
|
||||
Builder: io.of('/Builder'),
|
||||
visualization: io.of('/visualization'),
|
||||
visualization: io.of('/Visualization'),
|
||||
// widget:io.of('/widget')
|
||||
};
|
||||
// 🔹 Function to handle connections in a namespace
|
||||
@@ -921,7 +986,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
|
||||
// const organization = socket.handshake.query.organization as string;
|
||||
const {organization,email} = socket.handshake.auth
|
||||
console.log(`🔍 Received organization: ${organization}`);
|
||||
// console.log(`🔍 Received organization: ${organization}`);
|
||||
|
||||
if (organization) {
|
||||
socket.join(organization);
|
||||
@@ -966,7 +1031,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
// handleNamespace("visualization", namespaces.panel, panelHandleEvent);
|
||||
// handleNamespace("widget", namespaces.visualization, widgetHandleEvent);
|
||||
handleNamespace("Builder", namespaces.Builder, userStatus,modelAssetHandleEvent, cameraHandleEvent, EnvironmentHandleEvent, wallItemsHandleEvent, lineHandleEvent,zoneHandleEvent);
|
||||
handleNamespace("visualization", namespaces.visualization, panelHandleEvent, widgetHandleEvent, floatHandleEvent, templateHandleEvent);
|
||||
handleNamespace("Visualization", namespaces.visualization, panelHandleEvent, widgetHandleEvent, floatHandleEvent, templateHandleEvent);
|
||||
|
||||
return io;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user