forked from CiscoSE/language-set
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage-set.js
145 lines (132 loc) · 4.56 KB
/
language-set.js
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
/**
* Language Settings for Cisco Video Codecs
* @module language-set
* @author Jaroslav Martan <[email protected]>
* @copyright Copyright (c) 2019 Cisco and/or its affiliates.
* @license Cisco Sample Code License, Version 1.1
*/
/**
* @license
* Copyright (c) 2019 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.
*/
const xapi = require('xapi');
// global variables
var g_call_active = false;
const DEFAULT_LANG = 0; // default language index
const LANGUAGES = ["English", "German", "ChineseSimplified"]; // see codec command "xconfiguration UserInterface Language: <TAB>"
/* as of now the available languages are:
Arabic Danish French Italian Portuguese Swedish
Catalan Dutch FrenchCanadian Japanese PortugueseBrazilian Turkish
ChineseSimplified English German Korean Russian
ChineseTraditional EnglishUK Hebrew Norwegian Spanish
Czech Finnish Hungarian Polish SpanishLatin
*/
const MAX_DUMP_DEPTH = 10;
/**
* dumpObj - get a string dump of an object
*
* @param {Object} obj an Object to dump
* @param {string} name name to assign to the object in dump
* @param {string} indent indentation string, gets added depending on the the depth
* @param {int} depth maximum depth of the dump
* @return {string} string dump
*/
function dumpObj(obj, name, indent, depth) {
if (depth > MAX_DUMP_DEPTH) {
return indent + name + ": <Maximum Depth Reached>\n";
}
if (typeof obj == "object") {
var child = null;
var output = indent + name + "";
indent += "-";
for (var item in obj) {
try {
child = obj[item];
} catch (e) {
child = "<Unable to Evaluate>";
}
if (typeof child == "object") {
output += dumpObj(child, item, indent, depth + 1);
} else {
output += indent + item + ": " + child + "\n";
}
}
return output;
} else {
return obj;
}
}
/**
* defaultWidgets - initialize widget values on Touch10
*
*/
function defaultWidgets() {
console.log("Setting widget defaults");
xapi.command("UserInterface Extensions Widget Action", {WidgetId: "language", Value: DEFAULT_LANG, Type: "released"});
}
/**
*
* setLanguage - set codec UI setLanguage
*
*/
function setLanguage(language) {
console.log("Set language to: "+language+" ("+LANGUAGES[language]+")");
xapi.config.set("UserInterface Language", LANGUAGES[language]);
}
// monitor call status
const callStatusFeedback = xapi.status.on('Call Status', (status) => {
console.log('Call status changed to: '+status);
switch (status) {
case 'Connected':
g_call_active = true;
console.log('call connected');
break;
case 'Idle':
g_call_active = false;
console.log('call disconnected');
defaultWidgets(); // reset language back to default
break;
default:
}
});
// De-register feedback
// callStatusFeedback();
// monitor touch10 events
const touchFeedback = xapi.event.on('UserInterface Extensions Widget', (status) => {
if (status.LayoutUpdated) {
console.log("Layout updated");
defaultWidgets();
} else {
console.log("Widget event: "+dumpObj(status, "", " "));
if (status.Action) {
var widgetId = status.Action.WidgetId;
var widgetValue = status.Action.Value;
var widgetValueInt = parseInt(widgetValue);
var actionType = status.Action.Type;
switch (widgetId) {
case "language":
if (actionType == "released") {
setLanguage(widgetValue);
}
break;
default:
console.log("Widget "+widgetId+" "+actionType+", value: "+widgetValue);
}
}
}
});
// system setup
defaultWidgets();