01-29-2019 12:01 PM - edited 03-18-2019 02:37 PM
If a third-party control system uses the API to:
Thank you!
02-08-2019 11:20 AM - edited 02-10-2019 11:08 PM
Hi Thom,
You can subscribe to the lost connection status for the connected device. The ID does not change even though the control system disappears which is normal after a certain time (1 minute or so with no connection). Sending the heartbeat will revive the registered peripheral (even after a boot). I have not looked into closely but finding a way of dynamically keeping track of the id number should not be that difficult.
You can use the macro as a watchdog based on this, please see the simplified example:
When the peripheral loses the connection it removes all the inputs (here you can insert other actions as well). When the control device reconnects, it recreates the inputs (as you say the creation of sources would come from the control device, but I let the macro do this as a proof of concept). The macro can also do this but that should only remove upon lost connection and handle the "offline" scenario to improve the user experience.
UPDATED:
const xapi = require('xapi');
function createInputs() {
var inputs = [
{
'ConnectorId':'2',
'SourceIdentifier':'s1',
'Name':'PC Input',
'Type':'PC'
},
{
'ConnectorId':'2',
'SourceIdentifier':'s2',
'Name':'AppleTV',
'Type':'mediaplayer'
}
];
for (var i = 0; i < inputs.length; i++) {
xapi.command('UserInterface Presentation ExternalSource Add', inputs[i]);
}
}
function removeInputs() {
xapi.command('UserInterface Presentation ExternalSource RemoveAll');
}
xapi.status.on('Peripherals ConnectedDevice', event => {
if (!("ghost" in event)) {
xapi.status.get('Peripherals ConnectedDevice ' + event.id).then((device) => {
if (device.Type == 'ControlSystem') {
switch (device.Status) {
case 'LostConnection':
//Do stuff here
removeInputs();
break;
case 'Connected':
//Do stuff here
console.log('Connected');
createInputs();
break;
}
}
}).catch(error => {
console.log(JSON.stringify(error));
});
}
});
So here is the example flow:
xCommand UserInterface Presentation ExternalSource List OK *r ExternalSourceListResult (status=OK): #No sources ** end
xcommand Peripherals HeartBeat id: 1 timeout: 10 #Send heartbeat OK *r PeripheralsHeartBeatResult (status=OK): ** end *s Peripherals ConnectedDevice 1010 HardwareInfo: "" *s Peripherals ConnectedDevice 1010 ID: "1" *s Peripherals ConnectedDevice 1010 Name: "Control" *s Peripherals ConnectedDevice 1010 SoftwareInfo: "" *s Peripherals ConnectedDevice 1010 Status: Connected #Device connects again *s Peripherals ConnectedDevice 1010 Type: ControlSystem *s Peripherals ConnectedDevice 1010 UpgradeStatus: None ** end xCommand UserInterface Presentation ExternalSource List #See if the macro has done its job OK *r ExternalSourceListResult (status=OK): *r ExternalSourceListResult Source 1 ConnectorId: 2 *r ExternalSourceListResult Source 1 Name: "AppleTV" *r ExternalSourceListResult Source 1 SourceIdentifier: "s2" *r ExternalSourceListResult Source 1 State: NotReady *r ExternalSourceListResult Source 1 Type: mediaplayer *r ExternalSourceListResult Source 2 ConnectorId: 2 *r ExternalSourceListResult Source 2 Name: "PC Input" *r ExternalSourceListResult Source 2 SourceIdentifier: "s1" *r ExternalSourceListResult Source 2 State: NotReady *r ExternalSourceListResult Source 2 Type: PC ** end *s Peripherals ConnectedDevice 1010 Status: LostConnection #Lost connection *s Diagnostics Message 12 Description: "Expected a Control System, none is connected." *s Diagnostics Message 12 Level: Error *s Diagnostics Message 12 References: "" *s Diagnostics Message 12 Type: ControlSystemConnection ** end
xCommand UserInterface Presentation ExternalSource List #Check if the macro has removed the sources OK *r ExternalSourceListResult (status=OK): #No sources ** end
Hope this helps you.
/Magnus
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide