@yealink_dev/yealink-node-sdk-rcc
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Yealink Node.js SDK

Table of Contents

Pre-requisite

  1. Node.js v8.x or later.

  2. On MacOS: xcode & python 2.7. By default, Python is installed on macOS but make sure correct version(2.7.x) is installed. Install Xcode from App store or download it from here.

  3. On Windows: Visual C++ Build Tools & Python 2.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 both Visual C++ Build Tools & Python 2.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 2.7 can also be installed using command npm install --global --production --add-python-to-path windows-build-tools. To know more about this tool, see this link.. Note For executing this command through Windows Command Prompt or Windows PowerShell, they should be ran in Administrator mode.

  4. All Platforms: node-gyp. You can install this using command npm install -g node-gyp. To know more about this, see this link

  5. For Electron.JS: If you are using asar packaging then you may need to unpack some of the resources used in this module. These resources are native library files i.e libyealinkusbsdk.dll, libyealinkusbsdk.dylib & libyealinkusbsdk.so, which is stored in a build\Release folder. 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/@yealink_dev/yealink-node-sdk-rcc"]
}

Installation

npm install @yealink_dev/yealink-node-sdk-rcc

Debugging and Logging

Below environment variables are defined for logging and debugging purpose. User can change the values as per preference.

Environment Variable Value Description
YEALINKSDK_TRACE_LEVEL error, warning, info(default), verbose Log levels
YEALINKSDK_RESOURCE_PATH On Mac: ~/Library/Application Support/YealinkSdk/ On Windows: %appdata%/YealinkSdk This determine the system path where logs and device related files are written.

API Reference

API doc is in html format. See doc folder inside installed module node_modules\@yealink_dev\yealink-node-sdk\dist\doc and open index.html.

Examples

For all examples, user should first register the app from yealink teams to get appID. User should pass this appID to initSdk in order to initialize the yealink module:

Simple button events example using javascript and plain promises

const sdk = require("@yealink_dev/yealink-node-sdk-rcc");
sdk.initSdk('test_App_Id').then((ylSdk) => { // test_App_Id is appId here
    ylSdk.RegEvent('attach', (deviceImpl) => {
        console.log('press any key on yealink device ' + deviceImpl.deviceName);
        
        deviceImpl.RegEvent('btnPress', (btnType, btnValue) => {
          console.log('new input from device is received: ', sdk.DeviceBtnType[btnType], btnValue);
        });
    });    
});

Simple button events example using typescript and plain promises

import { initSdk, DeviceBtnType } from '@yealink_dev/yealink-node-sdk-rcc';
initSdk('test_App_Id').then((ylSdk) => { // test_App_Id is appId here
    ylSdk.RegEvent('attach', (deviceImpl) => {
        console.log('press any key on yealink device ' + deviceImpl.deviceName);

        deviceImpl.RegEvent('btnPress', (btnType, btnValue) => {
          console.log('new input from device is received: ', DeviceBtnType[btnType], btnValue);
        });
    });   
});

For more examples, see src/simpletest

Multiple device management with typescript and async/await

import { initSdk } from '@yealink_dev/yealink-node-sdk-rcc';

(async () => {
    let ylSdk = await initSdk('test_App_Id'); // test_App_Id is appId here

    await ylSdk.firseScanForDeviceDoneAsync(); // Wait for all pre-attached devices to be scanned.

    const deviceInstanceList = ylSdk.getAttachedDevices();
    if (deviceInstanceList.length<2) {
        throw new Error('please make sure 2 yealink devices are attached');
    }

    const firstDevice = deviceInstanceList[0];
    await firstDevice.ringAsync();

    const secondDevice = deviceInstanceList[1];
    await secondDevice.ringAsync();

    // Dispose yealink sdk to enable node process to shutdown.
    await ylSdk.disposeAsync();
})();

Setup VSCode

The project includes config files for debugging typescript and C++ source files in Visual Studio Code via the C++ extension, for both Windows. The configuration files work without any modification, provided that you set up your environment first, by installing the necessary tools and defining some environment variable.

To debug a C++ file, open a typescript file referencing the C++ file and start the debugger (Running the debugger on C++ files directly won't work). Make sure the "Run"-dropdown at the top of the debugging-sidebar is set to "Current TS File - native code only (<your operating system>)"

Below, the setup steps for Windows.

Windows

You can more or less follow the instruction in the VSCode C++ extension guide. Then, you need to make sure all project pre-requisites are installed correctly, and finally set the following environment variables:

Environment Variable Value Description
YEALINK_NODESDK_WIN_NODE_GYP_CACHE_PATH eg. %appdata%\Local\node-gyp\Cache\12.16.3\include\node Used by the C/C++ extension to resolve include paths
YEALINK_NODESDK_WIN_CPP_COMPILER_PATH eg. C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe Used by the C/C++ extension to infer the path to the C++ standard library header files

Readme

Keywords

Package Sidebar

Install

npm i @yealink_dev/yealink-node-sdk-rcc

Weekly Downloads

22

Version

1.0.1

License

MIT

Unpacked Size

14.1 MB

Total Files

170

Last publish

Collaborators

  • yealinkdevs