Esc to clear, Enter to open the best match, click an export to open it in its page
whip_phone

Phone apps

An app is one JavaScript file your resource ships. The phone loads it and draws it, and your server answers it with SecureCallbacks, so it has WHIP's checks as the built-in apps do. This page builds a small one; whip_phone/docs/MODULES.md is the full reference, with every field, the UI kit, apps drawn with React or three.js, and scoped CSS.

The example is a resource named mycars: a My Cars app listing the player's cars, which marks one that's out on their map.

1. The resource

fx_version 'cerulean'
game 'gta5'
lua54 'yes'

dependency 'whip_core'
shared_script '@whip_core/lib/satellite.lua'
server_script 'server.lua'
client_script 'client.lua'
files { 'html/phone_app.js' }   -- a file not listed never reaches players

There's no dependency 'whip_phone': Whip.registerWith below adds the app whenever whip_phone runs, so mycars starts with or without the phone.

2. Register the app (client)

-- client.lua
Whip.registerWith('whip_phone', function()   -- now, and again each time whip_phone starts
    local ok, why = exports.whip_phone:RegisterModule({ id = 'mycars', script = 'html/phone_app.js' })
    if not ok then print('[mycars] no phone app: ' .. tostring(why)) end
end)

RegisterNetEvent('mycars:waypoint', function(x, y)
    SetNewWaypoint(x, y)
end)

The app's requests use your resource's name, so app.request('list') asks the SecureCallback mycars:list. The app goes when your resource stops.

3. The app

// html/phone_app.js
(() => {
  const { kit: K, icons: I } = window.WhipPhone;
  WhipPhone.module({
    id: 'mycars', name: 'My Cars', version: '1.0.0', icon: I.pin,
    state: () => ({ cars: [], loaded: false }),
    async open(app) {
      app.state.cars = await app.request('list').catch(() => []);   // asks mycars:list
      app.state.loaded = true;
    },
    render(app) {
      const s = app.state;
      const rows = s.cars.map((c) => K.row({
        label: c.name, sub: c.plate, value: c.out ? 'Out' : 'Stored',
        act: c.out ? 'find' : '', hint: c.out ? 'Find' : '', d: { id: c.id },
      }));
      const body = rows.length ? K.list(rows) : K.empty({ title: s.loaded ? 'No cars' : 'Loading…' });
      return K.screen('list', K.title('My Cars') + K.scroll(body));
    },
    actions: {
      async find(app, d) {
        try {
          await app.request('find', { id: Number(d.id) });
          app.toast('Marked on your map');
        } catch (err) {
          app.toast(err.reason || 'Not found');
        }
      },
    },
  });
})();

render returns HTML from the kit's builders, which escape the text you give them, and the phone draws it again after every action and request. A row with act runs that action with its d values (as strings), from the mouse or the controller, and hint names the A button. A refused request rejects with err.reason.

4. Answer it (server)

-- server.lua
-- Name args in params, or the handler never gets what the app sent
local REQUEST = { rateLimit = 1000, params = { { 'args', 'any' } } }

Whip.register(function()
    Whip.core:SecureCallback('mycars:list', REQUEST, function(source)
        local out = {}
        for _, car in ipairs(Whip.core:GetVehiclesOf(source) or {}) do
            out[#out + 1] = {
                id = car.vehicleId, name = car.displayName or car.model,
                plate = car.plate, out = car.state == 'out',
            }
        end
        return out
    end)

    Whip.core:SecureCallback('mycars:find', REQUEST, function(source, player, args)
        local car = Whip.core:GetVehicle(tonumber(type(args) == 'table' and args.id))
        if type(car) ~= 'table' or car.owner.charId ~= player.charId then
            return false, 'Not your car'
        end
        if car.state ~= 'out' or not car.coords then return false, 'It is in a garage' end
        TriggerClientEvent('mycars:waypoint', source, car.coords.x, car.coords.y)
        return true
    end)
end)
Check everything an app sends. It runs in the player's game, so a request can carry anything. 'any' lets whip_core pass the table through: check each field you read, and that what it names is theirs, as mycars:find checks the owner.

What an app can do

ToUse
Ask your serverapp.request(action, args), a Promise of the answer
Tell the playerapp.toast(text), or app.notify({ title, text, kind, args }) for a capsule that opens your app with args
Hear your serveron: { changed(app, data) { … } }, run by Push(source, 'mycars', 'changed', data)
Show a screen with BackKeep it in app.state, give K.screen its own key, and return true from back(app) when you close it
Put a number on the iconbadge(app)
Use the controller's Xx(app), returning { label, run } or null
Open another appapp.open('messages', { number })
Show a picture or a font from your resourceapp.asset('img/car.png'). A bare path points at whip_phone's page
Draw it with React, Vue or three.jsmount(app, el, view) in place of render: Mount mode in MODULES.md
Give an answer back to a scriptapp.done(result), when RunApp opened it

Rules

Trying it in a browser

Serve whip_phone's html folder (for example python -m http.server inside it) and open preview.html: it runs the real phone on html/dev/mock.js, with a bar that fires calls, texts and notifications. Add your app to preview.html and answer its requests in mock.js, as the example Garage app (html/dev/example/app.js) does.