Client/WebView Requests

Server Enviroment

NOTE

There can be only one request and no more with the same name across all controllers.

Decorators

Name Arguments Description
@OnPlayerRequest() name?: string Listens to client requests and returns a value back to the client.
@OnWebViewRequest() id: string | number, name?: string Listens to WebView requests and returns a value back to the webview.

@OnPlayerRequest()

The OnPlayerRequest decorator is used to listen to client requests and returns a value back to the client.

@Controller()
export class DeliciousMangoController {
    @OnClient('eat')
    public onEat(@Player() player: alt.Player) {
        return new Promise((resolve) => {
            setTimeout(() => {
                resolve(`${player.name} ate a mango!`);
            }, 200);
        });
    }
}
ts

@OnWebViewRequest()

The OnWebViewRequest decorator is used to listen to WebView requests and return a value back to the WebView.

@Controller()
export class DeliciousMangoController {
    @OnWebView('my_webview_id', 'eat')
    public onEat() {
        const timeToEat = 1000;
        return new Promise((resolve) => {
            setTimeout(() => {
                resolve('I ate');
            }, timeToEat);
        });
    }
}
ts
Last update at: 2024/04/29 10:15:50