gen_prop_name server hook

This commit is contained in:
Rolands 2023-11-27 18:52:50 +02:00
parent 74dbd03719
commit 1facb320aa
4 changed files with 8 additions and 7 deletions

View file

@ -46,7 +46,7 @@ export class SocioServer extends LogHandler {
//rate limits server functions globally
#ratelimits: { [key: string]: RateLimiter | null } = { con: null, upd:null};
#lifecycle_hooks: ServerLifecycleHooks = { con: undefined, discon: undefined, msg: undefined, sub: undefined, unsub: undefined, upd: undefined, auth: undefined, gen_client_id: undefined, grant_perm: undefined, serv: undefined, admin: undefined, blob: undefined, file_upload: undefined, file_download: undefined, endpoint: undefined }; //call the register function to hook on these. They will be called if they exist
#lifecycle_hooks: ServerLifecycleHooks = { con: undefined, discon: undefined, msg: undefined, sub: undefined, unsub: undefined, upd: undefined, auth: undefined, gen_client_id: undefined, grant_perm: undefined, serv: undefined, admin: undefined, blob: undefined, file_upload: undefined, file_download: undefined, endpoint: undefined, gen_prop_name:undefined }; //call the register function to hook on these. They will be called if they exist
//If the hook returns a truthy value, then it is assumed, that the hook handled the msg and the lib will not. Otherwise, by default, the lib handles the msg.
//msg hook receives all incomming msgs to the server.
//upd works the same as msg, but for everytime updates need to be propogated to all the sockets.
@ -359,7 +359,7 @@ export class SocioServer extends LogHandler {
}
// if a name hasnt been supplied, then generate a unique prop name and return it
if (!data?.prop){
data.prop = UUID();
data.prop = this.#lifecycle_hooks.gen_prop_name ? await this.#lifecycle_hooks.gen_prop_name() : UUID();
while (this.#props.has(data.prop)) data.prop = UUID();
}

View file

@ -1,12 +1,12 @@
{
"name": "socio",
"version": "1.6.2",
"version": "1.6.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "socio",
"version": "1.6.2",
"version": "1.6.3",
"license": "MIT",
"dependencies": {
"base64-js": "^1.5.1",

View file

@ -1,6 +1,6 @@
{
"name": "socio",
"version": "1.6.2",
"version": "1.6.3",
"description": "A WebSocket Real-Time Communication (RTC) API framework.",
"main": "./dist/core.js",
"type": "module",

5
core/types.d.ts vendored
View file

@ -25,7 +25,7 @@ export type LoggingOpts = { logging?: LoggerOptions };
export type SessionOpts = { session_timeout_ttl_ms: number, max_payload_size?: number };
//server hook functions
export type ServerLifecycleHooks = { con?: Con_Hook, discon?: Discon_Hook, msg?: Msg_Hook, sub?: Sub_Hook, unsub?: Unsub_Hook, upd?: Upd_Hook, auth?: Auth_Hook, gen_client_id?: GenCLientID_Hook, grant_perm?: GrantPerm_Hook, serv?: Serv_Hook, admin?: Admin_Hook, blob?: Blob_Hook, file_upload?: FileUpload_Hook, file_download?: FileDownload_Hook, endpoint?: Endpoint_Hook };
export type ServerLifecycleHooks = { con?: Con_Hook, discon?: Discon_Hook, msg?: Msg_Hook, sub?: Sub_Hook, unsub?: Unsub_Hook, upd?: Upd_Hook, auth?: Auth_Hook, gen_client_id?: GenCLientID_Hook, grant_perm?: GrantPerm_Hook, serv?: Serv_Hook, admin?: Admin_Hook, blob?: Blob_Hook, file_upload?: FileUpload_Hook, file_download?: FileDownload_Hook, endpoint?: Endpoint_Hook, gen_prop_name?: Gen_Prop_Name_Hook };
export type GenCLientID_Hook = () => ClientID | Promise<ClientID>;
export type Con_Hook = (client: SocioSession, request: IncomingMessage) => void | Promise<void>;
export type Discon_Hook = (client: SocioSession) => void | Promise<void>;
@ -40,7 +40,8 @@ export type Admin_Hook = (client: SocioSession, data: MessageDataObj) => boolean
export type FileUpload_Hook = (client: SocioSession, files?: SocioFiles, data?: any) => Bit | boolean | Promise<Bit | boolean>;
export type FileDownload_Hook = (client: SocioSession, data: any) => FS_Util_Response | Promise<FS_Util_Response>;
export type Upd_Hook = (sessions: Map<ClientID, SocioSession>, initiator: SocioSession, sql: string, params:object) => boolean | Promise<boolean>;
export type Endpoint_Hook = (client: SocioSession, endpoint:string) => string | Promise<string>;
export type Endpoint_Hook = (client: SocioSession, endpoint: string) => string | Promise<string>;
export type Gen_Prop_Name_Hook = () => string | Promise<string>;
// export type _Hook = (client: SocioSession) => boolean;
//client hook functions