2025-01-30 12:44:04 +05:30
|
|
|
import { Server, Socket } from 'socket.io';
|
2025-03-28 12:45:59 +05:30
|
|
|
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';
|
2025-03-29 17:47:16 +05:30
|
|
|
import { addPanel, panelDelete } from '../services/visualization/panel-Services.ts';
|
|
|
|
|
import { addWidget, Widgetdelete } from '../services/visualization/widget-Services.ts';
|
2025-01-30 12:44:04 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-31 19:49:07 +05:30
|
|
|
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;
|
|
|
|
|
}
|
2025-01-30 12:44:04 +05:30
|
|
|
|
2025-03-31 19:49:07 +05:30
|
|
|
let result;
|
|
|
|
|
switch (event) {
|
|
|
|
|
case EVENTS.setCamera: {
|
|
|
|
|
result = await createCamera(data);
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
const responseEvent = EVENTS.cameraUpdateResponse
|
|
|
|
|
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.emit(responseEvent, {
|
|
|
|
|
success: result.success,
|
2025-01-30 12:44:04 +05:30
|
|
|
message: result.message,
|
2025-03-31 19:49:07 +05:30
|
|
|
data: result.data,
|
|
|
|
|
error: result.error || null,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.warn(`Organization missing in response for event: ${event}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break
|
2025-01-30 12:44:04 +05:30
|
|
|
}
|
2025-03-31 19:49:07 +05:30
|
|
|
// 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
|
|
|
|
|
// }
|
2025-01-30 12:44:04 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const EnvironmentHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
2025-03-31 19:49:07 +05:30
|
|
|
if (!data?.organization) {
|
|
|
|
|
console.warn(`Missing organization for event: ${event}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-01-30 12:44:04 +05:30
|
|
|
|
2025-03-31 19:49:07 +05:30
|
|
|
let result;
|
|
|
|
|
switch (event) {
|
|
|
|
|
case EVENTS.setenvironment: {
|
|
|
|
|
result = await setEnvironment(data);
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
const responseEvent = EVENTS.EnvironmentUpdateResponse
|
|
|
|
|
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.emit(responseEvent, {
|
|
|
|
|
success: result.success,
|
2025-01-30 12:44:04 +05:30
|
|
|
message: result.message,
|
2025-03-31 19:49:07 +05:30
|
|
|
data: result.data,
|
|
|
|
|
error: result.error || null,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.warn(`Organization missing in response for event: ${event}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break
|
2025-01-30 12:44:04 +05:30
|
|
|
}
|
2025-03-31 19:49:07 +05:30
|
|
|
// 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
|
|
|
|
|
// }
|
2025-01-30 12:44:04 +05:30
|
|
|
|
|
|
|
|
default:
|
2025-03-31 19:49:07 +05:30
|
|
|
return;
|
2025-01-30 12:44:04 +05:30
|
|
|
}
|
2025-03-31 19:49:07 +05:30
|
|
|
|
|
|
|
|
|
2025-01-30 12:44:04 +05:30
|
|
|
}
|
|
|
|
|
const floorItemsHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
|
|
|
|
switch (event) {
|
|
|
|
|
|
|
|
|
|
case EVENTS.setFloorItems:{
|
|
|
|
|
const result = await setFloorItems(data);
|
|
|
|
|
// console.log('result: ', result);
|
|
|
|
|
if (result.success) {
|
|
|
|
|
io.emit(EVENTS.FloorItemsUpdateResponse, {
|
|
|
|
|
success: true || false,
|
|
|
|
|
message: result.message,
|
|
|
|
|
data: result.data,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization:result.organization
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// Emit error response
|
|
|
|
|
socket.emit(EVENTS.floorItemError, {
|
|
|
|
|
success: false,
|
|
|
|
|
message: result.message,
|
|
|
|
|
error: result.error,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization:result.organization
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;}
|
|
|
|
|
case EVENTS.deleteFloorItems:{
|
|
|
|
|
const result = await deleteFloorItems(data);
|
|
|
|
|
// console.log('result: ', result);
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.emit(EVENTS.FloorItemsDeleteResponse, {
|
|
|
|
|
success: true || false,
|
|
|
|
|
message: result.message,
|
|
|
|
|
data: result.data,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization:result.organization
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// Emit error response
|
|
|
|
|
socket.emit(EVENTS.floorItemError, {
|
|
|
|
|
success: false,
|
|
|
|
|
message: result.message,
|
|
|
|
|
error: result.error,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization:result.organization
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// console.error(`Unhandled event type: ${event}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const wallItemsHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
|
|
|
|
switch (event) {
|
|
|
|
|
|
|
|
|
|
case EVENTS.setWallItems:{
|
|
|
|
|
const result = await setWallItems(data);
|
|
|
|
|
// console.log('result: ', result);
|
|
|
|
|
if (result.success) {
|
|
|
|
|
io.emit(EVENTS.wallItemsUpdateResponse, {
|
|
|
|
|
success: true,
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
case EVENTS.deleteWallItems:{
|
|
|
|
|
const result = await deleteWallItems(data);
|
|
|
|
|
// console.log('result: ', result);
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.emit(EVENTS.wallItemsDeleteResponse, {
|
|
|
|
|
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:
|
|
|
|
|
// console.error(`Unhandled event type: ${event}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const lineHandleEvent =async (event: string, socket: Socket, data: any,io:any) => {
|
|
|
|
|
switch (event) {
|
|
|
|
|
case EVENTS.createLine:{
|
|
|
|
|
const result = await createLineItems(data);
|
|
|
|
|
// console.log('result: ', result);
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.emit(EVENTS.createLineResponse, {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
case EVENTS.updateLine: {
|
|
|
|
|
const result = await updateLineItems(data);
|
|
|
|
|
// console.log('result: ', result);
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.emit(EVENTS.updateLineResponse, {
|
|
|
|
|
success: true || false,
|
|
|
|
|
message: result.message,
|
|
|
|
|
data: result.data,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization: result.organization
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case EVENTS.deleteLine:{
|
|
|
|
|
const result = await deleteLineItems(data);
|
|
|
|
|
// console.log('result: ', result);
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.emit(EVENTS.deleteLineResponse, {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
case EVENTS.deletePoint:{
|
|
|
|
|
const result = await deleteLinPoiteItems(data);
|
|
|
|
|
// console.log('result: ', result);
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
|
|
|
|
io.emit(EVENTS.deletePointResponse, {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
case EVENTS.deleteLineLayer:{
|
|
|
|
|
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:
|
|
|
|
|
// console.error(`Unhandled event type: ${event}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const userStatus =async (event: string, socket: Socket, data: any,io:any) => {
|
|
|
|
|
switch (event) {
|
|
|
|
|
case EVENTS.connection: {
|
|
|
|
|
// console.log('EVENTS.connection: ', EVENTS.connection);
|
|
|
|
|
// console.log('event: ', event);
|
|
|
|
|
const result = await activeUsers(data);
|
|
|
|
|
if (result?.success) {
|
|
|
|
|
// console.log('result.success: ', result.success)
|
|
|
|
|
|
|
|
|
|
io.emit(EVENTS.userConnect, {
|
|
|
|
|
success: true || false,
|
|
|
|
|
message: result.message,
|
|
|
|
|
data: result.data,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization:result.organization
|
|
|
|
|
|
|
|
|
|
});}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case EVENTS.disconnect: {
|
|
|
|
|
// console.log('EVENTS.disconnect: ', EVENTS.connection);
|
|
|
|
|
// console.log('event: ', event);
|
|
|
|
|
const result = await activeUserOffline(data);
|
|
|
|
|
if (result?.success) {
|
|
|
|
|
// console.log('result.success: ', result.success)
|
|
|
|
|
|
|
|
|
|
io.emit(EVENTS.userDisConnect, {
|
|
|
|
|
success: true || false,
|
|
|
|
|
message: result.message,
|
|
|
|
|
data: result.data,
|
|
|
|
|
socketId: socket.id,
|
|
|
|
|
organization:result.organization
|
|
|
|
|
|
|
|
|
|
});}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-18 17:46:24 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-28 18:53:20 +05:30
|
|
|
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) {
|
2025-03-29 17:47:16 +05:30
|
|
|
case EVENTS.addPanel:{
|
2025-03-28 18:53:20 +05:30
|
|
|
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);
|
2025-03-29 17:47:16 +05:30
|
|
|
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
2025-03-28 18:53:20 +05:30
|
|
|
// 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,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-03-29 17:47:16 +05:30
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-28 18:53:20 +05:30
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-03-29 17:47:16 +05:30
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-18 17:46:24 +05:30
|
|
|
|
2025-01-30 12:44:04 +05:30
|
|
|
export const initSocketServer = (httpServer: any) => {
|
|
|
|
|
const io = new Server(httpServer, {
|
|
|
|
|
cors: {
|
|
|
|
|
origin: '*', // Allow CORS for all origins (adjust in production)
|
|
|
|
|
methods: ['GET', 'POST'],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-28 18:53:20 +05:30
|
|
|
|
2025-01-30 12:44:04 +05:30
|
|
|
// Listen for new connections
|
|
|
|
|
io.on(EVENTS.connection, (socket: Socket) => {
|
|
|
|
|
// console.log(`New client connected: ${socket.id}`);
|
|
|
|
|
// console.log(socket.handshake.auth);
|
|
|
|
|
userStatus(EVENTS.connection, socket, socket.handshake.auth,io);
|
|
|
|
|
|
|
|
|
|
// Handle all incoming events with the handleEvent function
|
|
|
|
|
socket.onAny((event: string, data: any,) => {
|
|
|
|
|
cameraHandleEvent(event, socket, data,io);
|
|
|
|
|
EnvironmentHandleEvent(event, socket, data,io);
|
|
|
|
|
floorItemsHandleEvent(event, socket, data,io);
|
|
|
|
|
wallItemsHandleEvent(event, socket, data,io);
|
|
|
|
|
lineHandleEvent(event, socket, data,io);
|
2025-03-18 17:46:24 +05:30
|
|
|
zoneHandleEvent(event, socket, data,io);
|
2025-01-30 12:44:04 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
socket.on(EVENTS.disconnect, (reason: string) => {
|
|
|
|
|
// console.log(`Client disconnected: ${socket.id}, Reason: ${reason}`);
|
|
|
|
|
// console.log(socket.handshake.auth);
|
|
|
|
|
userStatus(EVENTS.disconnect, socket, socket.handshake.auth,io);
|
|
|
|
|
// Perform cleanup or other necessary actions
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return io;
|
|
|
|
|
};
|