Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): new WebView API #335

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, string>;
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).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<K extends shared.ExtractStringKeys<ICustomWebViewMeta>>(key: K): void;
Expand Down