diff --git a/core/core-server.ts b/core/core-server.ts index d2602f4..add3bd0 100644 --- a/core/core-server.ts +++ b/core/core-server.ts @@ -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(); } diff --git a/core/package-lock.json b/core/package-lock.json index ac4596e..c47ab02 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -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", diff --git a/core/package.json b/core/package.json index e2605d7..6caa2c1 100644 --- a/core/package.json +++ b/core/package.json @@ -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", diff --git a/core/types.d.ts b/core/types.d.ts index adbba13..4d1679d 100644 --- a/core/types.d.ts +++ b/core/types.d.ts @@ -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; export type Con_Hook = (client: SocioSession, request: IncomingMessage) => void | Promise; export type Discon_Hook = (client: SocioSession) => void | Promise; @@ -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; export type FileDownload_Hook = (client: SocioSession, data: any) => FS_Util_Response | Promise; export type Upd_Hook = (sessions: Map, initiator: SocioSession, sql: string, params:object) => boolean | Promise; -export type Endpoint_Hook = (client: SocioSession, endpoint:string) => string | Promise; +export type Endpoint_Hook = (client: SocioSession, endpoint: string) => string | Promise; +export type Gen_Prop_Name_Hook = () => string | Promise; // export type _Hook = (client: SocioSession) => boolean; //client hook functions