Skip to content

Instantly share code, notes, and snippets.

@Aldaviva
Created June 4, 2022 08:32
Show Gist options
  • Save Aldaviva/bccd766099e2d7807da086feacf2c18a to your computer and use it in GitHub Desktop.
Save Aldaviva/bccd766099e2d7807da086feacf2c18a to your computer and use it in GitHub Desktop.
Cisco macros
import xapi from 'xapi';
const cameraBrightnessCheckboxWidgetId = "camera_brightness_checkbox";
const brightnessModeConfiguration = xapi.Config.Cameras.Camera["1"].Brightness.Mode;
brightnessModeConfiguration.on(renderBrightnessCheckbox);
render();
async function render(){
return renderBrightnessCheckbox(await brightnessModeConfiguration.get());
}
function renderBrightnessCheckbox(brightnessMode) {
const newValue = brightnessMode === "Auto" ? "on" : "off";
console.debug("Setting camera brightness checkbox to "+newValue);
return xapi.Command.UserInterface.Extensions.Widget.SetValue({
WidgetId: cameraBrightnessCheckboxWidgetId,
Value: newValue
});
}
xapi.Event.UserInterface.Extensions.Widget.Action.on(event => {
if(event.WidgetId === cameraBrightnessCheckboxWidgetId && event.Type === "changed"){
const newValue = event.Value === "on" ? "Auto" : "Manual";
console.info("Setting camera brightness to "+newValue);
return brightnessModeConfiguration.set(newValue);
}
});
// If other macros add or remove widgets (like Virgin Moon), Cisco will not preserve the UI state of our widgets, so re-render them.
xapi.Event.UserInterface.Extensions.Widget.LayoutUpdated.on(async () => await render());
<Extensions>
<Version>1.7</Version>
<Panel>
<PanelId>settings_panel</PanelId>
<Origin>local</Origin>
<Type>InCall</Type>
<Icon>Sliders</Icon>
<Color>#6F739E</Color>
<Name>Settings</Name>
<ActivityType>Custom</ActivityType>
<Page>
<Name>Settings</Name>
<Row>
<Name>Camera brightness</Name>
<Widget>
<WidgetId>widget_1</WidgetId>
<Name>Manual</Name>
<Type>Text</Type>
<Options>size=1;fontSize=small;align=right</Options>
</Widget>
<Widget>
<WidgetId>camera_brightness_checkbox</WidgetId>
<Type>ToggleButton</Type>
<Options>size=1</Options>
</Widget>
<Widget>
<WidgetId>widget_2</WidgetId>
<Name>Auto</Name>
<Type>Text</Type>
<Options>size=1;fontSize=small;align=left</Options>
</Widget>
</Row>
<PageId>settings_page</PageId>
<Options>hideRowNames=0</Options>
</Page>
</Panel>
</Extensions>
import xapi from 'xapi';
/* Mute mics on macro start, unless a call is running */
xapi.Status.Call.get().then(callStatus => {
if(callStatus.length === 0){
muteMicrophones();
}
});
/* Mute mics when joining call */
xapi.Status.Call.on(callStatus => {
if(callStatus.Status === "Dialling"){
muteMicrophones();
}
});
/* Mute mics when leaving call */
xapi.Event.CallDisconnect.on(muteMicrophones);
function muteMicrophones(){
console.log("Muting microphones");
return xapi.Command.Audio.Microphones.Mute();
}
import xapi from 'xapi';
const endpointId = "612d8d9b4f0c6aaad9c67a26";
const relayAccessToken = "";
setTimeout(() =>
xapi.Command.HttpClient.Patch({
Url: "https://relay.bluejeans.com/api/endpoints/" + endpointId,
Header: [
"X-Access-Token: " + relayAccessToken,
"Content-Type: application/json"
]
}, "{}")
.then(() => {
console.log("Requested calendar push from Relay");
})
.catch(error => {
console.error("Failed to trigger calendar push from Relay", error);
})
, 30*1000);
import xapi from 'xapi';
const feedbackId = "shutdown_feedback_id";
xapi.Event.UserInterface.Extensions.Panel.Clicked.on(async event => {
if(event.PanelId === "shutdown_button"){
await xapi.Command.UserInterface.Message.Prompt.Display({
Title: "Shut down",
Text: "Are you sure you want to shut down this system?",
FeedbackId: feedbackId,
"Option.1": "Shut down",
"Option.2": "Cancel",
Duration: 40
});
}
});
xapi.Event.UserInterface.Message.Prompt.Response.on(async event => {
console.log(event);
if(event.FeedbackId === feedbackId && event.OptionId === "1") {
await xapi.Command.HttpClient.Put({
Url: "https://thor.aldaviva.com:8444/power?outletHostname=sx20.outlets.aldaviva.com&turnOn=false&delaySec=33" //it takes the SX20 about 28 seconds to shut down
}, "");
await xapi.Command.SystemUnit.Boot({ Action: "Shutdown" });
}
});
<Extensions>
<Version>1.7</Version>
<Panel>
<PanelId>shutdown_button</PanelId>
<Origin>local</Origin>
<Type>Home</Type>
<Icon>Power</Icon>
<Color>#FF503C</Color>
<Name>Shut down</Name>
<ActivityType>Custom</ActivityType>
</Panel>
</Extensions>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment