import { initSdk, YLSdkImpl } from "../main/app" import { DeviceBtnType, HidWorkState, ContactInfo, CallAction } from "../main/common-types"; import { DeviceImpl } from "../main/device"; async function sleep(ms: number) { return new Promise((resolve) => { setTimeout(() => { resolve(''); }, ms) }); } (async () => { try { let ylSdk = await initSdk("test_App_Id"); ylSdk.getSDKVersionAsync().then((result) => { console.log("current sdk version is:" + result); }).catch((error) => { console.log("get current error:" + error); }) // test softphone setting interface // Yealink application(Yealink USB Connect ) need to setup for this case let connectRet = await ylSdk.connectToYealinkApplicationAsync("bb0f6ade-b014-4f5b-90e4-15ced02cfcb2", "Test4NodeSdk"); console.log("conenct to yealink application ret: " + connectRet); if (connectRet) { try { await ylSdk.setSoftphoneReadyAsync(true); } catch (error) { console.log("set softphone ready exception:" + error); } } ylSdk.RegEvent('attach', async (deviceImpl: DeviceImpl) => { console.log("device attached, name:" + deviceImpl.deviceName); let contact:ContactInfo = { name: "electron-test", number: "7934" }; let cid: number = 1008; await deviceImpl.incomingCallAsync(cid, contact); await sleep(3000); await deviceImpl.answerCallAsync(cid); await sleep(3000); await deviceImpl.holdCallAsync(cid, contact); await sleep(3000); await deviceImpl.resumeCallAsync(cid); await sleep(3000); await deviceImpl.muteCallAsync(cid); await sleep(3000); await deviceImpl.terminateCallAsync(cid); deviceImpl.RegEvent('callAction', (cid: number, action: CallAction) => { console.log("call action, cid:", cid, "action:", action); }); }); ylSdk.RegEvent('detach', (deviceImpl: DeviceImpl) => { console.log("device detached, name:", deviceImpl.deviceName); ylSdk.disposeAsync(); }); } catch (error) { console.error("Got exception err " + error); } })();