From 06d1e65c6a69986d73629eb67df2d1afafa568d6 Mon Sep 17 00:00:00 2001 From: xshady <54737754+xxshady@users.noreply.github.com> Date: Wed, 29 Jan 2025 12:49:06 +0300 Subject: [PATCH] feat(client): new WebView API (#335) * feat(client): new WebView API * fix(client): new WebView API --- client/index.d.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/client/index.d.ts b/client/index.d.ts index 60e9ebc5..d12bb2fc 100644 --- a/client/index.d.ts +++ b/client/index.d.ts @@ -120,6 +120,18 @@ declare module "alt-client" { Justify, } + export enum CookieSameSite { + NoRestriction = "NO_RESTRICTION", + LaxMode = "LAX_MODE", + StrictMode = "STRICT_MODE", + } + + export enum CookiePriority { + Low = "LOW", + Medium = "MEDIUM", + High = "HIGH", + } + export interface IClientEvent { anyResourceError: (resourceName: string) => void; anyResourceStart: (resourceName: string) => void; @@ -574,6 +586,33 @@ declare module "alt-client" { max: number; } + export interface IWebViewParams { + url: string; + pos?: shared.IVector2; + size?: shared.IVector2; + isOverlay?: boolean; + drawableHash?: number; + targetTexture?: string; + headers?: Record; + cookies?: ICookie[]; + } + + export interface ICookie { + /** + * Cookie name must always start with "__altv_" + */ + name: `__altv_${string}`; + url: string; + value: unknown; + httpOnly?: boolean; + secure?: boolean; + domain?: string; + path?: string; + sameSite?: CookieSameSite; + priority: CookiePriority; + expires: number; + } + export class BaseObject extends shared.BaseObject { /** * Whether this entity was created clientside or serverside. (Clientside = false, Serverside = true). @@ -1918,10 +1957,16 @@ declare module "alt-client" { * Creates a WebView rendered on game object. * * @param url URL of the html file. - * @param propHash Hash of object to render on. - * @param targetTexture Name of object's texture to replace. + * @param drawableHash Hash of drawable to render on. + * @param targetTexture Name of texture to replace. + */ + constructor(url: string, drawableHash: number, targetTexture: string); + + /** + * Creates a WebView depending on params. + * */ - constructor(url: string, propHash: number, targetTexture: string); + constructor(params: IWebViewParams); /** * Emits specified event across particular WebView. @@ -2002,6 +2047,7 @@ declare module "alt-client" { public removeOutput(output: AudioOutput): void; public getOutputs(): readonly (AudioOutput | number)[]; public reload(ignoreCache?: boolean): void; + public setCookie(cookie: ICookie): void; public deleteMeta(key: string): void; public deleteMeta>(key: K): void;