process external scans and check room exists
This commit is contained in:
parent
83ab0c4ea7
commit
70d03553d7
5 changed files with 149 additions and 1 deletions
|
@ -9,6 +9,9 @@ import SettingHelper from "../helpers/settingsHelper";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import ico from "sharp-ico";
|
import ico from "sharp-ico";
|
||||||
import { FileSystemHelper } from "../helpers/fileSystemHelper";
|
import { FileSystemHelper } from "../helpers/fileSystemHelper";
|
||||||
|
import { SocketConnectionTypes } from "../enums/socketEnum";
|
||||||
|
import SocketServer from "../websocket";
|
||||||
|
import BadRequestException from "../exceptions/badRequestException";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all calendar items by types or nscdr
|
* @description get all calendar items by types or nscdr
|
||||||
|
@ -54,6 +57,26 @@ export async function getCalendarItemsByTypes(req: Request, res: Response): Prom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get all calendar items by types or nscdr
|
||||||
|
* @summary passphrase is passed as value pair like `type:passphrase`
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function checkScannerRoomExists(req: Request, res: Response): Promise<any> {
|
||||||
|
let roomId = req.body.roomId;
|
||||||
|
|
||||||
|
const socketsInOtherRoom = await SocketServer.server.of(SocketConnectionTypes.scanner).in(roomId).fetchSockets();
|
||||||
|
const count = socketsInOtherRoom.length;
|
||||||
|
|
||||||
|
if (count != 0) {
|
||||||
|
res.sendStatus(204);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("room does not exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get configuration of UI
|
* @description get configuration of UI
|
||||||
* @param req {Request} Express req object
|
* @param req {Request} Express req object
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import {
|
import {
|
||||||
|
checkScannerRoomExists,
|
||||||
getApplicationConfig,
|
getApplicationConfig,
|
||||||
getApplicationFavicon,
|
getApplicationFavicon,
|
||||||
getApplicationIcon,
|
getApplicationIcon,
|
||||||
|
@ -18,6 +19,10 @@ router.post("/reportdamage", async (req, res) => {
|
||||||
res.send("TODO");
|
res.send("TODO");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post("/checkscannerroom", async (req, res) => {
|
||||||
|
await checkScannerRoomExists(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/configuration", async (req, res) => {
|
router.get("/configuration", async (req, res) => {
|
||||||
await getApplicationConfig(req, res);
|
await getApplicationConfig(req, res);
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,10 @@ import pScanner from "./pScanner";
|
||||||
export default abstract class SocketServer {
|
export default abstract class SocketServer {
|
||||||
private static io: Server;
|
private static io: Server;
|
||||||
|
|
||||||
|
static get server() {
|
||||||
|
return this.io;
|
||||||
|
}
|
||||||
|
|
||||||
public static init(httpServer: httpServerType) {
|
public static init(httpServer: httpServerType) {
|
||||||
this.io = new Server(httpServer, {
|
this.io = new Server(httpServer, {
|
||||||
cors: {
|
cors: {
|
||||||
|
|
116
src/websocket/pScanner/index.ts
Normal file
116
src/websocket/pScanner/index.ts
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
import { Server, Socket } from "socket.io";
|
||||||
|
import { emitEvent, handleEvent } from "../handleEvent";
|
||||||
|
import { SocketConnectionTypes } from "../../enums/socketEnum";
|
||||||
|
|
||||||
|
export default (io: Server, socket: Socket) => {
|
||||||
|
socket.on(
|
||||||
|
"session:join",
|
||||||
|
handleEvent(
|
||||||
|
"noPermissionsRequired",
|
||||||
|
async (room: string) => {
|
||||||
|
const socketsInOtherRoom = await io.of(SocketConnectionTypes.scanner).in(room).fetchSockets();
|
||||||
|
const count = socketsInOtherRoom.length;
|
||||||
|
|
||||||
|
if (count == 0) {
|
||||||
|
return {
|
||||||
|
type: "status-session:join",
|
||||||
|
answer: { status: "failed" },
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
socket.join(room);
|
||||||
|
emitEvent(
|
||||||
|
{
|
||||||
|
type: "package-scanner_join",
|
||||||
|
answer: socket.id,
|
||||||
|
room: room,
|
||||||
|
namespace: SocketConnectionTypes.scanner,
|
||||||
|
},
|
||||||
|
socket,
|
||||||
|
io
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: "status-session:join",
|
||||||
|
answer: { status: "success" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
socket
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
socket.on(
|
||||||
|
"session:leave",
|
||||||
|
handleEvent(
|
||||||
|
"noPermissionsRequired",
|
||||||
|
async () => {
|
||||||
|
console.log("called leave");
|
||||||
|
const rooms = Array.from(socket.rooms).filter((r) => r !== socket.id);
|
||||||
|
const room = rooms[0];
|
||||||
|
|
||||||
|
socket.leave(room);
|
||||||
|
emitEvent(
|
||||||
|
{
|
||||||
|
type: "package-scanner_leave",
|
||||||
|
answer: socket.id,
|
||||||
|
room: room,
|
||||||
|
namespace: SocketConnectionTypes.scanner,
|
||||||
|
},
|
||||||
|
socket,
|
||||||
|
io
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: "status-session:leave",
|
||||||
|
answer: { status: "success" },
|
||||||
|
};
|
||||||
|
},
|
||||||
|
socket
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
socket.on(
|
||||||
|
"scan:send",
|
||||||
|
handleEvent(
|
||||||
|
"noPermissionsRequired",
|
||||||
|
async (result: string) => {
|
||||||
|
const rooms = Array.from(socket.rooms).filter((r) => r !== socket.id);
|
||||||
|
const room = rooms[0];
|
||||||
|
|
||||||
|
emitEvent(
|
||||||
|
{
|
||||||
|
type: "package-scan_receive",
|
||||||
|
answer: result,
|
||||||
|
room: room,
|
||||||
|
namespace: SocketConnectionTypes.scanner,
|
||||||
|
},
|
||||||
|
socket,
|
||||||
|
io
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: "status-scan:send",
|
||||||
|
answer: { status: "success" },
|
||||||
|
};
|
||||||
|
},
|
||||||
|
socket
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
socket.on("disconnecting", () => {
|
||||||
|
const rooms = Array.from(socket.rooms).filter((r) => r !== socket.id);
|
||||||
|
const room = rooms[0];
|
||||||
|
|
||||||
|
socket.leave(room);
|
||||||
|
emitEvent(
|
||||||
|
{
|
||||||
|
type: "package-scanner_leave",
|
||||||
|
answer: socket.id,
|
||||||
|
room: room,
|
||||||
|
namespace: SocketConnectionTypes.scanner,
|
||||||
|
},
|
||||||
|
socket,
|
||||||
|
io
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
|
@ -48,7 +48,7 @@ export default (io: Server, socket: Socket) => {
|
||||||
socket.on("disconnecting", () => {
|
socket.on("disconnecting", () => {
|
||||||
const rooms = Array.from(socket.rooms).filter((r) => r !== socket.id);
|
const rooms = Array.from(socket.rooms).filter((r) => r !== socket.id);
|
||||||
const room = rooms[0];
|
const room = rooms[0];
|
||||||
io.of(SocketConnectionTypes.pscanner).in(room).disconnectSockets();
|
// io.of(SocketConnectionTypes.pscanner).in(room).disconnectSockets();
|
||||||
emitEvent(
|
emitEvent(
|
||||||
{
|
{
|
||||||
type: "package-host_leave",
|
type: "package-host_leave",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue