admin side scan connection
This commit is contained in:
parent
b29cdae088
commit
83ab0c4ea7
7 changed files with 156 additions and 6 deletions
|
@ -3,6 +3,8 @@ import { PermissionObject, PermissionType, PermissionSection, PermissionModule }
|
|||
import PermissionHelper from "../helpers/permissionHelper";
|
||||
import ForbiddenRequestException from "../exceptions/forbiddenRequestException";
|
||||
import { SocketMap } from "../storage/socketMap";
|
||||
import { SocketConnectionTypes } from "../enums/socketEnum";
|
||||
import SocketServer from ".";
|
||||
|
||||
export type EventResponseType = {
|
||||
answer: any;
|
||||
|
@ -23,7 +25,8 @@ type PermissionPass =
|
|||
section: PermissionSection;
|
||||
module?: PermissionModule;
|
||||
}
|
||||
| "admin";
|
||||
| "admin"
|
||||
| "noPermissionsRequired";
|
||||
|
||||
export let handleEvent = (
|
||||
permissions: PermissionPass,
|
||||
|
@ -37,7 +40,7 @@ export let handleEvent = (
|
|||
if (!socketData.isOwner && !socketData.permissions.admin) {
|
||||
throw new ForbiddenRequestException(`missing admin permission`);
|
||||
}
|
||||
} else {
|
||||
} else if (permissions != "noPermissionsRequired") {
|
||||
if (
|
||||
!socketData.isOwner &&
|
||||
!PermissionHelper.can(socketData.permissions, permissions.type, permissions.section, permissions.module)
|
||||
|
@ -58,6 +61,25 @@ export let handleEvent = (
|
|||
};
|
||||
};
|
||||
|
||||
export let emitEvent = (
|
||||
event: EventResponseType & { namespace?: SocketConnectionTypes },
|
||||
socket: Socket,
|
||||
io: Server
|
||||
) => {
|
||||
try {
|
||||
const { answer, type, room, namespace } = event;
|
||||
if (room === undefined || room == "") {
|
||||
socket.emit(type, answer);
|
||||
} else if (namespace === undefined) {
|
||||
socket.to(room).emit(type, answer);
|
||||
} else {
|
||||
io.of(namespace).emit(type, answer);
|
||||
}
|
||||
} catch (e) {
|
||||
socket.emit("error", e.message);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
socket.on(
|
||||
"event",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue