assetmodel creation and adding for namespace socket
This commit is contained in:
@@ -33,8 +33,13 @@ export interface assetData extends Document {
|
|||||||
];
|
];
|
||||||
}[];
|
}[];
|
||||||
}[];
|
}[];
|
||||||
assetPosition: number[];
|
position: [];
|
||||||
assetRotation: number[];
|
// rotation: [];
|
||||||
|
rotation: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
};
|
||||||
speed: number | string;
|
speed: number | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,16 +71,16 @@ const assetDataSchema: Schema = new Schema({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
assetPosition: { type: [Number] },
|
position: { type: Array},
|
||||||
assetRotation: { type: [Number] },
|
// rotation: { type: Array},
|
||||||
|
rotation: {
|
||||||
|
x: { type: Number },
|
||||||
|
y: { type: Number },
|
||||||
|
z: { type: Number },
|
||||||
|
},
|
||||||
speed: { type: Schema.Types.Mixed },
|
speed: { type: Schema.Types.Mixed },
|
||||||
isLocked: { type: Boolean },
|
isLocked: { type: Boolean },
|
||||||
isVisible: { type: Boolean },
|
isVisible: { type: Boolean },
|
||||||
// rotation: {
|
|
||||||
// x: { type: Number },
|
|
||||||
// y: { type: Number },
|
|
||||||
// z: { type: Number },
|
|
||||||
// },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// export default floorItemsModel;
|
// export default floorItemsModel;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
|||||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||||
|
|
||||||
export const setAssetModel = async (data: any) => {
|
export const setAssetModel = async (data: any) => {
|
||||||
const {modeluuid, modelname,assetPosition, eventData,modelfileID,assetRotation,isLocked,isVisible,organization, }= data
|
const {modeluuid, modelname,position,rotation, eventData,modelfileID,isLocked,isVisible,organization, }= data
|
||||||
console.log('data: ', data);
|
console.log('data: ', data);
|
||||||
// const points=eventData.points
|
// const position=data.position
|
||||||
// const speed=eventData.speed
|
// const rotation=data.rotation
|
||||||
try {
|
try {
|
||||||
const findvalue = await assetModel(organization).findOne({
|
const findvalue = await assetModel(organization).findOne({
|
||||||
modeluuid: modeluuid,
|
modeluuid: modeluuid,
|
||||||
@@ -14,24 +14,26 @@ export const setAssetModel = async (data: any) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (findvalue) {
|
if (findvalue) {
|
||||||
|
console.log('findvalue: ', findvalue);
|
||||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||||
{ modeluuid: modeluuid, modelname: modelname },
|
{ modeluuid: modeluuid, modelname: modelname },
|
||||||
{
|
{
|
||||||
assetPosition: assetPosition,
|
position: position,
|
||||||
assetRotation: assetRotation,
|
rotation: rotation,
|
||||||
isVisible: isVisible,
|
isVisible: isVisible,
|
||||||
isLocked: isLocked,
|
isLocked: isLocked,
|
||||||
},
|
},
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
return { success: true, message: 'Model updated', data: updatevalue, organization: organization }
|
console.log('updatevalue: ', updatevalue);
|
||||||
|
return { success: true, message: 'Model updated successfully', data: updatevalue, organization: organization }
|
||||||
} else {
|
} else {
|
||||||
let assetData: any = {
|
let assetData: any = {
|
||||||
modeluuid,
|
modeluuid,
|
||||||
modelname,
|
modelname,
|
||||||
assetPosition,
|
position,
|
||||||
modelfileID,
|
modelfileID,
|
||||||
assetRotation,
|
rotation,
|
||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
};
|
};
|
||||||
@@ -93,10 +95,33 @@ export const setAssetModel = async (data: any) => {
|
|||||||
const assetDoc = await assetModel(organization).create(assetData);
|
const assetDoc = await assetModel(organization).create(assetData);
|
||||||
await assetDoc.save();
|
await assetDoc.save();
|
||||||
// await assetDoc.save();
|
// await assetDoc.save();
|
||||||
return { success: true, message:"Model stored successfully", data: assetDoc, organization: organization }
|
// if(assetDoc.)
|
||||||
|
const assetDatas={
|
||||||
|
modeluuid:assetDoc.modeluuid,modelname:assetDoc.modelname,modelfileID:assetDoc.modelfileID,position:assetDoc.position,rotation:assetDoc.rotation,isLocked:assetDoc.isLocked,isVisible:assetDoc.isVisible
|
||||||
|
,eventData:{points:assetDoc.points,type:assetDoc.type,speed:assetDoc.speed}
|
||||||
|
}
|
||||||
|
return { success: true, message:"Model created successfully", data: assetDatas, organization: organization }
|
||||||
}
|
}
|
||||||
} catch (error:any) {
|
} catch (error:any) {
|
||||||
console.error("Error creating flooritems:", error);
|
// console.error("Error creating flooritems:", error);
|
||||||
return { success: false, message: error?.message || "Error occurred while ModelAsset", error, organization: organization }
|
return { success: false, message: error?.message || "Error occurred while ModelAsset", error, organization: organization }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export const deleteAssetModel = async (data: any)=>{
|
||||||
|
const { modeluuid,modelname,organization } = data;
|
||||||
|
try {
|
||||||
|
|
||||||
|
const findValue = await assetModel(organization).findOneAndDelete({modeluuid:modeluuid,modelname:modelname})
|
||||||
|
if (!findValue) {
|
||||||
|
return { success: false, message: 'model not found',organization:organization }
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return { success: true, message: 'Model deleted successfully', data: findValue,organization:organization }
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// console.error('Error get flooritems:', error);
|
||||||
|
return { success: false, message: 'Failed to delete asset', error,organization:organization }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import cameraModel from "../../../shared/model/camera/camera-Model.ts";
|
|||||||
|
|
||||||
export const createCamera = async (data: any,) => {
|
export const createCamera = async (data: any,) => {
|
||||||
const { userId, position, target, organization,rotation } = data
|
const { userId, position, target, organization,rotation } = data
|
||||||
console.log('data: ', data);
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import zoneModel from "../../../shared/model/lines/zone-Model.ts";
|
import zoneModel from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||||
|
|
||||||
export const setZone = async (data: any) => {
|
export const setZone = async (data: any) => {
|
||||||
try {
|
|
||||||
const { organization, userId, zoneData } = data
|
const { organization, userId, zoneData } = data
|
||||||
console.log('data: ', data);
|
try {
|
||||||
const zoneId = zoneData.zoneId
|
const zoneId = zoneData.zoneId
|
||||||
const points = zoneData.points
|
const points = zoneData.points
|
||||||
const zoneName = zoneData.zoneName
|
const zoneName = zoneData.zoneName
|
||||||
@@ -18,7 +16,7 @@ export const setZone = async (data: any) => {
|
|||||||
return { success: true, message: 'zone updated', data: updateZone, organization: organization }
|
return { success: true, message: 'zone updated', data: updateZone, organization: organization }
|
||||||
} else {
|
} else {
|
||||||
const zoneCreate = await zoneModel(organization).create({
|
const zoneCreate = await zoneModel(organization).create({
|
||||||
zoneId, createBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
|
zoneId, createdBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
|
||||||
})
|
})
|
||||||
const createdZone = await zoneModel(organization)
|
const createdZone = await zoneModel(organization)
|
||||||
.findById(zoneCreate._id)
|
.findById(zoneCreate._id)
|
||||||
@@ -28,18 +26,18 @@ export const setZone = async (data: any) => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error: ', error);
|
console.log('error: ', error);
|
||||||
return { success: false, message: 'Zone not found', error }
|
return { success: false, message: 'Zone not found', error , organization: organization}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteZone = async (data: any) => {
|
export const deleteZone = async (data: any) => {
|
||||||
try {
|
|
||||||
const { organization, userId, zoneId } = data
|
const { organization, userId, zoneId } = data
|
||||||
|
try {
|
||||||
|
|
||||||
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
||||||
if (findZoneId) {
|
if (findZoneId) {
|
||||||
const deleteZone = await zoneModel(organization).findOneAndDelete(
|
const deleteZone = await zoneModel(organization).findOneAndDelete(
|
||||||
{ zoneId: zoneId, createBy: userId }
|
{ zoneId: zoneId, createdBy: userId }
|
||||||
).select("-_id -__v")
|
).select("-_id -__v")
|
||||||
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
|
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
|
||||||
} else {
|
} else {
|
||||||
@@ -48,6 +46,6 @@ export const deleteZone = async (data: any) => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error: ', error);
|
console.log('error: ', error);
|
||||||
return { success: false, message: 'Zone not found', error }
|
return { success: false, message: 'Zone not found', error, organization: organization }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ import userModel from "../../../shared/model/user-Model.ts"
|
|||||||
|
|
||||||
export const activeUsers = async (data: any) => {
|
export const activeUsers = async (data: any) => {
|
||||||
const {organization}=data
|
const {organization}=data
|
||||||
|
// console.log('data: ', data);
|
||||||
try {
|
try {
|
||||||
if (data && data.email) {
|
if (data && data.email) {
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ export const activeUsers = async (data: any) => {
|
|||||||
// Handle the error or return a default value
|
// Handle the error or return a default value
|
||||||
// Example: Return an error response if the email is invalid
|
// Example: Return an error response if the email is invalid
|
||||||
|
|
||||||
return { success: false, message: 'Email is missing or invalid', }
|
return { success: false, message: 'Email is missing or invalid', organization:organization }
|
||||||
// return res.status(400).send({ message: 'Email is missing or invalid' });
|
// return res.status(400).send({ message: 'Email is missing or invalid' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,3 +100,38 @@ export const activeUserOffline = async (data: any) => {
|
|||||||
// return { success: false, message: error}
|
// return { success: false, message: error}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
type OnlineUsersMap = Map<string, Set<string>>;
|
||||||
|
|
||||||
|
// export const addUserToOnlineList = async (
|
||||||
|
// organization: string,
|
||||||
|
// email: string,
|
||||||
|
// onlineUsers: OnlineUsersMap,
|
||||||
|
// socket: any,
|
||||||
|
// namespace: string
|
||||||
|
// ) => {
|
||||||
|
// if (!organization || !email) return;
|
||||||
|
// console.log('organization: ', organization);
|
||||||
|
|
||||||
|
// // Ensure the organization entry exists
|
||||||
|
// if (!onlineUsers.has(organization)) {
|
||||||
|
// onlineUsers.set(organization, new Set());
|
||||||
|
// }
|
||||||
|
// const findUser = await userModel(organization).findOne({email})
|
||||||
|
// if (!findUser) {
|
||||||
|
// return { success: false, message: "User not found", organization };
|
||||||
|
// }
|
||||||
|
// const userId = findUser._id;
|
||||||
|
// console.log(`🔍 Found user with ID: ${userId}`);
|
||||||
|
// // Add user to the online set
|
||||||
|
// onlineUsers.get(organization)!.add(userId);
|
||||||
|
|
||||||
|
// console.log(`✅ User ${userId} is online (Org: ${organization})`);
|
||||||
|
|
||||||
|
// // Emit updated online users list
|
||||||
|
// socket.emit("users:online", {
|
||||||
|
// organization,
|
||||||
|
// users: [...onlineUsers.get(organization)!],
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@ export const EVENTS = {
|
|||||||
connection: "connection",
|
connection: "connection",
|
||||||
disconnect:"disconnect",
|
disconnect:"disconnect",
|
||||||
//userActiveStatus
|
//userActiveStatus
|
||||||
userConnect:"userConnectRespones",
|
userConnect:"userConnectResponse",
|
||||||
userDisConnect:"userDisConnectRespones",
|
userDisConnect:"userDisConnectResponse",
|
||||||
// Room management events
|
// Room management events
|
||||||
joinRoom: 'joinRoom',
|
joinRoom: 'joinRoom',
|
||||||
createroom: "createRoom", // When a client joins a room
|
createroom: "createRoom", // When a client joins a room
|
||||||
@@ -73,4 +73,8 @@ export const EVENTS = {
|
|||||||
//model-asset
|
//model-asset
|
||||||
setAssetModel: "v2:model-asset:add",
|
setAssetModel: "v2:model-asset:add",
|
||||||
assetUpdateRespones: "model-asset:response:updates",
|
assetUpdateRespones: "model-asset:response:updates",
|
||||||
|
deleteAssetModel:"v2:model-asset:delete",
|
||||||
|
assetDeleteRespones: "model-asset:response:updates",
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,13 @@ import { setEnvironment } from '../services/environments/environments-controller
|
|||||||
import { deleteFloorItems, setFloorItems } from '../services/assets/flooritem-Controller.ts';
|
import { deleteFloorItems, setFloorItems } from '../services/assets/flooritem-Controller.ts';
|
||||||
import { deleteWallItems, setWallItems } from '../services/assets/wallitem-Controller.ts';
|
import { deleteWallItems, setWallItems } from '../services/assets/wallitem-Controller.ts';
|
||||||
import { deleteLineItems, deleteLinPoiteItems, updateLineItems, createLineItems, deleteLayer } from '../services/lines/line-Controller.ts';
|
import { deleteLineItems, deleteLinPoiteItems, updateLineItems, createLineItems, deleteLayer } from '../services/lines/line-Controller.ts';
|
||||||
import { activeUserOffline, activeUsers } from '../services/users/user-controller.ts';
|
import { activeUserOffline, activeUsers, } from '../services/users/user-controller.ts';
|
||||||
import { deleteZone, setZone } from '../services/lines/zone-controller.ts';
|
import { deleteZone, setZone } from '../services/lines/zone-controller.ts';
|
||||||
import { addPanel, panelDelete } from '../services/visualization/panel-Services.ts';
|
import { addPanel, panelDelete } from '../services/visualization/panel-Services.ts';
|
||||||
import { addWidget, Widgetdelete } from '../services/visualization/widget-Services.ts';
|
import { addWidget, Widgetdelete } from '../services/visualization/widget-Services.ts';
|
||||||
|
import { addfloat } from '../services/visualization/floatWidgetService.ts';
|
||||||
|
import { addTemplate } from '../services/visualization/templateServices.ts';
|
||||||
|
import { deleteAssetModel, setAssetModel } from '../services/assets/asset-Controller.ts';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -31,7 +33,7 @@ const cameraHandleEvent = async (event: string, socket: Socket, data: any, names
|
|||||||
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||||
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||||
if (organization) {
|
if (organization) {
|
||||||
socket.emit(responseEvent, {
|
socket.to(organization).emit(responseEvent, {
|
||||||
success: result.success,
|
success: result.success,
|
||||||
message: result.message,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
@@ -165,7 +167,8 @@ const floorItemsHandleEvent =async (event: string, socket: Socket, data: any,io:
|
|||||||
organization: result.organization
|
organization: result.organization
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;}
|
break;
|
||||||
|
}
|
||||||
case EVENTS.deleteFloorItems: {
|
case EVENTS.deleteFloorItems: {
|
||||||
const result = await deleteFloorItems(data);
|
const result = await deleteFloorItems(data);
|
||||||
// console.log('result: ', result);
|
// console.log('result: ', result);
|
||||||
@@ -191,265 +194,317 @@ const floorItemsHandleEvent =async (event: string, socket: Socket, data: any,io:
|
|||||||
organization: result.organization
|
organization: result.organization
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// console.error(`Unhandled event type: ${event}`);
|
// 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) => {
|
||||||
switch (event) {
|
if (!data?.organization) {
|
||||||
|
console.warn(`Missing organization for event: ${event}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result;
|
||||||
|
switch (event) {
|
||||||
case EVENTS.setWallItems: {
|
case EVENTS.setWallItems: {
|
||||||
const result = await setWallItems(data);
|
result = await setWallItems(data);
|
||||||
// console.log('result: ', result);
|
|
||||||
if (result.success) {
|
if (result) {
|
||||||
io.emit(EVENTS.wallItemsUpdateResponse, {
|
const responseEvent = EVENTS.wallItemsUpdateResponse
|
||||||
success: true,
|
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,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization:result.organization
|
organization,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Emit error response
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
socket.emit(EVENTS.wallItemError, {
|
|
||||||
success: false,
|
|
||||||
message: result.message,
|
|
||||||
error: result.error,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
case EVENTS.deleteWallItems: {
|
case EVENTS.deleteWallItems: {
|
||||||
const result = await deleteWallItems(data);
|
const result = await deleteWallItems(data)
|
||||||
// console.log('result: ', result);
|
if (result) {
|
||||||
if (result.success) {
|
// console.log('result?.success: ', result.organization);
|
||||||
|
const responseEvent = EVENTS.wallItemsDeleteResponse
|
||||||
|
// console.log('responseEvent: ', responseEvent);
|
||||||
io.emit(EVENTS.wallItemsDeleteResponse, {
|
const organization = result?.organization
|
||||||
success: true || false,
|
// 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,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization:result.organization
|
organization,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Emit error response
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
socket.emit(EVENTS.wallItemError, {
|
|
||||||
success: false,
|
|
||||||
message: result.message,
|
|
||||||
error: result.error,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// console.error(`Unhandled event type: ${event}`);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVENTS.createLine: {
|
case EVENTS.createLine: {
|
||||||
const result = await createLineItems(data);
|
result = await createLineItems(data);
|
||||||
// console.log('result: ', result);
|
|
||||||
if (result.success) {
|
|
||||||
|
|
||||||
|
if (result) {
|
||||||
io.emit(EVENTS.createLineResponse, {
|
const responseEvent = EVENTS.createLineResponse
|
||||||
success: true || false,
|
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,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization:result.organization
|
organization,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Emit error response
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
// socket.emit(EVENTS.wallItemError, {
|
|
||||||
// success: false,
|
|
||||||
// message: result.message,
|
|
||||||
// error: result.error,
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
case EVENTS.updateLine: {
|
case EVENTS.updateLine: {
|
||||||
const result = await updateLineItems(data);
|
const result = await updateLineItems(data)
|
||||||
// console.log('result: ', result);
|
if (result) {
|
||||||
if (result.success) {
|
// console.log('result?.success: ', result.organization);
|
||||||
|
const responseEvent = EVENTS.updateLineResponse
|
||||||
|
// console.log('responseEvent: ', responseEvent);
|
||||||
io.emit(EVENTS.updateLineResponse, {
|
const organization = result?.organization
|
||||||
success: true || false,
|
// 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,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization: result.organization
|
organization,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
case EVENTS.deleteLine: {
|
case EVENTS.deleteLine: {
|
||||||
const result = await deleteLineItems(data);
|
const result = await deleteLineItems(data)
|
||||||
// console.log('result: ', result);
|
if (result) {
|
||||||
if (result.success) {
|
// console.log('result?.success: ', result.organization);
|
||||||
|
const responseEvent = EVENTS.deleteLineResponse
|
||||||
|
// console.log('responseEvent: ', responseEvent);
|
||||||
io.emit(EVENTS.deleteLineResponse, {
|
const organization = result?.organization
|
||||||
success: true || false,
|
// 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,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization:result.organization
|
organization,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Emit error response
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
// socket.emit(EVENTS.wallItemError, {
|
|
||||||
// success: false,
|
|
||||||
// message: result.message,
|
|
||||||
// error: result.error,
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
case EVENTS.deletePoint: {
|
case EVENTS.deletePoint: {
|
||||||
const result = await deleteLinPoiteItems(data);
|
const result = await deleteLinPoiteItems(data)
|
||||||
// console.log('result: ', result);
|
if (result) {
|
||||||
if (result.success) {
|
// console.log('result?.success: ', result.organization);
|
||||||
|
const responseEvent = EVENTS.deletePointResponse
|
||||||
io.emit(EVENTS.deletePointResponse, {
|
// console.log('responseEvent: ', responseEvent);
|
||||||
success: true || false,
|
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,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization:result.organization
|
organization,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Emit error response
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
// socket.emit(EVENTS.wallItemError, {
|
|
||||||
// success: false,
|
|
||||||
// message: result.message,
|
|
||||||
// error: result.error,
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case EVENTS.deleteLineLayer:{
|
break
|
||||||
const result = await deleteLayer(data);
|
|
||||||
// console.log('result: ', result);
|
|
||||||
if (result.success) {
|
|
||||||
|
|
||||||
io.emit(EVENTS.deleteLineLayerResponse, {
|
|
||||||
success: true || false,
|
|
||||||
message: result.message,
|
|
||||||
data: result.data,
|
|
||||||
socketId: socket.id,
|
|
||||||
organization:result.organization
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Emit error response
|
|
||||||
// socket.emit(EVENTS.wallItemError, {
|
|
||||||
// success: false,
|
|
||||||
// message: result.message,
|
|
||||||
// error: result.error,
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// console.error(`Unhandled event type: ${event}`);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVENTS.connection: {
|
case EVENTS.connection: {
|
||||||
// console.log('EVENTS.connection: ', EVENTS.connection);
|
result = await activeUsers(data);
|
||||||
// console.log('event: ', event);
|
// console.log('result: ', result);
|
||||||
const result = await activeUsers(data);
|
|
||||||
if (result?.success) {
|
|
||||||
// console.log('result.success: ', result.success)
|
|
||||||
|
|
||||||
io.emit(EVENTS.userConnect, {
|
if (result) {
|
||||||
success: true || false,
|
const responseEvent = EVENTS.userConnect
|
||||||
|
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,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization:result.organization
|
organization,
|
||||||
|
});
|
||||||
});}
|
} else {
|
||||||
break;
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
case EVENTS.disconnect: {
|
case EVENTS.disconnect: {
|
||||||
// console.log('EVENTS.disconnect: ', EVENTS.connection);
|
const result = await activeUserOffline(data)
|
||||||
// console.log('event: ', event);
|
if (result) {
|
||||||
const result = await activeUserOffline(data);
|
// console.log('result?.success: ', result.organization);
|
||||||
if (result?.success) {
|
const responseEvent = EVENTS.userDisConnect
|
||||||
// console.log('result.success: ', result.success)
|
// console.log('responseEvent: ', responseEvent);
|
||||||
|
const organization = result?.organization
|
||||||
io.emit(EVENTS.userDisConnect, {
|
// console.log('organization: ', organization);
|
||||||
success: true || false,
|
// 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,
|
message: result.message,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
error: result.error || "disconnectError",
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization:result.organization
|
organization,
|
||||||
|
|
||||||
});}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const zoneHandleEvent =async (event: string, socket: Socket, data: any,io:any)=>{
|
|
||||||
switch (event) {
|
|
||||||
case EVENTS.setZone:{
|
|
||||||
const result=await setZone(data)
|
|
||||||
if (result?.success) {
|
|
||||||
io.emit(EVENTS.zoneUpdateRespones, {
|
|
||||||
success: true || false,
|
|
||||||
message: result.message,
|
|
||||||
data: result.data,
|
|
||||||
error: result.error,
|
|
||||||
socketId: socket.id,
|
|
||||||
organization:result.organization
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
}
|
}
|
||||||
break}
|
|
||||||
case EVENTS.deleteZone:{
|
|
||||||
const result=await deleteZone(data)
|
|
||||||
if (result?.success) {
|
|
||||||
io.emit(EVENTS.ZoneDeleteRespones, {
|
|
||||||
success: true || false,
|
|
||||||
message: result.message,
|
|
||||||
data: result.data,
|
|
||||||
error: result.error,
|
|
||||||
socketId: socket.id,
|
|
||||||
organization:result.organization
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break}
|
break
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
const zoneHandleEvent = async (event: string, socket: Socket, data: any, io: any) => {
|
||||||
|
if (!data?.organization) {
|
||||||
|
console.warn(`Missing organization for event: ${event}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result;
|
||||||
|
switch (event) {
|
||||||
|
case EVENTS.setZone: {
|
||||||
|
result = await setZone(data);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const responseEvent = EVENTS.zoneUpdateRespones
|
||||||
|
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.deleteZone: {
|
||||||
|
const result = await deleteZone(data)
|
||||||
|
if (result) {
|
||||||
|
// console.log('result?.success: ', result.organization);
|
||||||
|
const responseEvent = EVENTS.ZoneDeleteRespones
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
const panelHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
const panelHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
||||||
if (!data?.organization) {
|
if (!data?.organization) {
|
||||||
@@ -461,14 +516,9 @@ const panelHandleEvent=async(event: string, socket: Socket, data: any,namespace:
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
case EVENTS.addPanel: {
|
case EVENTS.addPanel: {
|
||||||
result = await addPanel(data);
|
result = await addPanel(data);
|
||||||
console.log('result: ', result);
|
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log('result?.success: ', result.organization);
|
|
||||||
const responseEvent = EVENTS.panelUpdateRespones
|
const responseEvent = EVENTS.panelUpdateRespones
|
||||||
console.log('responseEvent: ', responseEvent);
|
|
||||||
const organization = result?.organization
|
const organization = result?.organization
|
||||||
console.log('organization: ', organization);
|
|
||||||
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||||
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||||
// console.log('emitTarget: ', emitTarget);
|
// console.log('emitTarget: ', emitTarget);
|
||||||
@@ -482,7 +532,8 @@ const panelHandleEvent=async(event: string, socket: Socket, data: any,namespace:
|
|||||||
organization: result.organization,
|
organization: result.organization,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;}
|
break;
|
||||||
|
}
|
||||||
case EVENTS.deletePanel: {
|
case EVENTS.deletePanel: {
|
||||||
const result = await panelDelete(data)
|
const result = await panelDelete(data)
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -586,7 +637,203 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
const floatHandleEvent = 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.addFloat: {
|
||||||
|
result = await addfloat(data);
|
||||||
|
// console.log('result: ', result);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
// console.log('result?.success: ', result.organization);
|
||||||
|
const responseEvent = EVENTS.floatUpdateRespones
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
// // 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
const modelAssetHandleEvent = 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.setAssetModel: {
|
||||||
|
result = await setAssetModel(data);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const responseEvent = EVENTS.assetUpdateRespones
|
||||||
|
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.deleteAssetModel: {
|
||||||
|
const result = await deleteAssetModel(data)
|
||||||
|
if (result) {
|
||||||
|
// console.log('result?.success: ', result.organization);
|
||||||
|
const responseEvent = EVENTS.assetDeleteRespones
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export const initSocketServer = (httpServer: any) => {
|
export const initSocketServer = (httpServer: any) => {
|
||||||
const io = new Server(httpServer, {
|
const io = new Server(httpServer, {
|
||||||
@@ -621,6 +868,105 @@ userStatus(EVENTS.connection, socket, socket.handshake.auth,io);
|
|||||||
// Perform cleanup or other necessary actions
|
// Perform cleanup or other necessary actions
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// 🔹 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}`);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
const onlineUsers = new Map<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 {organization,email} = socket.handshake.auth
|
||||||
|
console.log(`🔍 Received organization: ${organization}`);
|
||||||
|
|
||||||
|
if (organization) {
|
||||||
|
socket.join(organization);
|
||||||
|
// console.log(`🔹 Socket ${socket.id} joined room: ${organization}`);
|
||||||
|
} else {
|
||||||
|
// console.warn(`⚠️ Warning: Socket ${socket.id} did not provide an organization`);
|
||||||
|
}
|
||||||
|
// addUserToOnlineList(organization, socket.id, onlineUsers, socket, namespaceName);
|
||||||
|
// Handle all events
|
||||||
|
userStatus(EVENTS.connection, socket, socket.handshake.auth, socket);
|
||||||
|
|
||||||
|
socket.onAny((event: string, data: any) => {
|
||||||
|
eventHandlers.forEach(handler => handler(event, socket, data, namespace,io));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle disconnection
|
||||||
|
socket.on("disconnect", (reason: string) => {
|
||||||
|
userStatus(EVENTS.disconnect, socket, socket.handshake.auth, socket);
|
||||||
|
|
||||||
|
// 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})`);
|
||||||
|
if (organization) {
|
||||||
|
socket.join(organization);
|
||||||
|
// console.log(`♻️ Rejoined room: ${organization}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 🔹 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, userStatus,modelAssetHandleEvent, cameraHandleEvent, EnvironmentHandleEvent, wallItemsHandleEvent, lineHandleEvent,zoneHandleEvent);
|
||||||
|
handleNamespace("visualization", namespaces.visualization, panelHandleEvent, widgetHandleEvent, floatHandleEvent, templateHandleEvent);
|
||||||
|
|
||||||
return io;
|
return io;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user