tessting branch-1
This commit is contained in:
102
src/socket-server/services/assets/asset-Controller.ts
Normal file
102
src/socket-server/services/assets/asset-Controller.ts
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
||||||
|
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||||
|
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||||
|
|
||||||
|
export const setAssetModel = async (data: any) => {
|
||||||
|
const {modeluuid, modelname,assetPosition, eventData,modelfileID,assetRotation,isLocked,isVisible,organization, }= data
|
||||||
|
console.log('data: ', data);
|
||||||
|
// const points=eventData.points
|
||||||
|
// const speed=eventData.speed
|
||||||
|
try {
|
||||||
|
const findvalue = await assetModel(organization).findOne({
|
||||||
|
modeluuid: modeluuid,
|
||||||
|
modelname: modelname,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (findvalue) {
|
||||||
|
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||||
|
{ modeluuid: modeluuid, modelname: modelname },
|
||||||
|
{
|
||||||
|
assetPosition: assetPosition,
|
||||||
|
assetRotation: assetRotation,
|
||||||
|
isVisible: isVisible,
|
||||||
|
isLocked: isLocked,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
return { success: true, message: 'Model updated', data: updatevalue, organization: organization }
|
||||||
|
} else {
|
||||||
|
let assetData: any = {
|
||||||
|
modeluuid,
|
||||||
|
modelname,
|
||||||
|
assetPosition,
|
||||||
|
modelfileID,
|
||||||
|
assetRotation,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
};
|
||||||
|
if (eventData) {
|
||||||
|
let pointRefs: any[] = [];
|
||||||
|
|
||||||
|
if (Array.isArray(eventData.points)) {
|
||||||
|
for (const point of eventData.points) {
|
||||||
|
let actionRefs: any[] = [];
|
||||||
|
let triggerRefs: any[] = [];
|
||||||
|
|
||||||
|
if (Array.isArray(point.actions)) {
|
||||||
|
for (const action of point.actions) {
|
||||||
|
const actionDoc = await actionModel(organization).create({
|
||||||
|
pointsUUID: point.uuid,
|
||||||
|
isArchive: false,
|
||||||
|
uuid: action.uuid,
|
||||||
|
name: action.name,
|
||||||
|
type: action.type,
|
||||||
|
material: action.material,
|
||||||
|
delay: action.delay,
|
||||||
|
spawn_Interval: action.spawn_Interval,
|
||||||
|
});
|
||||||
|
await actionDoc.save();
|
||||||
|
actionRefs.push(actionDoc._id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(point.triggers)) {
|
||||||
|
for (const trigger of point.triggers) {
|
||||||
|
const triggerDoc = await triggerModel(organization).create({
|
||||||
|
pointsUUID: point.uuid,
|
||||||
|
isArchive: false,
|
||||||
|
uuid: trigger.uuid,
|
||||||
|
name: trigger.name,
|
||||||
|
type: trigger.type,
|
||||||
|
bufferTime: trigger.bufferTime,
|
||||||
|
});
|
||||||
|
await triggerDoc.save();
|
||||||
|
triggerRefs.push(triggerDoc._id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pointRefs.push({
|
||||||
|
uuid: point.uuid,
|
||||||
|
position: point.position || [],
|
||||||
|
rotation: point.rotation || [],
|
||||||
|
actions: actionRefs,
|
||||||
|
triggers: triggerRefs,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assetData.speed = eventData.speed;
|
||||||
|
assetData.type = eventData.type;
|
||||||
|
assetData.points = pointRefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
const assetDoc = await assetModel(organization).create(assetData);
|
||||||
|
await assetDoc.save();
|
||||||
|
// await assetDoc.save();
|
||||||
|
return { success: true, message:"Model stored successfully", data: assetDoc, organization: organization }
|
||||||
|
}
|
||||||
|
} catch (error:any) {
|
||||||
|
console.error("Error creating flooritems:", error);
|
||||||
|
return { success: false, message: error?.message || "Error occurred while ModelAsset", error, organization: organization }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,10 @@ import { Socket } from "socket.io";
|
|||||||
import cameraModel from "../../../shared/model/camera/camera-Model";
|
import cameraModel from "../../../shared/model/camera/camera-Model";
|
||||||
|
|
||||||
export const createCamera = async (data: any,) => {
|
export const createCamera = async (data: any,) => {
|
||||||
|
const { userId, position, target, organization,rotation } = data
|
||||||
|
console.log('data: ', data);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const { userId, position, target, organization,rotation } = data
|
|
||||||
|
|
||||||
const findCamera = await cameraModel(organization).findOne({ userId: userId })
|
const findCamera = await cameraModel(organization).findOne({ userId: userId })
|
||||||
if (findCamera) {
|
if (findCamera) {
|
||||||
@@ -18,14 +19,14 @@ export const createCamera = async (data: any,) => {
|
|||||||
else {
|
else {
|
||||||
const newCamera = await cameraModel(organization).create({ userId, position, target,rotation })
|
const newCamera = await cameraModel(organization).create({ userId, position, target,rotation })
|
||||||
|
|
||||||
return { success: false, message: 'Camera created' ,data:newCamera,organization:organization}
|
return { success: true, message: 'Camera created' ,data:newCamera,organization:organization}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send response with the created document
|
// Send response with the created document
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating camera:', error);
|
console.error('Error creating camera:', error);
|
||||||
return { success: false, message: 'Error creating or updating camera', error, }
|
return { success: false, message: 'Error creating or updating camera', error, organization:organization}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import environmentModel from "../../../shared/model/environments/environments-Mo
|
|||||||
|
|
||||||
|
|
||||||
export const setEnvironment = async (data: any,) => {
|
export const setEnvironment = async (data: any,) => {
|
||||||
|
const { userId,roofVisibility,wallVisibility,shadowVisibility, organization } = data
|
||||||
try {
|
try {
|
||||||
const { userId,roofVisibility,wallVisibility,shadowVisibility, organization } = data
|
|
||||||
|
|
||||||
const findvalue = await environmentModel(organization).findOne({ userId: userId })
|
const findvalue = await environmentModel(organization).findOne({ userId: userId })
|
||||||
if (findvalue) {
|
if (findvalue) {
|
||||||
@@ -27,7 +27,7 @@ export const setEnvironment = async (data: any,) => {
|
|||||||
// Send response with the created document
|
// Send response with the created document
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating evironments:', error);
|
console.error('Error creating evironments:', error);
|
||||||
return { success: false, message: 'Error creating or updating evironments', error }
|
return { success: false, message: 'Error creating or updating evironments', error ,organization:organization}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,21 @@ import lineModel from "../../../shared/model/lines/lines-Model";
|
|||||||
|
|
||||||
|
|
||||||
export const createLineItems = async (data: any)=>{
|
export const createLineItems = async (data: any)=>{
|
||||||
|
const {organization,layer,line,type}=data
|
||||||
try {
|
try {
|
||||||
const {organization,layer,line,type}=data
|
|
||||||
const newLine = await lineModel(organization).create({ layer,line,type });
|
const newLine = await lineModel(organization).create({ layer,line,type });
|
||||||
return { success: true, message: 'line create', data: newLine,organization:organization }
|
return { success: true, message: 'line create', data: newLine,organization:organization }
|
||||||
|
|
||||||
// Send response with the created document
|
// Send response with the created document
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
return { success: false, message: 'Error create line', error }
|
return { success: false, message: 'Error create line', error,organization:organization }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const updateLineItems = async (data: any)=>{
|
export const updateLineItems = async (data: any)=>{
|
||||||
|
const {organization,uuid,position,}=data
|
||||||
try {
|
try {
|
||||||
const {organization,uuid,position,}=data
|
|
||||||
// const findLine = await lineModel(organization).find({ 'line.uuid': uuid });
|
// const findLine = await lineModel(organization).find({ 'line.uuid': uuid });
|
||||||
// Update the position of the line matching the uuid
|
// Update the position of the line matching the uuid
|
||||||
const updateResult = await lineModel(organization).updateMany(
|
const updateResult = await lineModel(organization).updateMany(
|
||||||
@@ -29,13 +29,13 @@ export const updateLineItems = async (data: any)=>{
|
|||||||
// Send response with the created document
|
// Send response with the created document
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating Lines:', error);
|
console.error('Error creating Lines:', error);
|
||||||
return { success: false, message: 'Error updating line', error }
|
return { success: false, message: 'Error updating line', error,organization:organization }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteLineItems = async (data: any)=>{
|
export const deleteLineItems = async (data: any)=>{
|
||||||
|
const {organization,line}=data
|
||||||
try {
|
try {
|
||||||
const {organization,line}=data
|
|
||||||
|
|
||||||
const inputUuids = line.map((item: any) => item.uuid);
|
const inputUuids = line.map((item: any) => item.uuid);
|
||||||
|
|
||||||
@@ -54,12 +54,12 @@ export const updateLineItems = async (data: any)=>{
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error delete Lines:', error);
|
console.error('Error delete Lines:', error);
|
||||||
return { success: false, message: 'Failed to delete line', error }
|
return { success: false, message: 'Failed to delete line', error ,organization:organization}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const deleteLayer = async (data: any)=>{
|
export const deleteLayer = async (data: any)=>{
|
||||||
|
const {organization,layer}=data
|
||||||
try {
|
try {
|
||||||
const {organization,layer}=data
|
|
||||||
|
|
||||||
const findValue = await lineModel(organization).find({ layer: layer });
|
const findValue = await lineModel(organization).find({ layer: layer });
|
||||||
|
|
||||||
@@ -77,12 +77,12 @@ export const updateLineItems = async (data: any)=>{
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error delete layer:', error);
|
console.error('Error delete layer:', error);
|
||||||
return { success: false, message: 'Failed to delete layer', error }
|
return { success: false, message: 'Failed to delete layer', error ,organization:organization}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const deleteLinPoiteItems = async (data: any)=>{
|
export const deleteLinPoiteItems = async (data: any)=>{
|
||||||
|
const {organization,uuid}=data
|
||||||
try {
|
try {
|
||||||
const {organization,uuid}=data
|
|
||||||
|
|
||||||
|
|
||||||
const findValue = await lineModel(organization).deleteMany({ 'line.uuid': uuid })
|
const findValue = await lineModel(organization).deleteMany({ 'line.uuid': uuid })
|
||||||
@@ -95,6 +95,6 @@ export const updateLineItems = async (data: any)=>{
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error delete Lines:', error);
|
console.error('Error delete Lines:', error);
|
||||||
return { success: false, message: 'Failed to delete point', error }
|
return { success: false, message: 'Failed to delete point', error ,organization:organization}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import cameraModel from "../../../shared/model/camera/camera-Model"
|
|||||||
import userModel from "../../../shared/model/user-Model"
|
import userModel from "../../../shared/model/user-Model"
|
||||||
|
|
||||||
export const activeUsers = async (data: any) => {
|
export const activeUsers = async (data: any) => {
|
||||||
|
const {organization}=data
|
||||||
try {
|
try {
|
||||||
if (data && data.email) {
|
if (data && data.email) {
|
||||||
|
|
||||||
@@ -48,17 +49,19 @@ export const activeUsers = async (data: any) => {
|
|||||||
|
|
||||||
|
|
||||||
// // return [];
|
// // return [];
|
||||||
} catch (error) {
|
} catch (error:any) {
|
||||||
|
return { success: false, message: error?.message || "Error occurred while activeUser", error, organization: organization }
|
||||||
|
|
||||||
return { success: false, message:error}
|
// return { success: false, message:error}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const activeUserOffline = async (data: any) => {
|
export const activeUserOffline = async (data: any) => {
|
||||||
try {
|
|
||||||
|
|
||||||
const email = data.email
|
|
||||||
const organization = email.split("@")[1].split(".")[0]
|
const email = data.email
|
||||||
|
const organization = email.split("@")[1].split(".")[0]
|
||||||
|
try {
|
||||||
|
|
||||||
const findUsers = await userModel(organization).findOne({email})
|
const findUsers = await userModel(organization).findOne({email})
|
||||||
// console.log('findUsers: ', findUsers);
|
// console.log('findUsers: ', findUsers);
|
||||||
@@ -90,8 +93,9 @@ export const activeUserOffline = async (data: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// // return [];
|
// // return [];
|
||||||
} catch (error) {
|
} catch (error:any) {
|
||||||
|
return { success: false, message: error?.message || "Error occurred while activeUser", error, organization: organization }
|
||||||
|
|
||||||
return { success: false, message: error}
|
// return { success: false, message: error}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import floatWidgetModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||||
|
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||||
|
|
||||||
|
export const addfloat = async (data: any) => {
|
||||||
|
const { organization, widget, 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 for the zoneId", organization: organization }
|
||||||
|
|
||||||
|
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existingFloatWidget) {
|
||||||
|
const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
// Data: {
|
||||||
|
// // measurements: widget.Data.measurements || {},
|
||||||
|
// duration: widget.Data.duration || "1h",
|
||||||
|
// },
|
||||||
|
position: widget.position,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
upsert: true,
|
||||||
|
new: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return { success: true, message: "Widget updated successfully", data: updateFloatWidget, organization: organization }
|
||||||
|
}
|
||||||
|
|
||||||
|
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||||
|
className: widget.className,
|
||||||
|
header: widget.header,
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
position: widget.position,
|
||||||
|
per: widget.per,
|
||||||
|
value: widget.value,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (newFloadWidget) {
|
||||||
|
return { success: true, message: "FloatWidget created successfully", data: newFloadWidget, organization: organization }
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
26
src/socket-server/services/visualization/templateServices.ts
Normal file
26
src/socket-server/services/visualization/templateServices.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import templateModel from "../../../shared/model/vizualization/templatemodel.ts";
|
||||||
|
export const addTemplate = async (data: any) => {
|
||||||
|
const { organization, templateID, name, panelOrder, widgets, snapshot } =data;
|
||||||
|
console.log('data: ', data);
|
||||||
|
try {
|
||||||
|
|
||||||
|
const existingTemplate = await templateModel(organization).findOne({
|
||||||
|
templateID: templateID,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existingTemplate)
|
||||||
|
return { success: false, message: "TemplateID alreay exists", organization: organization }
|
||||||
|
const newTemplate = await templateModel(organization).create({
|
||||||
|
templateID,
|
||||||
|
name,
|
||||||
|
panelOrder,
|
||||||
|
widgets,
|
||||||
|
snapshot,
|
||||||
|
});
|
||||||
|
if (newTemplate)
|
||||||
|
return { success: false, message: "Template saved successfully", data: newTemplate, organization: organization }
|
||||||
|
} catch (error: any) {
|
||||||
|
return { success: false, message: error?.message || "Error occurred while template", error, organization: organization }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -47,4 +47,30 @@ export const EVENTS = {
|
|||||||
zoneUpdateRespones:"zone:response:updates",
|
zoneUpdateRespones:"zone:response:updates",
|
||||||
deleteZone:"v2:zone:delete",
|
deleteZone:"v2:zone:delete",
|
||||||
ZoneDeleteRespones:"zone:response: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",
|
||||||
}
|
}
|
||||||
@@ -12,104 +12,130 @@ import { deleteZone, setZone } from '../services/lines/zone-controller';
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const cameraHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
const cameraHandleEvent = 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) {
|
switch (event) {
|
||||||
|
case EVENTS.setCamera: {
|
||||||
|
result = await createCamera(data);
|
||||||
|
|
||||||
case EVENTS.setCamera:
|
if (result) {
|
||||||
const result = await createCamera(data,);
|
const responseEvent = EVENTS.cameraUpdateResponse
|
||||||
// console.log('result: ', result);
|
const organization = result?.organization
|
||||||
if (result.success) {
|
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||||
// console.log('result.success: ', result.success);
|
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||||
// if (result.message === 'Camera updated') {
|
if (organization) {
|
||||||
// Emit update response
|
socket.emit(responseEvent, {
|
||||||
|
success: result.success,
|
||||||
io.emit(EVENTS.cameraUpdateResponse, {
|
|
||||||
success: true,
|
|
||||||
message: result.message,
|
|
||||||
data: result.data,
|
|
||||||
socketId: socket.id,
|
|
||||||
organization:result.organization
|
|
||||||
});
|
|
||||||
} else if (result.message === 'Camera created') {
|
|
||||||
// Emit create response
|
|
||||||
io.emit(EVENTS.cameraCreateResponse, {
|
|
||||||
success: true,
|
|
||||||
message: result.message,
|
|
||||||
data: result.data,
|
|
||||||
socketId: socket.id,
|
|
||||||
organization:result.organization
|
|
||||||
});
|
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
// Emit error response
|
|
||||||
socket.emit(EVENTS.cameraError, {
|
|
||||||
success: false,
|
|
||||||
message: result.message,
|
message: result.message,
|
||||||
error: result.error,
|
data: result.data,
|
||||||
socketId: socket.id,
|
error: result.error || null,
|
||||||
organization:result.organization
|
socketId: socket.id,
|
||||||
});
|
organization,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
break;
|
// case EVENTS.deleteWidget: {
|
||||||
// case EVENTS.updataControlle_iot:
|
// const result = await Widgetdelete(data)
|
||||||
// updateControlle(data);
|
// if (result) {
|
||||||
break;
|
// // console.log('result?.success: ', result.organization);
|
||||||
// case EVENTS.deleteControlle_iot:
|
// const responseEvent = EVENTS.widgetDeleteRespones
|
||||||
// deleteControlle(data);
|
// // console.log('responseEvent: ', responseEvent);
|
||||||
break;
|
// 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:
|
|
||||||
// console.error(`Unhandled event type: ${event}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const EnvironmentHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
const EnvironmentHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
||||||
|
if (!data?.organization) {
|
||||||
|
console.warn(`Missing organization for event: ${event}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
|
case EVENTS.setenvironment: {
|
||||||
|
result = await setEnvironment(data);
|
||||||
|
|
||||||
case EVENTS.setenvironment:
|
if (result) {
|
||||||
const result = await setEnvironment(data,);
|
const responseEvent = EVENTS.EnvironmentUpdateResponse
|
||||||
// console.log('result: ', result);
|
const organization = result?.organization
|
||||||
if (result.success) {
|
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||||
// if (result.message === 'Camera updated') {
|
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||||
// Emit update response
|
if (organization) {
|
||||||
|
socket.emit(responseEvent, {
|
||||||
io.emit(EVENTS.EnvironmentUpdateResponse, {
|
success: result.success,
|
||||||
success: true,
|
|
||||||
message: result.message,
|
|
||||||
data: result.data,
|
|
||||||
socketId: socket.id,
|
|
||||||
organization:result.organization
|
|
||||||
});
|
|
||||||
// } else if (result.message === 'evironments created') {
|
|
||||||
// // Emit create response
|
|
||||||
// io.emit(EVENTS.cameraCreateResponse, {
|
|
||||||
// success: true,
|
|
||||||
// message: result.message,
|
|
||||||
// data: result.data,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
// Emit error response
|
|
||||||
socket.emit(EVENTS.cameraError, {
|
|
||||||
success: false,
|
|
||||||
message: result.message,
|
message: result.message,
|
||||||
error: result.error,
|
data: result.data,
|
||||||
socketId: socket.id,
|
error: result.error || null,
|
||||||
organization:result.organization
|
socketId: socket.id,
|
||||||
});
|
organization,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
break;
|
// case EVENTS.deleteWidget: {
|
||||||
// case EVENTS.updataControlle_iot:
|
// const result = await Widgetdelete(data)
|
||||||
// updateControlle(data);
|
// if (result) {
|
||||||
break;
|
// // console.log('result?.success: ', result.organization);
|
||||||
// case EVENTS.deleteControlle_iot:
|
// const responseEvent = EVENTS.widgetDeleteRespones
|
||||||
// deleteControlle(data);
|
// // console.log('responseEvent: ', responseEvent);
|
||||||
break;
|
// 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:
|
default:
|
||||||
// console.error(`Unhandled event type: ${event}`);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
const floorItemsHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
const floorItemsHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
@@ -457,5 +483,62 @@ 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;
|
return io;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user