Version: Smart Feature Phone 3.0

TimeService 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/time/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 _timeManager = null;
sessionstate.onsessionconnected = function () {
console.log(`TimeService onsessionconnected`);
lib_time.TimeService.get(session).then((TimeServiceService) => {
console.log(`Got TimeService : #TimeServiceService.service_id}`);
_timeManager = TimeServiceService;
}).catch((e) => {
console.log(`Error calling TimeService service${JSON.stringify(e)}`);
_timeManager = null;
});
};
sessionstate.onsessiondisconnected = function () {
console.log(`TimeService onsessiondisconnected Daemon Crashed`);
};
// On desktop version, set ENV WS_RUNTIME_TOKEN=secrettoken
session.open('websocket', 'localhost', 'secrettoken', sessionstate, true);

Then the developer can use _timeManager as TimeService service instance.

This service implements the Time interface.


CallbackReason enumeration#

{
NONE,
TIME_CHANGED,
TIMEZONE_CHANGED
}

TimeInfo dictionnary#

{
reason: <a href="#enumeration_CallbackReason">CallbackReason</a>,
timezone: string,
delta: integer
}

TimeObserver callback object#

Creating a TimeObserver object#

Use code similar to:

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

Methods#

callback

// info: TimeInfo
callback(info)

Resolves with void

Rejects with void

Time Interface#

Methods#

  addObserver get getElapsedRealTime removeObserver set setTimezone

// reason: CallbackReason
// observer: TimeObserver
addObserver(reason, observer)

Resolves with void

Rejects with void


get()

Resolves with Date

Rejects with void


getElapsedRealTime()

Resolves with integer

Rejects with void


// reason: CallbackReason
// observer: TimeObserver
removeObserver(reason, observer)

Resolves with void

Rejects with void


// time: Date
set(time)

Resolves with void

Rejects with void


// timezone: string
setTimezone(timezone)

Resolves with void

Rejects with void


Events#

  TIME_CHANGED TIMEZONE_CHANGED

The TIME_CHANGED event emits a void

To manage this event, use code similar to:

function handleEvent(value) {
...
}
_timeManager.addEventListener(_timeManager.TIME_CHANGED_EVENT, handleEvent);
_timeManager.removeEventListener(_timeManager.TIME_CHANGED_EVENT, handleEvent);

The TIMEZONE_CHANGED event emits a void

To manage this event, use code similar to:

function handleEvent(value) {
...
}
_timeManager.addEventListener(_timeManager.TIMEZONE_CHANGED_EVENT, handleEvent);
_timeManager.removeEventListener(_timeManager.TIMEZONE_CHANGED_EVENT, handleEvent);

Sample code#

New APIs sample code