On KaiOS, there are some APIs that aren't implemented as Web APIs built into Gecko, but are powered by a special api-daemon
instead. They are not documented in the official KaiOS 2.5 documentation, but are documented in the KaiOS 3.0 docs (see here for example).
On KaiOS 2.5, these APIs are currently only used by WhatsApp.
A new version of the api-daemon
used in KaiOS 3.0 is open-source: https://github.com/kaiostech/api-daemon. It is written in Rust.
The API daemon also serves the KaiAds SDK for privileged apps.
The daemon runs an HTTP/WebSocket server listening on localhost. The port differs between operating system versions and environments:
KaiOS version | Environment | Port |
---|---|---|
KaiOS 3.0 | Device | 80 |
KaiOS 3.0 | Simulator | 8081 |
KaiOS 2.5 | Device | 8081 |
KaiOS 2.5 | Simulator | (API daemon not present) |
The manifest permission external-api
is required on KaiOS 2.5.
APIs are provided by services. Each service has a JS client and a Rust library.
The JS clients are available at http://127.0.0.1:<port>/api/v1
.
All JS clients require shared/core.js
and shared/session.js
to be loaded, in the correct order:
Example:
<script src="http://127.0.0.1:8081/api/v1/shared/core.js"></script>
<script src="http://127.0.0.1:8081/api/v1/shared/session.js"></script>
Each service exposes APIs in library at <service>/service.js
in a lib_<service>
variable.
Example:
<script src="http://127.0.0.1:8081/api/v1/telephony/service.js">
The session.js
script also provides a lib_session
API (see Session management).
The Rust libraries are linked into the api-daemon
binary at system build time, so they can't be changed or updated without recompiling the daemon. However, you can also create remote services that work like API add-ons.
Before loading APIs, you need to establish a session (requires loading the core libraries first):
var sess = new lib_session.Session();
function onsessionconnected(){
/* Handle session connect */
}
function onsessiondisconnected(){
/* Handle session disconnect */
}
session.open('websocket', 'localhost:<port>', 'secrettoken', {onsessionconnected, onsessiondisconnected}, true);
To load a service and its APIs, first load its library (see JS clients) and then initialize it:
/* in function onsessionconnected */
lib_<service>.<interface>.get(sess).then(function(srv){
/* Store srv somewhere, since it provides the APIs */
/* Maybe use it now */
});
This list might be incomplete/inaccurate
On KaiOS 2.5:
libsignal
telephony
tcpsocket
wavoip2
On KaiOS 3.0:
accounts
apps
audiovolumemanager
contacts
devicecapability
deviceconfig
fota
geckobridge
libsignal
powermanager
procmanager
settings
tcpsocket
telephony
time