Merge branch 'main' into branch-1
This commit is contained in:
@@ -7,7 +7,7 @@ ENV NODE_ENV development
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
RUN npm install -g npm
|
||||
RUN npm install -g tsx
|
||||
|
||||
COPY package.json /usr/src/app/package.json
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import dotenv from "dotenv"; // Import dotenv
|
||||
|
||||
dotenv.config();
|
||||
|
||||
import { initSocketServer } from "./socket/socketManager";
|
||||
import { initSocketServer } from "./socket/socketManager.ts";
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.SOCKET_PORT;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import floorItemsModel from "../../../shared/model/assets/flooritems-Model";
|
||||
import floorItemsModel from "../../../shared/model/assets/flooritems-Model.ts";
|
||||
|
||||
export const setFloorItems = async (data: any) => {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import wallItenmModel from "../../../shared/model/assets/wallitems-Model";
|
||||
import wallItenmModel from "../../../shared/model/assets/wallitems-Model.ts";
|
||||
|
||||
|
||||
export const setWallItems = async (data: any) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response } from "express";
|
||||
import { Socket } from "socket.io";
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model";
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model.ts";
|
||||
|
||||
export const createCamera = async (data: any,) => {
|
||||
const { userId, position, target, organization,rotation } = data
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import environmentModel from "../../../shared/model/environments/environments-Model";
|
||||
import environmentModel from "../../../shared/model/environments/environments-Model.ts";
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import lineModel from "../../../shared/model/lines/lines-Model";
|
||||
import lineModel from "../../../shared/model/lines/lines-Model.ts";
|
||||
|
||||
|
||||
export const createLineItems = async (data: any)=>{
|
||||
|
||||
79
src/socket-server/services/lines/zone-Services.ts
Normal file
79
src/socket-server/services/lines/zone-Services.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import zoneModel from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
|
||||
// export const setZone = async (data: any) => {
|
||||
// const { organization, userId, zoneData } = data
|
||||
|
||||
// try {
|
||||
// console.log('data: ', data);
|
||||
// const zoneId = zoneData.zoneId
|
||||
// const points = zoneData.points
|
||||
// const zoneName = zoneData.zoneName
|
||||
// const layer = zoneData.layer
|
||||
// const viewPortCenter = zoneData.viewPortCenter
|
||||
// const viewPortposition = zoneData.viewPortposition
|
||||
// const sceneID = zoneData.sceneID
|
||||
|
||||
// const existingZone = await zoneModel(organization).findOne({
|
||||
// zoneId: zoneId,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (!existingZone) {
|
||||
// const newZone = await zoneModel(organization).create({
|
||||
// zoneName: zoneName,
|
||||
// zoneId: zoneId,
|
||||
// zonePoints: points,
|
||||
// viewPortposition: viewPortposition,
|
||||
// viewPortCenter: viewPortCenter,
|
||||
// createdBy: userId,
|
||||
// layer: layer,
|
||||
// sceneID: sceneID,
|
||||
// });
|
||||
// if (newZone)
|
||||
// return { success: true, message: 'zone created', data: newZone, organization: organization }
|
||||
|
||||
// } else {
|
||||
// const replaceZone = await zoneModel(organization).findOneAndUpdate(
|
||||
// { zoneId: zoneId, isArchive: false },
|
||||
// {
|
||||
// zonePoints: points,
|
||||
// viewPortposition: viewPortposition,
|
||||
// viewPortCenter: viewPortCenter,
|
||||
// },
|
||||
// { new: true }
|
||||
// );
|
||||
// if (!replaceZone)
|
||||
// return { success: false, message: 'Zone not updated',organization: organization }
|
||||
// else
|
||||
// return { success: true, message: 'zone updated', data: replaceZone, organization: organization }
|
||||
|
||||
// }
|
||||
// } catch (error: any) {
|
||||
// return { success: false, message: 'Zone not found', error,organization: organization }
|
||||
// }
|
||||
// }
|
||||
// export const deleteZone = async (data: any) => {
|
||||
// const { organization, userId, zoneId } = data
|
||||
// try {
|
||||
// const existingZone = await zoneModel(organization).findOne({
|
||||
// zoneId: zoneId,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (!existingZone) {
|
||||
// return { success: true, message: 'Invalid zone ID', organization: organization }
|
||||
// } else {
|
||||
// const deleteZone = await zoneModel(organization).findOneAndUpdate(
|
||||
// { zoneId: zoneId, isArchive: false },
|
||||
// {
|
||||
// isArchive: true,
|
||||
// },
|
||||
// { new: true }
|
||||
// );
|
||||
|
||||
// if (deleteZone) {
|
||||
// return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
|
||||
// }
|
||||
// }
|
||||
// } catch (error: any) {
|
||||
// return { success: false, message: 'Zone not found', error,organization: organization }
|
||||
// }
|
||||
// }
|
||||
@@ -1,4 +1,4 @@
|
||||
import zoneModel from "../../../shared/model/lines/zone-Model";
|
||||
import zoneModel from "../../../shared/model/lines/zone-Model.ts";
|
||||
|
||||
export const setZone = async (data: any) => {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model"
|
||||
import userModel from "../../../shared/model/user-Model"
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model.ts"
|
||||
import userModel from "../../../shared/model/user-Model.ts"
|
||||
|
||||
export const activeUsers = async (data: any) => {
|
||||
const {organization}=data
|
||||
|
||||
105
src/socket-server/services/visualization/panel-Services.ts
Normal file
105
src/socket-server/services/visualization/panel-Services.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
|
||||
export const addPanel = async (data: any) => {
|
||||
const{organization,zoneId,panelName,panelOrder}=data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const findZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
console.log('findZone: ', findZone);
|
||||
if (!findZone) {
|
||||
return { success: false, message: 'Zone not found',organization: organization}
|
||||
|
||||
}
|
||||
const updatezone = await zoneSchema(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneId, isArchive: false },
|
||||
{ panelOrder: panelOrder },
|
||||
{ new: true }
|
||||
);
|
||||
const existingPanels = await panelSchema(organization).find({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
const existingPanelNames = existingPanels.map(
|
||||
(panel: any) => panel.panelName
|
||||
);
|
||||
|
||||
const missingPanels = panelOrder.filter(
|
||||
(panelName: string) => !existingPanelNames.includes(panelName)
|
||||
);
|
||||
|
||||
const createdPanels = [];
|
||||
for (const panelName of missingPanels) {
|
||||
const newPanel = await panelSchema(organization).create({
|
||||
zoneId: zoneId,
|
||||
panelName: panelName,
|
||||
widgets: [],
|
||||
isArchive: false,
|
||||
});
|
||||
createdPanels.push(newPanel);
|
||||
}
|
||||
|
||||
if (createdPanels.length === 0) {
|
||||
return { success: false, message: "No new panels were created. All panels already exist",organization: organization}
|
||||
}
|
||||
// const IDdata = createdPanels.map((ID: any) => {
|
||||
// return ID._id;
|
||||
// });
|
||||
console.log("IDdata: ", createdPanels);
|
||||
createdPanels
|
||||
return { success: true, message: "Panels created successfully", data: createdPanels, organization: organization }
|
||||
}catch (error) {
|
||||
return { success: false, message: 'Panel not found', error,organization: organization }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
export const panelDelete = async (data: any) => {
|
||||
const { organization, panelName, zoneId } = data;
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: 'Zone not found',organization: organization}
|
||||
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
panelName: panelName,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel)
|
||||
return { success: false, message: 'Panel Already Deleted',organization: organization}
|
||||
const updatePanel = await panelSchema(organization).updateOne(
|
||||
{ _id: existingPanel._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
const existingWidgets = await widgetSchema(organization).find({
|
||||
panelID:existingPanel._id,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
for (const widgetData of existingWidgets) {
|
||||
widgetData.isArchive = true;
|
||||
await widgetData.save();
|
||||
}
|
||||
|
||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||
const index1 = existingZone.panelOrder.indexOf(existingPanel.panelName);
|
||||
existingZone.panelOrder.splice(index1, 1);
|
||||
|
||||
const panelDeleteDatas= await existingZone.save();
|
||||
return { success: true, message: 'Panel deleted successfully',data:panelDeleteDatas,organization: organization}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
return { success: false, message: 'Panel not found', error,organization: organization } }
|
||||
|
||||
}
|
||||
119
src/socket-server/services/visualization/widget-Services.ts
Normal file
119
src/socket-server/services/visualization/widget-Services.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export const addWidget = async (data: any) => {
|
||||
const { organization,panel,zoneId,widget,} = data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
panelName: widget.panel,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel)
|
||||
|
||||
return { success: false, message: "panelName not found",organization: organization}
|
||||
|
||||
|
||||
if (existingPanel.panelName === widget.panel) {
|
||||
const existingWidget = await widgetSchema(organization).findOne({
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
isArchive: false,
|
||||
// widgetOrder: widget.widgetOrder,
|
||||
});
|
||||
if (existingWidget) {
|
||||
const updateWidget = await widgetSchema(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
Data: {
|
||||
measurements: widget.Data.measurements,
|
||||
duration: widget.Data.duration,
|
||||
},
|
||||
isArchive: false,
|
||||
},
|
||||
},
|
||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||
);
|
||||
|
||||
return { success: false, message: "Widget updated successfully",data:updateWidget,organization: organization}
|
||||
|
||||
}
|
||||
const newWidget = await widgetSchema(organization).create({
|
||||
widgetID: widget.id,
|
||||
elementType: widget.type,
|
||||
// widgetOrder: widgetOrder,
|
||||
widgetName: widget.widgetName,
|
||||
panelID: existingPanel._id,
|
||||
widgetside: widget.panel,
|
||||
// Data: {
|
||||
// measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1hr",
|
||||
// },
|
||||
});
|
||||
if (newWidget) {
|
||||
existingPanel.widgets.push(newWidget._id);
|
||||
await existingPanel.save();
|
||||
return { success: true, message: "Widget already exist for the widgetID",data:existingPanel,organization: organization}
|
||||
}
|
||||
}
|
||||
return { success: false, message: "Type mismatch",organization: organization}
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: 'widge not found', error,organization: organization }
|
||||
}
|
||||
}
|
||||
export const Widgetdelete = async (data: any) => {
|
||||
const { widgetID, organization } = data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const findWidget = await widgetSchema(organization).findOne({
|
||||
widgetID: widgetID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findWidget)
|
||||
return { success: false, message: "Widget not found",organization: organization}
|
||||
const widgetData = await widgetSchema(organization).updateOne(
|
||||
{ _id: findWidget._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
if (widgetData) {
|
||||
// Find all widgets in the same panel and sort them by widgetOrder
|
||||
const widgets = await widgetSchema(organization).find({
|
||||
panelID: findWidget.panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
// .sort({ widgetOrder: 1 });
|
||||
|
||||
// Reassign widgetOrder values
|
||||
// for (let i = 0; i < widgets.length; i++) {
|
||||
// widgets[i].widgetOrder = (i + 1).toString(); // Convert to string
|
||||
// await widgets[i].save();
|
||||
// }
|
||||
const panelData = await panelSchema(organization).findOne({
|
||||
_id: findWidget.panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (panelData.widgets.includes(findWidget._id)) {
|
||||
const index1 = panelData.widgets.indexOf(findWidget._id);
|
||||
panelData.widgets.splice(index1, 1);
|
||||
}
|
||||
const panelDeletedata = await panelData.save();
|
||||
console.log('Widget deleted successfully: ');
|
||||
return { success: false, message: "Widget deleted successfully",data:panelDeletedata,organization: organization}
|
||||
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "An unknown error occurred.", error ,organization: organization}
|
||||
}
|
||||
}
|
||||
@@ -47,30 +47,4 @@ export const EVENTS = {
|
||||
zoneUpdateRespones:"zone:response:updates",
|
||||
deleteZone:"v2:zone:delete",
|
||||
ZoneDeleteRespones:"zone:response:delete",
|
||||
|
||||
//visualization
|
||||
addPanel:"v2:viz-panel:add",
|
||||
panelUpdateRespones:"viz-panel:response:updates",
|
||||
deletePanel:"v2:viz-panel:delete",
|
||||
PanelDeleteRespones:"viz-panel:response:delete",
|
||||
|
||||
//widget
|
||||
addWidget:"v2:viz-widget:add",
|
||||
widgetUpdateRespones:"viz-widget:response:updates",
|
||||
deleteWidget:"v2:viz-widget:delete",
|
||||
widgetDeleteRespones:"viz-widget:response:delete",
|
||||
|
||||
//float
|
||||
addFloat: "v2:viz-float:add",
|
||||
floatUpdateRespones: "viz-float:response:updates",
|
||||
deleteFloat: "v2:viz-float:delete",
|
||||
floatDeleteRespones: "viz-float:response:delete",
|
||||
|
||||
//template
|
||||
addTemplate:"v2:viz-template:add",
|
||||
templateUpdateRespones:"viz-template:response:updates",
|
||||
|
||||
//model-asset
|
||||
setAssetModel: "v2:model-asset:add",
|
||||
assetUpdateRespones: "model-asset:response:updates",
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { EVENTS } from './events';
|
||||
import { createCamera } from '../services/camera/camera-Controller';
|
||||
import { setEnvironment } from '../services/environments/environments-controller';
|
||||
import { deleteFloorItems, setFloorItems } from '../services/assets/flooritem-Controller';
|
||||
import { deleteWallItems, setWallItems } from '../services/assets/wallitem-Controller';
|
||||
import { deleteLineItems, deleteLinPoiteItems, updateLineItems ,createLineItems, deleteLayer} from '../services/lines/line-Controller';
|
||||
import { activeUserOffline, activeUsers } from '../services/users/user-controller';
|
||||
import { deleteZone, setZone } from '../services/lines/zone-controller';
|
||||
import { EVENTS } from './events.ts';
|
||||
import { createCamera } from '../services/camera/camera-Controller.ts';
|
||||
import { setEnvironment } from '../services/environments/environments-controller.ts';
|
||||
import { deleteFloorItems, setFloorItems } from '../services/assets/flooritem-Controller.ts';
|
||||
import { deleteWallItems, setWallItems } from '../services/assets/wallitem-Controller.ts';
|
||||
import { deleteLineItems, deleteLinPoiteItems, updateLineItems ,createLineItems, deleteLayer} from '../services/lines/line-Controller.ts';
|
||||
import { activeUserOffline, activeUsers } from '../services/users/user-controller.ts';
|
||||
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';
|
||||
|
||||
|
||||
|
||||
@@ -449,6 +451,142 @@ switch (event) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
const panelHandleEvent=async(event: string, socket: Socket, data: any,namespace: any, notifySender: boolean = false)=>{
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let result;
|
||||
switch (event) {
|
||||
case EVENTS.addPanel:{
|
||||
result = await addPanel(data);
|
||||
console.log('result: ', result);
|
||||
|
||||
if (result) {
|
||||
console.log('result?.success: ', result.organization);
|
||||
const responseEvent = EVENTS.panelUpdateRespones
|
||||
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);
|
||||
|
||||
socket.to(organization).emit(responseEvent, {
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
data: result.data,
|
||||
error: result.error,
|
||||
socketId: socket.id,
|
||||
organization: result.organization,
|
||||
});
|
||||
}
|
||||
break;}
|
||||
case EVENTS.deletePanel: {
|
||||
const result = await panelDelete(data)
|
||||
if (result) {
|
||||
// console.log('result?.success: ', result.organization);
|
||||
const responseEvent = EVENTS.PanelDeleteRespones
|
||||
// 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.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 widgetHandleEvent = 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.addWidget: {
|
||||
result = await addWidget(data);
|
||||
// console.log('result: ', result);
|
||||
|
||||
if (result) {
|
||||
// console.log('result?.success: ', result.organization);
|
||||
const responseEvent = EVENTS.widgetUpdateRespones
|
||||
// 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
|
||||
}
|
||||
case EVENTS.deleteWidget: {
|
||||
const result = await Widgetdelete(data)
|
||||
if (result) {
|
||||
// console.log('result?.success: ', result.organization);
|
||||
const responseEvent = EVENTS.widgetDeleteRespones
|
||||
// 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.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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export const initSocketServer = (httpServer: any) => {
|
||||
const io = new Server(httpServer, {
|
||||
@@ -458,6 +596,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// Listen for new connections
|
||||
io.on(EVENTS.connection, (socket: Socket) => {
|
||||
// console.log(`New client connected: ${socket.id}`);
|
||||
@@ -483,62 +622,5 @@ userStatus(EVENTS.connection, socket, socket.handshake.auth,io);
|
||||
});
|
||||
});
|
||||
|
||||
// 🔹 Create different namespaces
|
||||
const namespaces = {
|
||||
camera: io.of("/camera"),
|
||||
environment: io.of("/environment"),
|
||||
floorItems: io.of("/floorItems"),
|
||||
wallItems: io.of("/wallItems"),
|
||||
line: io.of("/line"),
|
||||
zone: io.of("/zone"),
|
||||
Builder: io.of('/Builder'),
|
||||
visualization: io.of('/visualization'),
|
||||
// widget:io.of('/widget')
|
||||
};
|
||||
// 🔹 Function to handle connections in a namespace
|
||||
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 organization = socket.handshake.auth.organization as string;
|
||||
console.log(`🔍 Received organization: ${organization}`);
|
||||
|
||||
if (organization) {
|
||||
socket.join(organization);
|
||||
// console.log(`🔹 Socket ${socket.id} joined room: ${organization}`);
|
||||
|
||||
// Debug: Check rooms
|
||||
// console.log(`🛠️ Current rooms for ${socket.id}:`, socket.rooms);
|
||||
} else {
|
||||
console.warn(`⚠️ Warning: Socket ${socket.id} did not provide an organization`);
|
||||
}
|
||||
|
||||
socket.onAny((event: string, data: any) => {
|
||||
// console.log(`📩 Event received: ${event}, Data: ${JSON.stringify(data)}`);
|
||||
eventHandlers.forEach(handler => handler(event, socket, data, namespace));
|
||||
// eventHandler(event, socket, data, namespace); // Pass `namespace` instead of `io`
|
||||
});
|
||||
|
||||
socket.on("disconnect", (reason: string) => {
|
||||
console.log(`❌ Client disconnected from ${namespaceName}: ${socket.id}, Reason: ${reason}`);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 🔹 Apply namespace handlers
|
||||
// handleNamespace("camera", namespaces.camera, cameraHandleEvent);
|
||||
// handleNamespace("environment", namespaces.environment, EnvironmentHandleEvent);
|
||||
// handleNamespace("floorItems", namespaces.floorItems, floorItemsHandleEvent);
|
||||
// handleNamespace("wallItems", namespaces.wallItems, wallItemsHandleEvent);
|
||||
handleNamespace("line", namespaces.line, lineHandleEvent);
|
||||
handleNamespace("zone", namespaces.zone, zoneHandleEvent);
|
||||
// handleNamespace("visualization", namespaces.panel, panelHandleEvent);
|
||||
// handleNamespace("widget", namespaces.visualization, widgetHandleEvent);
|
||||
// handleNamespace("Builder", namespaces.Builder, modelAssetHandleEvent,cameraHandleEvent,EnvironmentHandleEvent,wallItemsHandleEvent,lineHandleEvent);
|
||||
// handleNamespace("visualization", namespaces.visualization, panelHandleEvent, widgetHandleEvent,floatHandleEvent,templateHandleEvent);
|
||||
|
||||
|
||||
return io;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user