Hi,
you can use manager
object's appStarted
signal to reconnect the API when the app has been restarted:
const myAppId = 'com.myapps.testapp/1';
let apiCtrl;
let api;
let managerCtrl;
let manager;
async function connectApi()
{
if (apiCtrl)
apiCtrl.disconnect(); // Note: this is currently needed first
apiCtrl = new va.RemoteObject('/apis/' + myAppId);
api = await apiCtrl.connect();
}
async function connect()
{
managerCtrl = new va.RemoteObject('/manager');
manager = await managerCtrl.connect();
manager.$appStarted.connect((appId) =>
{
if (appId === myAppId)
connectApi();
});
connectApi();
}
Now, if you add connect()
call before setInterval()
call in your example, the api object should be always connected and ready to serve whenever the app is running.
P.S. there seems to be also an issue that the previous remote api object instance needs to be disconnected first, or reconnecting won't work. We'll be looking at
that also.