-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleMonitorRole.js
More file actions
168 lines (136 loc) · 5.63 KB
/
ToggleMonitorRole.js
File metadata and controls
168 lines (136 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/********************************************************
Copyright (c) 2024 Cisco and/or its affiliates.
This software is licensed to you under the terms of the Cisco Sample
Code License, Version 1.1 (the "License"). You may obtain a copy of the
License at
https://developer.cisco.com/docs/licenses
All use of the material herein must be in accordance with the terms of
the License. All rights not expressly granted by the License are
reserved. Unless required by applicable law or agreed to separately in
writing, software distributed under the License is distributed on an "AS
IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied.
*********************************************************
* Author(s): Gerardo Chaves
* Solutions Engineer
* Cisco Systems
* gchaves@cisco.com
*
*
* Released: April 22, 2025
*
* Version 1.0.0
*
* Description:
* - Implements a custom panel button to toggle the monitor role of a specific monitor
*
* Tested Devices
* - Codec Pro
*/
import xapi from 'xapi';
// set the ID of the microphone to toggle below
const MonitorId = '2'
const button_color_red = '#D43B52'
const button_color_green = '#1D805F'
async function init() {
console.log({ Message: `Intializing Macro [${_main_macro_name()}...]` })
await buildUI()
await StartSubscriptions()
console.log({ Message: `Macro [${_main_macro_name()}] initialization Complete!` })
}
//Iterates over the Subscribe Object
async function StartSubscriptions() {
const subs = Object.getOwnPropertyNames(Subscribe);
subs.sort();
let mySubscriptions = [];
subs.forEach(element => {
Subscribe[element]();
mySubscriptions.push(element);
Subscribe[element] = function () {
console.warn({ Warn: `The [${element}] subscription is already active, unable to fire it again` });
};
});
console.log({ Message: 'Subscriptions Set', Details: { Total_Subs: subs.length, Active_Subs: mySubscriptions.join(', ') } });
};
//Define all Event/Status subscriptions needed for the macro
const Subscribe = {
PanelClicked: function () { xapi.Event.UserInterface.Extensions.Panel.Clicked.on(handle.Event.PanelClicked) }
}
const handle = {
Event: {
PanelClicked: function (event) {
console.log(event.PanelId)
if (event.PanelId == 'toggle_role_mode') {
ToggleMode();
}
}
}
}
function delay(ms) { return new Promise(resolve => { setTimeout(resolve, ms) }) }
async function ToggleMode() {
console.log({ Message: `Toggle Mode ${MonitorId}` })
//const current_value = await xapi.Config.Audio.Input.Microphone[1].Mode.get()
//console.log({ Message: `Current Mode ${MonitorId} current value: ${current_value}` })
const current_value = await xapi.Config.Video.Output.Connector[parseInt(MonitorId)].MonitorRole.get()
console.log({ Message: `Current Monitor ${MonitorId} mode current value: ${current_value}` })
let toggle_value = ''
let tog_color = ''
if (current_value == 'First') { toggle_value = 'Second' } else { toggle_value = 'First' };
if (current_value == 'First') {
toggle_value = 'Second';
tog_color = button_color_red;
}
else {
toggle_value = 'First';
tog_color = button_color_green;
};
console.log({ Message: `Setting Mode ${MonitorId} to : ${toggle_value}` })
//await xapi.Config.Audio.Input.Microphone[1].Mode.set(toggle_value);
await xapi.Config.Video.Output.Connector[parseInt(MonitorId)].MonitorRole.set(toggle_value);
await xapi.Command.UserInterface.Extensions.Panel.Update({ PanelId: 'toggle_role_mode', Name: `Monitor${MonitorId} turn ${current_value}`, Color: tog_color });
}
async function buildUI() {
console.log({ Message: `Building UserInterface...` })
// delete any previous action buttons
let customPanelsList = (await xapi.Command.UserInterface.Extensions.List({ ActivityType: 'Custom' }))?.Extensions.Panel;
if (customPanelsList != undefined) {
customPanelsList.forEach(async panel => {
if (panel.PanelId.substring(0, 16) == "toggle_role_mode") {
await xapi.Command.UserInterface.Extensions.Panel.Remove({ PanelId: panel.PanelId });
console.log('removed previous panel: ', panel.PanelId)
}
})
}
// get current state of mic to toggle
//const current_value = await xapi.Config.Audio.Input.Microphone[1].Mode.get()
const current_value = await xapi.Config.Video.Output.Connector[parseInt(MonitorId)].MonitorRole.get()
console.log({ Message: `Current Monitor ${MonitorId} Mode current value: ${current_value}` })
let tog_state = ''
let tog_color = ''
if (current_value == 'First') {
tog_state = 'First';
tog_color = button_color_green;
}
else {
tog_state = 'Second';
tog_color = button_color_red;
};
//build action buttons
let actionButton_xml = ``
actionButton_xml = `<Extensions>
<Version>1.10</Version>
<Panel>
<Order>1</Order>
<PanelId>$toggle_role_mode</PanelId>
<Origin>local</Origin>
<Location>HomeScreenAndCallControls</Location>
<Icon>Tv</Icon>
<Color>${tog_color}</Color>
<Name>Monitor${MonitorId} turn ${tog_state}</Name>
<ActivityType>Custom</ActivityType>
</Panel>
</Extensions>`
await xapi.Command.UserInterface.Extensions.Panel.Save({ PanelId: 'toggle_role_mode' }, actionButton_xml)
console.log({ Message: `UserInterface Built!` })
}
init()