NssClient
This ui component is used to communicate between the browser user interface (NUI) and the game client.
NUI Usage
ES6 module import
For NssUiApi usage, please see the README.md of the nss_libs/ui folder.
Alternative example of direct ES6 module import:
import {NssClient} from "nui://nss_libs/ui/NssClient/NssClient.js";Create instance
/**
* @type {NssClient}
*/
const nss_client = new NssClient('YOUR_RESOURCE_NAME');Ensure that the resource name is the identical and correct name of your resource folder because it is used for paths.
Send simple message
/**
* @type {NssClient}
*/
const nss_client = new NssClient('YOUR_RESOURCE_NAME');
const request_data = {
// Your data here...
example: "Hello World!"
};
nss_client.post('EVENT_NAME', request_data);Send message with callback
request_data will be automatically extended with property response_event_type. You must have to response directly to the request. Use the response_event_type as value of type of response_data. This ensures the response is linked to the related request callback.
Listen to client messages
Only one callback is allowed per event type. If you want to add more callbacks, you have to add a wrapper callback that manage the different callbacks.
Standard close message
This will send a message to the client with the event name close. Often used to close the NUI by the client.
Use mock for local development
Import the NssClient as shown above and use the following code to use the mock instead of the real client.
Client Usage
Important
register_nui_callback_wrapper and send_nui_message_wrapper are wrappers for the native functions RegisterNUICallback and SendNUIMessage. You have to provide these functions to the getNssClientApi form your resource. Because the resource where it is declared is responsible for the communication between the NUI and the game client.
Last updated
Was this helpful?