project update
This commit is contained in:
@@ -101,7 +101,7 @@ export const GetAllProjects = async (data: GetProjectsInterface) => {
|
||||
.find({
|
||||
isArchive: false,
|
||||
})
|
||||
.select("_id projectName createdBy thumbnail createdAt");
|
||||
.select("_id projectName createdBy thumbnail createdAt projectUuid");
|
||||
if (projectDatas) return { status: "Success", Datas: projectDatas };
|
||||
} catch (error: unknown) {
|
||||
return { status: error };
|
||||
|
||||
@@ -13,6 +13,7 @@ import { addfloat, deletefloat, duplicatefloat } from '../services/visualization
|
||||
import { addTemplate, addTemplateZone, TemplateZoneDelete } from '../services/visualization/templateServices.ts';
|
||||
import { deleteAssetModel, replaceEventDatas, setAssetModel } from '../services/assets/asset-Controller.ts';
|
||||
import { add3Dwidget, delete3Dwidget, update3D } from '../services/visualization/3dWidget-Service.ts';
|
||||
import { projectDeleteHandleEvent, projectHandleEvent, projecUpdateHandleEvent } from '../controllers/project/projectController.ts';
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +26,7 @@ const cameraHandleEvent = async (event: string, socket: Socket, data: any, names
|
||||
|
||||
let result;
|
||||
switch (event) {
|
||||
|
||||
|
||||
case EVENTS.setCamera: {
|
||||
result = await createCamera(data);
|
||||
|
||||
@@ -203,7 +204,7 @@ const floorItemsHandleEvent = async (event: string, socket: Socket, data: any, i
|
||||
// console.error(`Unhandled event type: ${event}`);
|
||||
}
|
||||
}
|
||||
const wallItemsHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
||||
const wallItemsHandleEvent = async (event: string, socket: Socket, data: any, io: any) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
return;
|
||||
@@ -266,7 +267,7 @@ const wallItemsHandleEvent =async (event: string, socket: Socket, data: any,io:a
|
||||
}
|
||||
|
||||
}
|
||||
const lineHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
||||
const lineHandleEvent = async (event: string, socket: Socket, data: any, io: any) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
return;
|
||||
@@ -378,7 +379,7 @@ const lineHandleEvent =async (event: string, socket: Socket, data: any,io:any) =
|
||||
|
||||
|
||||
}
|
||||
const userStatus =async (event: string, socket: Socket, data: any,io:any) => {
|
||||
const userStatus = async (event: string, socket: Socket, data: any, io: any) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
return;
|
||||
@@ -476,7 +477,7 @@ const zoneHandleEvent = async (event: string, socket: Socket, data: any, io: any
|
||||
const responseEvent = EVENTS.ZoneDeleteResponse
|
||||
// console.log('responseEvent: ', responseEvent);
|
||||
const organization = result?.organization
|
||||
if (organization) {
|
||||
if (organization) {
|
||||
socket.to(organization).emit(responseEvent, {
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
@@ -494,7 +495,7 @@ const zoneHandleEvent = async (event: string, socket: Socket, data: any, io: any
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
const panelHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
||||
@@ -598,7 +599,7 @@ const panelHandleEvent = async (event: string, socket: Socket, data: any, namesp
|
||||
|
||||
|
||||
}
|
||||
const widgetHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false,callback:any) => {
|
||||
const widgetHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false, callback: any) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
return;
|
||||
@@ -607,7 +608,7 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names
|
||||
let result;
|
||||
switch (event) {
|
||||
case EVENTS.addWidget: {
|
||||
result = await addWidget(data,callback);
|
||||
result = await addWidget(data, callback);
|
||||
// console.log('result: ', result);
|
||||
|
||||
if (result) {
|
||||
@@ -615,7 +616,7 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names
|
||||
const responseEvent = EVENTS.widgetUpdateResponse
|
||||
// console.log('responseEvent: ', responseEvent);
|
||||
const organization = result?.organization
|
||||
if (organization) {
|
||||
if (organization) {
|
||||
socket.to(organization).emit(responseEvent, {
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
@@ -637,7 +638,7 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names
|
||||
const responseEvent = EVENTS.widgetDeleteResponse
|
||||
// console.log('responseEvent: ', responseEvent);
|
||||
const organization = result?.organization
|
||||
|
||||
|
||||
if (organization) {
|
||||
socket.to(organization).emit(responseEvent, {
|
||||
success: result.success,
|
||||
@@ -659,7 +660,7 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names
|
||||
}
|
||||
|
||||
}
|
||||
const floatHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false,callback:any) => {
|
||||
const floatHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false, callback: any) => {
|
||||
// console.log('data: ', data);
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
@@ -715,7 +716,7 @@ const floatHandleEvent = async (event: string, socket: Socket, data: any, namesp
|
||||
break
|
||||
}
|
||||
case EVENTS.duplicatefloat: {
|
||||
const result = await duplicatefloat(data,callback)
|
||||
const result = await duplicatefloat(data, callback)
|
||||
if (result) {
|
||||
// console.log('result?.success: ', result.organization);
|
||||
const responseEvent = EVENTS.duplicatefloatUpdateResponse
|
||||
@@ -817,14 +818,14 @@ const templateHandleEvent = async (event: string, socket: Socket, data: any, nam
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false,callback:any ) => {
|
||||
const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false, callback: any) => {
|
||||
// console.log('data: ', data);
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
@@ -834,7 +835,7 @@ const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, nam
|
||||
let result;
|
||||
switch (event) {
|
||||
case EVENTS.add3DWidget: {
|
||||
result = await add3Dwidget(data,callback);
|
||||
result = await add3Dwidget(data, callback);
|
||||
|
||||
if (result) {
|
||||
const responseEvent = EVENTS.widget3DUpdateResponse
|
||||
@@ -903,7 +904,7 @@ const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, nam
|
||||
break
|
||||
}
|
||||
|
||||
// case EVENTS.deleteWidget: {
|
||||
// case EVENTS.deleteWidget: {
|
||||
// const result = await Widgetdelete(data)
|
||||
// if (result) {
|
||||
// // console.log('result?.success: ', result.organization);
|
||||
@@ -948,14 +949,14 @@ const modelAssetHandleEvent = async (event: string, socket: Socket, data: any, n
|
||||
result = await setAssetModel(data);
|
||||
if (result) emitEventResponse(socket, result.organization, EVENTS.assetUpdateResponse, result);
|
||||
break;
|
||||
case EVENTS.deleteAssetModel:
|
||||
result = await deleteAssetModel(data);
|
||||
if (result) emitEventResponse(socket, result.organization, EVENTS.assetDeleteResponse, result);
|
||||
break;
|
||||
case EVENTS.assetEventData:
|
||||
result = await replaceEventDatas(data);
|
||||
if (result) emitEventResponse(socket, result.organization, EVENTS.assetEventDataResponse, result);
|
||||
break;
|
||||
case EVENTS.deleteAssetModel:
|
||||
result = await deleteAssetModel(data);
|
||||
if (result) emitEventResponse(socket, result.organization, EVENTS.assetDeleteResponse, result);
|
||||
break;
|
||||
case EVENTS.assetEventData:
|
||||
result = await replaceEventDatas(data);
|
||||
if (result) emitEventResponse(socket, result.organization, EVENTS.assetEventDataResponse, result);
|
||||
break;
|
||||
// case EVENTS.setAssetModel: {
|
||||
// result = await setAssetModel(data);
|
||||
|
||||
@@ -1035,22 +1036,22 @@ const simulationHandleEvent = async (event: string, socket: Socket, data: any,)
|
||||
return;
|
||||
}
|
||||
let result;
|
||||
try {
|
||||
switch (event) {
|
||||
case EVENTS.setAssetModel:
|
||||
result = await addTemplate(data);
|
||||
if (result) emitEventResponse(socket, result.organization, EVENTS.zoneUpdateResponse, result);
|
||||
break;
|
||||
try {
|
||||
switch (event) {
|
||||
case EVENTS.setAssetModel:
|
||||
result = await addTemplate(data);
|
||||
if (result) emitEventResponse(socket, result.organization, EVENTS.zoneUpdateResponse, result);
|
||||
break;
|
||||
default:
|
||||
console.warn(`❌ Unknown event received: ${event}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`❌ Error handling event ${event}:`, error);
|
||||
} catch (error) {
|
||||
console.error(`❌ Error handling event ${event}:`, error);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
const emitEventResponse = (socket: Socket, organization: string, event: string, result: any) => {
|
||||
const emitEventResponse = (socket: Socket, organization: string, event: string, result: any) => {
|
||||
if (organization) {
|
||||
socket.to(organization).emit(event, {
|
||||
success: result.success,
|
||||
@@ -1109,24 +1110,26 @@ export const initSocketServer = (httpServer: any) => {
|
||||
// zone: io.of("/zone"),
|
||||
Builder: io.of('/Builder'),
|
||||
visualization: io.of('/Visualization'),
|
||||
project: io.of('/project'),
|
||||
|
||||
// widget:io.of('/widget')
|
||||
};
|
||||
|
||||
|
||||
// const onlineUsers = new Map<string, Set<string>>();
|
||||
const onlineUsers: { [organization: string]: Set<string> } = {};
|
||||
|
||||
|
||||
const handleNamespace = (namespaceName: string, namespace: any, ...eventHandlers: Function[]) => {
|
||||
|
||||
|
||||
namespace.on("connection", (socket: Socket) => {
|
||||
// console.log(`✅ Client connected to ${namespaceName}: ${socket.id}`);
|
||||
// Extract organization from query parameters
|
||||
|
||||
|
||||
// const organization = socket.handshake.query.organization as string;
|
||||
// const email = socket.handshake.query.email as string;
|
||||
const {organization,email} = socket.handshake.auth
|
||||
const { organization, email } = socket.handshake.auth
|
||||
// console.log(`🔍 Received organization: ${organization}`);
|
||||
|
||||
|
||||
if (organization) {
|
||||
socket.join(organization);
|
||||
// console.log(`🔹 Socket ${socket.id} joined room: ${organization}`);
|
||||
@@ -1134,20 +1137,20 @@ export const initSocketServer = (httpServer: any) => {
|
||||
// Handle all events
|
||||
if (organization && email) {
|
||||
if (!onlineUsers[organization]) {
|
||||
onlineUsers[organization] = new Set();
|
||||
onlineUsers[organization] = new Set();
|
||||
}
|
||||
onlineUsers[organization].add(socket.id);
|
||||
// console.log('onlineUsers: ', onlineUsers);
|
||||
|
||||
// console.log(`✅ User ${email} joined ${organization}. Active users:`, onlineUsers[organization]);
|
||||
}
|
||||
}
|
||||
|
||||
userStatus(EVENTS.connection, socket, socket.handshake.auth, socket);
|
||||
|
||||
socket.onAny((event: string, data: any ,callback:any) => {
|
||||
eventHandlers.forEach(handler => handler(event, socket, data, namespace,io,callback));
|
||||
socket.onAny((event: string, data: any, callback: any) => {
|
||||
eventHandlers.forEach(handler => handler(event, socket, data, namespace, io, callback));
|
||||
});
|
||||
|
||||
|
||||
// Handle disconnection
|
||||
socket.on("disconnect", () => {
|
||||
onlineUsers[organization]?.delete(socket.id);
|
||||
@@ -1156,7 +1159,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
// console.log(`❌ User ${email} disconnected. Remaining:`, onlineUsers[organization]);
|
||||
// console.log(`❌ Client disconnected from ${namespaceName}: ${socket.id}, Reason: ${reason}`);
|
||||
});
|
||||
|
||||
|
||||
// Handle reconnection (Auto rejoin)
|
||||
socket.on("reconnect", (attempt: number) => {
|
||||
// console.log(`🔄 Socket ${socket.id} reconnected to ${namespaceName} (Attempt ${attempt})`);
|
||||
@@ -1167,7 +1170,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 🔹 Apply namespace handlers
|
||||
// handleNamespace("camera", namespaces.camera, cameraHandleEvent);
|
||||
@@ -1178,8 +1181,8 @@ export const initSocketServer = (httpServer: any) => {
|
||||
// handleNamespace("zone", namespaces.zone, zoneHandleEvent);
|
||||
// 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,Widget3DHandleEvent);
|
||||
|
||||
handleNamespace("Builder", namespaces.Builder, userStatus, modelAssetHandleEvent, cameraHandleEvent, EnvironmentHandleEvent, wallItemsHandleEvent, lineHandleEvent, zoneHandleEvent);
|
||||
handleNamespace("Visualization", namespaces.visualization, panelHandleEvent, widgetHandleEvent, floatHandleEvent, templateHandleEvent, Widget3DHandleEvent);
|
||||
handleNamespace("project", namespaces.project, projectHandleEvent, projectDeleteHandleEvent, projecUpdateHandleEvent)
|
||||
return io;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user