@vbet/vt-node-sdk
v1.0.1
Published
NodeJS SDK for VT Devices
Downloads
184
Readme
VT Node.js SDK
Table of Contents
Pre-requisite
Node.js v8.x or later.
On MacOS:
xcode&python 3.7. By default, Python is installed on macOS but make sure correct version(3.7+) is installed. Install Xcode from App store or download it from here.On Windows:
Visual C++ Build Tools&Python 3.7. You can install all of these by following any of the below mentioned steps.3.1. During Node.js installation By ticking the checkbox when prompted during Node.js installation for
Tools for Native modules, this installs bothVisual C++ Build Tools&Python 3.7. Note This is prompted only for Windows platform. For other platforms like Linux or MAC, C++ compilation tools has to be installed separately as mentioned in other steps.3.2. Both
Visual C++ Build Tools&Python 3.7can also be installed using commandnpm install --global --production --add-python-to-path windows-build-tools. To know more about this tool, see this link.. Note For executing this command throughWindows Command PromptorWindows PowerShell, they should be ran in Administrator mode.On Linux:
build-essentialpackage for C++ compilation &Python 3.7.4.1. Udev rules: To be able to communicate with VT devices with non-root privileges it is required to create a udev rule for VT devices. Place the udev rule in
/etc/udev/rules.d, and follow naming guidelines for udev files.Example: The file name should be something like
80-vt.ruleswhere the number before the dash indicates in what order the system reads the rules (e.g. if you had another rules file called70-someotherrule.rules, it would read that one first), the word after the dash is just an identifier of sorts (it could be something other than vt) and the extension must be.rules.The contents of the file are:
ATTRS{idVendor}=="340b", MODE="0666", GROUP="users"After creating the udev file (as root), reload the udev rules using:
sudo udevadm control --reloadReattach your VT device in order to get new permissions assigned.
All Platforms:
node-gyp. You can install this using commandnpm install -g node-gyp. To know more about this, see this linkFor Electron.JS: If you are using
asarpackaging then you may need tounpacksome of the resources used in this module. These resources are native library files i.esdk.dll,libsdk.dylib&libsdk.so, which is stored in abuild\Releasefolder. By default latest electron builder will automatically unpack, but if it does not work then you can provide below option to your build process. To know more, see this link
"build": {
"asarUnpack": ["node_modules/@vbet/vt-node-sdk"]
}- If you are using
webpackor similar module bundler, you may need to exclude the sdk from the bundle. In webpack, you say whichexternalsyou have in yourwebpack-config.js:
externals: {
"@vbet/vt-node-sdk": "commonjs @vbet/vt-node-sdk",
},Installation
npm install @vbet/vt-node-sdk
Examples
Simple button events example using javascript and plain promises
const { initSdk, CallAction } = require("@vbet/vt-node-sdk");
initSdk().then((vtSdk) => {
vtSdk.RegEvent("attach", (deviceImpl) => {
console.log("device attached:" + deviceImpl.deviceName);
deviceImpl.RegEvent("callAction", (action) => {
console.log("new input from device is received: ", action);
//........
//softphone do something to update the call state, once done inform device to sync state
switch (action) {
case CallAction.ACCEPT_CALL:
deviceImpl.setOffHookAsync(true);
break;
case CallAction.END_CALL:
deviceImpl.setOffHookAsync(false);
break;
case CallAction.MUTE_CALL:
deviceImpl.setMuteAsync(true);
break;
case CallAction.UNMUTE_CALL:
deviceImpl.setMuteAsync(false);
break;
case CallAction.HOLD_CALL:
deviceImpl.setHoldAsync(true);
break;
case CallAction.RESUME_CALL:
deviceImpl.setHoldAsync(false);
break;
case CallAction.REJECT:
deviceImpl.setRingAsync(false);
break;
}
});
deviceImpl.setRingAsync(true);
});
});Multiple device management with typescript and async/await
import { initSdk } from "@vbet/vt-node-sdk";
(async () => {
let vtSdk = await initSdk();
await vtSdk.firseScanForDeviceDoneAsync(); // Wait for all pre-attached devices to be scanned.
const deviceInstanceList = vtSdk.getAttachedDevices();
if (deviceInstanceList.length < 2) {
throw new Error("please make sure 2 vt devices are attached");
}
const firstDevice = deviceInstanceList[0];
await firstDevice.setRingAsync(true);
const secondDevice = deviceInstanceList[1];
await secondDevice.setRingAsync(true);
// Dispose vt sdk to enable node process to shutdown.
await vtSdk.disposeAsync();
})();