Skip to content

Commit

Permalink
Big Refactor: use ES6 modules instead of CommonJS modules
Browse files Browse the repository at this point in the history
CommonJS is now deprecated for macros and will probably be removed completely later,
when Duktape is replaced with QuickJS

(There are also some dangling space cleanups in this commit that my editor
did automatically)
  • Loading branch information
tbjolset committed Mar 30, 2023
1 parent 1fbd8ba commit c9adc12
Show file tree
Hide file tree
Showing 41 changed files with 115 additions and 115 deletions.
2 changes: 1 addition & 1 deletion AppleTV Control/AppleTV.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

// https://kwikwai.com/knowledge-base/the-hdmi-cec-bus/
const CEC_PLAYBACK_DEVICE_LOGICAL_ADR = 4;
Expand Down
12 changes: 6 additions & 6 deletions Audio Call Dial Pad/audioCall.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

const KEYBOARD_TYPES = {
NUMERIC : 'Numeric'
Expand All @@ -24,10 +24,10 @@ function showDialPad(text){

xapi.command("UserInterface Message TextInput Display", {
InputType: KEYBOARD_TYPES.NUMERIC
, Placeholder: "Use keypad to enter number"
, Placeholder: "Use keypad to enter number"
, Title: "Audio Call"
, Text: text
, SubmitText: "Call"
, SubmitText: "Call"
, FeedbackId: DIALPAD_ID
}).catch((error) => { console.error(error); });
}
Expand All @@ -45,12 +45,12 @@ xapi.event.on('UserInterface Extensions Panel Clicked', (event) => {
xapi.event.on('UserInterface Message TextInput Response', (event) => {
switch(event.FeedbackId){
case DIALPAD_ID:

var regex =REGEXP_URLDIALER; //change this to whatever filter you want to check for validity
var match = regex.exec(event.Text);
var match = regex.exec(event.Text);
if (match !== null) {
var numbertodial = match[1];
numbertodial = DIALPREFIX_AUDIO_GATEWAY + numbertodial; // Here you can do some massaging of the number to dial, e.g. if it need prefixing or postfixing
numbertodial = DIALPREFIX_AUDIO_GATEWAY + numbertodial; // Here you can do some massaging of the number to dial, e.g. if it need prefixing or postfixing
xapi.command("dial", {Number: numbertodial, CallType: CALL_TYPES.AUDIO}).catch((error) => { console.error(error); });

}
Expand Down
2 changes: 1 addition & 1 deletion Audio Safe Guard/Audio Safe Guard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Limit the volume of a video system to a user definede level < 100.
* Show a message if this happens
*/
const xapi = require('xapi');
import xapi from 'xapi';

const MAX_VOLUME = 70;

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ You can define user settings in the manifest file, this will allow users to choo

It's important that the parameters you set in the macro file is similar to one of the examples below:
```
const xapi = require('xapi');
import xapi from 'xapi';
const myCustomNumber = 1234;
let myCustomString;
Expand Down
2 changes: 1 addition & 1 deletion Camera control with wide angle view/Camera Controls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

const CAMERAID_CAMERA_LEFT = 1;
const CAMERAID_CAMERA_RIGHT = 2;
Expand Down
2 changes: 1 addition & 1 deletion Child safe controls/Child safe call.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// child safe end call slider
const xapi = require('xapi');
import xapi from 'xapi';

function guiEvent(e) {
if (e.WidgetId === 'end-call' && e.Type === 'released' && e.Value > 225) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

/*
Expand Down
36 changes: 18 additions & 18 deletions Control Room Devices using USB Input Device/QWERTY_Dialling.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

const KEYBOARDLAYOUT = 'English'; // English || Norwegian

Expand Down Expand Up @@ -92,75 +92,75 @@ function copyHistoryToCurrentNumber(pointer){
currentNumber = '';
showCurrentNumber();
}

}

xapi.event.on('UserInterface InputDevice Key Action', (event) => {
if(event.Type == 'Pressed'){

if(event.Key == 'KEY_RIGHTSHIFT' || event.Key == 'KEY_LEFTSHIFT'){
KEY_SHIFT_IS_DEPRESSED = 1;
}
KEY_SHIFT_IS_DEPRESSED = 1;
}
else{
var key = getKeymappedCharacter(event.Key); //This is a bit of a hack as codec currently does not support meta keys. Thus, we need to keep state of metakeys in memory
// console.log('Translated key: ' + key);
if(key == 'KEY_BACK' || key == 'KEY_BACKSPACE' || key == 'KEY_DELETE'){
removeLastCharacter();
showCurrentNumber();
}
}
else if(key == 'KEY_UP'){
dialHistoryPointer++;
if(dialHistoryPointer >dialHistory.length) dialHistoryPointer = dialHistory.length;
copyHistoryToCurrentNumber(dialHistoryPointer);
}
}
else if(key == 'KEY_DOWN'){
dialHistoryPointer--;
if(dialHistoryPointer < 0) dialHistoryPointer = 0;
copyHistoryToCurrentNumber(dialHistoryPointer);
}
}
else if(key == 'KEY_ENTER'){
dialCurrentNumber();
}
}
else if(key == 'KEY_ESC'){
disconnectCall();
}
}
else if(key == 'KEY_DOT'){
addCharacterToCurrentNumber('.');
showCurrentNumber();
}
}
else if(key == 'KEY_DASH' || key == 'KEY_MINUS'){
addCharacterToCurrentNumber('-');
showCurrentNumber();
}
}
else if(key == 'KEY_UNDERSCORE'){
addCharacterToCurrentNumber('_');
showCurrentNumber();
}
}
else if(key == 'KEY_PLUS'){
addCharacterToCurrentNumber('+');
showCurrentNumber();
}
}
else if(key == 'KEY_AT'){ //This is a bit of a hack as codec currently does not support variations of keyboard layouts
addCharacterToCurrentNumber('@');
showCurrentNumber();
}
}
else{

let match = /^KEY_(\S){1}$/.exec(event.Key);
if(match){
addCharacterToCurrentNumber(match[1]);
showCurrentNumber();
}
else{
// xapi.command('UserInterface Message Alert Display', {'Title': 'Remote Control Warning', 'Text':'This button is not in use yet. To program it use the "Key: ' + event.Key + ' (or Code: ' + event.Code + ')', 'Duration': 2});
}
}
}
}
}
else{
if(event.Key == 'KEY_RIGHTSHIFT' || event.Key == 'KEY_LEFTSHIFT'){
KEY_SHIFT_IS_DEPRESSED = 0; //This is a bit of a hack as codec currently does not support meta keys. Thus, we need to keep state of metakeys in memory
}
}
}
});

8 changes: 4 additions & 4 deletions Control Room Devices using USB Input Device/RemoteControl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

const speedDialNumber = '[email protected]';
const cameraId = 3; // Set this to the camera id of camera you want to control. See "xStatus Cameras Camera"
Expand Down Expand Up @@ -48,7 +48,7 @@ xapi.event.on('UserInterface InputDevice Key Action', (event) => {
default:
xapi.command('UserInterface Message Alert Display', {'Title': 'Remote Control Warning', 'Text':'This button is not in use yet. To program it use the "Key: ' + event.Key + ' (or Code: ' + event.Code + ')', 'Duration': 2});
break;
}
}
}
else if(event.Type == 'Released'){
switch(event.Key){
Expand All @@ -66,8 +66,8 @@ xapi.event.on('UserInterface InputDevice Key Action', (event) => {
case 'KEY_FASTFORWARD':
xapi.command('Camera Ramp ', {CameraId: cameraId, 'Zoom':'Stop'});
break;
}
}
}

});

2 changes: 1 addition & 1 deletion Custom Config Panel/Room Setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

function showRoomSetupNotification(eventtext){
eventtext = eventtext.replace(/\"/g,"'"); // replace double quotes wiht single quotes for rendering purposes
Expand Down
2 changes: 1 addition & 1 deletion Customer Satisfaction Survey/customersatisfaction.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

xapi.event.on('CallDisconnect', (event) => {
if(event.Duration > 0){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
Expand Down
22 changes: 11 additions & 11 deletions Datadog Call Performance Monitoring/datadog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi'); // should be require('xapi')
import xapi from 'xapi';

const DD_TOKEN = 'REPLACE_ME'; // get a Client Token from your Datadog account here: https://app.datadoghq.com/organization-settings/client-tokens
const DD_URL = `https://browser-http-intake.logs.datadoghq.com/v1/input/${DD_TOKEN}`; // if your Datadog instance is in the EU region, use "datadog.eu" instead of "datadog.com"
Expand Down Expand Up @@ -72,7 +72,7 @@ function formatHealthResults(message, command){
message['Channel'][i]['Direction']
].join('_')
message[namespace] = Object.assign(
message['Channel'][i]['Netstat'],
message['Channel'][i]['Netstat'],
message['Channel'][i][message['Channel'][i]['Type']]
)
} else {
Expand Down Expand Up @@ -106,8 +106,8 @@ function sendHealthData(message){
// getting data

function getEachPeripheralData(perifData){
// the `xStatus Perhipherals ConnectedDevice [n]` commands must be run
// per peripheral device and with the id as an argument. we get the
// the `xStatus Perhipherals ConnectedDevice [n]` commands must be run
// per peripheral device and with the id as an argument. we get the
// peripheral id list first from `xCommand Peripherals List`.
// we schedule the sending of data in 1s increments so as to avoid running out of HttpClient handlers on the device
// TODO: confirm that the results capture all device data. Early results suggest that some devices might be getting missed.
Expand All @@ -123,7 +123,7 @@ function getEachPeripheralData(perifData){
} else {
setTimeout(
() => sendHealthData(formatHealthResults(
[{'command_response': 'none'}],
[{'command_response': 'none'}],
'peripherals connecteddevice'
)), (STATUS_LIST.length + 1)*1000
);
Expand All @@ -133,8 +133,8 @@ function getEachPeripheralData(perifData){
function checkStatus(statusList){
// we schedule the sending of data in 1s increments so as to avoid running out of HttpClient handlers on the device
for (let i = 0; i < statusList.length; i++) {
setTimeout(() => xapi.status.get(statusList[i]).then((stat) => {
sendHealthData(formatHealthResults(stat, statusList[i]));
setTimeout(() => xapi.status.get(statusList[i]).then((stat) => {
sendHealthData(formatHealthResults(stat, statusList[i]));
}), i*1000);
}
}
Expand Down Expand Up @@ -187,17 +187,17 @@ function scheduleStatusChecks(countdown_general, countdown_in_call, calls) {
setTimeout(() => runGeneralStatusCheck(), countdown_in_call > 0 ? 1 : (IN_CALL_STATUS_COMMAND_LIST.length + 1) * 1000);
countdown_general = GENERAL_CHECK_FREQUENCY;
}
setTimeout(() => xapi.status.get('call').then((res) => {
scheduleStatusChecks(countdown_general, countdown_in_call, res);
setTimeout(() => xapi.status.get('call').then((res) => {
scheduleStatusChecks(countdown_general, countdown_in_call, res);
}), CHECK_IF_CALL_FREQUENCY);
}


function monitorRoomKit() {
getSystemData();
console.log("got system data, now schedule status checks")
xapi.status.get('call').then((res) => {
scheduleStatusChecks(GENERAL_CHECK_FREQUENCY, 0, res);
xapi.status.get('call').then((res) => {
scheduleStatusChecks(GENERAL_CHECK_FREQUENCY, 0, res);
});
}

Expand Down
2 changes: 1 addition & 1 deletion Dial Favorite From Homescreen/onebuttontodial.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

const MYSPEED_DIAL_NUMBER = '[email protected]';

Expand Down
4 changes: 2 additions & 2 deletions End Of Meeting Countdown/BookingCountdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

let startTime = -1; // minutes
let timeLeft = 0; // seconds
Expand Down Expand Up @@ -61,7 +61,7 @@ function showTime() {
}

function tick() {

if (timeLeft < 0) timerFinished();
else{
timer = setTimeout(tick, 1000);
Expand Down
2 changes: 1 addition & 1 deletion HTTP Post - Report Issue/ReportIssue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';


const SERVICE_NOW_INSTANCE_URL = 'yourinstance.service-now.com'; // Specify a URL to a service like serviceNow etc.
Expand Down
6 changes: 3 additions & 3 deletions In-Room Control Debugger/In-Room Control Debugger.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const xapi = require('xapi');
import xapi from 'xapi';

// Generic Event handler for in-room control extensions

function showInRoomControlEvent(eventtext){
eventtext = eventtext.replace(/\"/g,"'"); // replace double quotes wiht single quotes for rendering purposes
console.log(eventtext);
xapi.command("UserInterface Message TextLine Display", {Text: eventtext, Duration: 3});

}

xapi.event.on('UserInterface Extensions Widget LayoutUpdated', (event) => {
Expand Down Expand Up @@ -46,7 +46,7 @@ xapi.event.on('UserInterface Extensions Widget Action', (event) => {
console.log(`myWidgetId was Clicked`);
xapi.command("dial", {number: 'somenumber@mydomain.com'});
}
}
}
*/

});
10 changes: 5 additions & 5 deletions Language Selector/language-selector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi');
import xapi from 'xapi';

const LANGUAGE_DEFAULT = 'English';
const LANGUAGE_REVERT_TO_DEFAULT_IN_STANDBY = 1;
Expand All @@ -7,11 +7,11 @@ function initUILanguage(language) {
var languageWidgetId = language.toLowerCase();
console.log('Setting lang id to ' + languageWidgetId);
xapi.command('UserInterface Extensions Widget SetValue', {'WidgetId': 'lang', 'Value': languageWidgetId}).catch((error) => { console.error(error); }); // This expects an in-room control group-widget named 'lang' and the selected language in the list named lowercase name of language

}

function setLanguage(language) {
let newlanguage = null;
let newlanguage = null;
console.log('setlang:' + language)
switch(language) {
case 'lang_arabic':
Expand Down Expand Up @@ -96,10 +96,10 @@ function setLanguage(language) {
default:
newlanguage = LANGUAGE_DEFAULT;
}

xapi.config.set('UserInterface Language', newlanguage).catch((error) => { console.error(error); });
xapi.command('UserInterface Extensions Panel Close').catch((error) => { console.error(error); }); //This command was added to CE 9.5. This line will fail if running on older firmware

}

function onGui(event) {
Expand Down
2 changes: 1 addition & 1 deletion Library - Send Webex Message/webex.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ function sendMessage(token, toPersonEmail, roomId, markdown) {
return xapi.Command.HttpClient.Post({ Header: headers, Url: webexMsgUrl }, JSON.stringify(body));
}

module.exports = sendMessage;
export default sendMessage;
4 changes: 2 additions & 2 deletions Measure Climate/measureclimate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const xapi = require('xapi');
const storage = require('./storage-csv');
import xapi from 'xapi';
import storage from './storage-csv';

// how often to sample data
const SampleMinutes = 10;
Expand Down
4 changes: 2 additions & 2 deletions Philips Hue/examples/incall-indicator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const xapi = require('xapi');
const Hue = require('../hue-lib');
import xapi from 'xapi';
import Hue from './hue-lib';

const hue = new Hue();

Expand Down
Loading

0 comments on commit c9adc12

Please sign in to comment.