TypeScript
NuiCallback
Client

Client

onNuiCallback

define an NUI callback and execute a function when the callback is received

onNuiCallback<T = unknown>(
  endpoint: string,
  callback: (
    data: T,
    callback: (returned: any) => void
  ) => void
): boolean

Parameters

  • endpoint: The unique name of the callback
  • callback: The function to run when the callback is received
    • data: The data sent from the NUI
    • callback: The callback value to return to the NUI, you always must call it back to the NUI

Returns

  • success: true if the callback was registered successfully

triggerNuiCallback

send an NUI message to the NUI

triggerNuiCallback(
  endpoint: string,
  ...parameters: any[]
): typeof ReturnType<SendNuiMessage>

Parameters

  • endpoint: The name of the callback to trigger
  • ...parameters: The parameters to pass with the callback

Returns

  • reponse: 1 | unknown

Examples

import { triggerNuiCallback, onNuiCallback } from '@trippler/tr_lib/client'
 
const success = onNuiCallback<{ message: string }>('client/module/test', (data) => {
  console.log(`call received with ${data}`)
  return data.message
})
 
const data = { message: 'Hello World' }
triggerNuiCallback('nui/module/test', data)
 
console.log(success) // true