Version: Smart Feature Phone 3.0

SettingsManager service

Instanciating the service#

Load the following scripts:

<script src="http://127.0.0.1/api/v1/shared/core.js"></script>
<script src="http://127.0.0.1/api/v1/shared/session.js"></script>
<script src="http://127.0.0.1/api/v1/settings/service.js"></script>

You can then get an instance of the service with code similar to:

const session = new lib_session.Session();
const sessionstate = {};
let _settingsManager = null;
sessionstate.onsessionconnected = function () {
console.log(`SettingsManager onsessionconnected`);
lib_settings.SettingsManager.get(session).then((SettingsManagerService) => {
console.log(`Got SettingsManager : #SettingsManagerService.service_id}`);
_settingsManager = SettingsManagerService;
}).catch((e) => {
console.log(`Error calling SettingsManager service${JSON.stringify(e)}`);
_settingsManager = null;
});
};
sessionstate.onsessiondisconnected = function () {
console.log(`SettingsManager onsessiondisconnected Daemon Crashed`);
};
// On desktop version, set ENV WS_RUNTIME_TOKEN=secrettoken
session.open('websocket', 'localhost', 'secrettoken', sessionstate, true);

Then the developer can use _settingsManager as SettingsManager service instance.

This service implements the SettingsFactory interface.


GetErrorReason enumeration#

{
UNKNOWN_ERROR,
NON_EXISTING_SETTING
}

GetError dictionnary#

{
name: string,
reason: <a href="#enumeration_GetErrorReason">GetErrorReason</a>
}

SettingInfo dictionnary#

{
name: string,
value: json
}

SettingObserver callback object#

Creating a SettingObserver object#

Use code similar to:

class MyCallbackObject extends lib_settings.SettingObserverBase {
constructor(service, session) {
super(service.id, session);
}
callback(...) {
...
}

Methods#

callback

// setting: SettingInfo
callback(setting)

Resolves with void

Rejects with void

SettingsFactory Interface#

Methods#

  addObserver clear get getBatch removeObserver set

// name: string
// observer: SettingObserver
addObserver(name, observer)

Resolves with void

Rejects with void


clear()

Resolves with void

Rejects with void


// name: string
get(name)

Resolves with SettingInfo

Rejects with GetError


// name: [string]
getBatch(name)

Resolves with [SettingInfo]

Rejects with void


// name: string
// observer: SettingObserver
removeObserver(name, observer)

Resolves with void

Rejects with void


// settings: [SettingInfo]
set(settings)

Resolves with void

Rejects with void


Events#

  CHANGE

The CHANGE event emits a SettingInfo

To manage this event, use code similar to:

function handleEvent(value) {
...
}
_settingsManager.addEventListener(_settingsManager.CHANGE_EVENT, handleEvent);
_settingsManager.removeEventListener(_settingsManager.CHANGE_EVENT, handleEvent);

Sample code#

New APIs sample code