import { isNodeJs } from './help'; import { YLSdkInterface } from './sdkinterface'; import { FirmwareEventStatus, FirmwareEventType, FirmwareInfo } from './fw-types' import { BtPairedDeviceList } from './bt-types' import { CameraDirectionCmd, CameraSmartTracking, CameraSmartTrackingOpt, CameraZoomCmd } from './camera-types' import { AudioModes, BusylightStatus, ContactInfo, ContactInfoList, DateTime, DeviceConnectionType, DeviceFeature, DeviceInfo, EqualizerMode, ErrorStatus, DeviceBtnType, HidWorkState, LogEventType, ReturnCode, UploadEventStatus, WizardModes, CallAction } from './common-types' import { DeviceSettings } from './settings-type' import util = require('util') import { RemoteMmiActionOutput, RemoteMmiInput, RemoteMmiOutput, RemoteMmiPriority, RemoteMmiSequence, RemoteMmiType } from './remotemmi-types'; import { NativeLogVerbose } from './logwrapper'; export namespace DeviceTypeCallbacks { export type btnPress = (btnType: DeviceBtnType, value: boolean) => void; export type busyLightChange = (status: boolean) => void; export type downloadFirmwareProgress = (type: FirmwareEventType, status: FirmwareEventStatus, dwnldStatusInPrcntg: number) => void; export type onBTParingListChange = (pairedListInfo: BtPairedDeviceList) => void; export type onGNPBtnEvent = (btnEvents: Array<{ buttonTypeKey: number, buttonTypeValue: string, buttonEventType: Array<{ key: number, value: string }> }>) => void; export type onDevLogEvent = (data: LogEventType, result: boolean) => void; export type onBatteryStatusUpdate = (levelInPercent: number, isCharging: boolean, isBatteryLow: boolean) => void; export type onRemoteMmiEvent = (type: RemoteMmiType, input: RemoteMmiInput) => void; export type onUploadProgress = (status: UploadEventStatus, levelInPercent: number) => void; //export type onDectInfoEvent = (dectInfo: DectInfo) => void; export type callAction = (cid: number, action: CallAction) => void; export type onDialNumebrChange = (cid: number, dialnumber: string) => void; } export type DeviceImplEvents = 'btnPress' | 'busyLightChange' | 'downloadFirmwareProgress' | 'onBTParingListChange' | 'onGNPBtnEvent' | 'onDevLogEvent' | 'onBatteryStatusUpdate' | 'onRemoteMmiEvent' | 'onUploadProgress' | 'onDectInfoEvent' | 'callAction' | 'onDialNumebrChange'; export const DeviceEventsList: DeviceImplEvents[] = ['btnPress', 'busyLightChange', 'downloadFirmwareProgress', 'onBTParingListChange', 'onGNPBtnEvent', 'onDevLogEvent', 'onBatteryStatusUpdate', 'onRemoteMmiEvent', 'onUploadProgress', 'onDectInfoEvent', 'callAction', 'onDialNumebrChange']; // Browser friendly type-only import: type _EventEmitter = import('events').EventEmitter; let ylSdkInterface: YLSdkInterface; let events: any; if (isNodeJs()) { // These statements should be executed under nodejs only to avoid browserfy problems: let bindings = require('bindings'); ylSdkInterface = bindings('sdkinterface'); events = require('events'); } export class DeviceImpl implements DeviceInfo { readonly _eventEmitter: _EventEmitter; constructor(deviceInfo: DeviceInfo) { this._eventEmitter = new events.EventEmitter(); this.deviceId = deviceInfo.deviceId; this.deviceName = deviceInfo.deviceName; this.productId = deviceInfo.productId; this.serialNumber = deviceInfo.serialNumber; this.vendorId = deviceInfo.vendorId; this.variant = deviceInfo.variant; this.deviceconnection = deviceInfo.deviceconnection; this.errStatus = deviceInfo.errStatus; this.isDongle = deviceInfo.isDongle; this.isInFirmwareUpdateMode = deviceInfo.isInFirmwareUpdateMode; //this.attached_time_ms = attached_time_ms; //this.detached_time_ms = undefined; this.devicePath = ""; this.parentInstanceId = ""; this.dongleName = ""; this.connectionId = 0; this.parentDeviceId = 0; this.isInUpgradeProgress = false; } readonly deviceId: number; readonly productId: number; readonly vendorId: number; readonly deviceName: string; readonly errStatus: ErrorStatus; readonly isDongle: boolean; readonly variant: string; readonly serialNumber: string; readonly isInFirmwareUpdateMode: boolean; readonly deviceconnection: DeviceConnectionType; readonly devicePath: string; readonly parentInstanceId: string; readonly dongleName: string; readonly connectionId: number; readonly parentDeviceId: number; isInUpgradeProgress: boolean; getDeviceInfo(): DeviceInfo{ return { deviceId: this.deviceId, productId: this.productId, vendorId: this.vendorId, deviceName: this.deviceName, devicePath: this.devicePath, parentInstanceId: this.parentInstanceId, errStatus: this.errStatus, isDongle: this.isDongle, dongleName: this.dongleName, variant: this.variant, serialNumber: this.serialNumber, isInFirmwareUpdateMode: this.isInFirmwareUpdateMode, deviceconnection: this.deviceconnection, connectionId: this.connectionId, parentDeviceId: this.parentDeviceId}; } getSupportedFeaturesAsync(): Promise> { return util.promisify(ylSdkInterface.GetSupportedFeatures)(this.deviceId).then((result) => { console.log(this.getSupportedFeaturesAsync.name, "returned"); return result; }); } isFeatureSupportedAsync(feature: DeviceFeature): Promise { return util.promisify(ylSdkInterface.IsFeatureSupported)(this.deviceId, feature).then((result) => { return result; }); } isRingSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsRingSupported)(this.deviceId).then((result) => { return result; }); } setRingAsync(enable: boolean): Promise { return util.promisify(ylSdkInterface.SetRing)(this.deviceId, enable).then(() => { console.log(this.setRingAsync.name, "returned"); }); } isOffHookSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsOffHookSupported)(this.deviceId).then((result) => { return result; }); } setOffHookAsync(enable: boolean): Promise { return util.promisify(ylSdkInterface.SetOffHook)(this.deviceId, enable).then(() => { console.log(this.setOffHookAsync.name, "returned"); }); } isMuteSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsMuteSupported)(this.deviceId).then((result) => { return result; }); } setMuteAsync(enable: boolean): Promise { return util.promisify(ylSdkInterface.SetMute)(this.deviceId, enable).then(() => { console.log(this.setMuteAsync.name, "returned"); }); } isHoldSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsHoldSupported)(this.deviceId).then((result) => { return result; }); } setHoldAsync(enable: boolean): Promise { return util.promisify(ylSdkInterface.SetHold)(this.deviceId, enable).then(() => { console.log(this.setHoldAsync.name, "returned"); }); } isOnlineSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsOnlineSupported)(this.deviceId).then((result) => { console.log(this.isOnlineSupportedAsync.name, "returned"); return result; }); } setOnline(enable: boolean): Promise { return util.promisify(ylSdkInterface.SetOnline)(this.deviceId, enable).then(() => { console.log(this.setOnline.name, "returned"); }); } setHidWorkingStateAsync(hidWorkState: HidWorkState): Promise { return util.promisify(ylSdkInterface.SetHidWorkingState)(this.deviceId, hidWorkState).then(() => { console.log(this.setHidWorkingStateAsync.name, "returned"); }); } getHidWorkingStateAsync(): Promise { return util.promisify(ylSdkInterface.GetHidWorkingState)(this.deviceId).then((result) => { console.log(this.getHidWorkingStateAsync.name, "returned"); return result; }); } IsYlHidStdHidSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsYlHidStdHidSupported)(this.deviceId).then((result) => { console.log(this.IsYlHidStdHidSupportedAsync.name, "returned"); return result; }); } setStdHidEventsFromYealinkDevicesAsync(enable: boolean): Promise { return util.promisify(ylSdkInterface.SetStdHidEventsFromYealinkDevices)(enable).then(() => { console.log(this.setStdHidEventsFromYealinkDevicesAsync.name, "returned"); }); } isStdHidEventsFromYealinkDevicesAsync(): Promise { return util.promisify(ylSdkInterface.IsStdHidEventsFromYealinkDevices)().then((result) => { console.log(this.isStdHidEventsFromYealinkDevicesAsync.name, "returned"); return result; }); } enterDialCallAsync(cid: number): Promise { return util.promisify(ylSdkInterface.EnterDialCall)(this.deviceId, cid).then(() => { console.log(this.enterDialCallAsync.name, "returned"); }); } ringBackCallAsync(cid: number): Promise { return util.promisify(ylSdkInterface.RingBackCall)(this.deviceId, cid).then(() => { console.log(this.ringBackCallAsync.name, "returned"); }); } incomingCallAsync(cid: number, contact: ContactInfo): Promise { return util.promisify(ylSdkInterface.IncomingCall)(this.deviceId, cid, contact).then(() => { console.log(this.incomingCallAsync.name, "returned"); }); } outgoingCallAsync(cid: number, contact: ContactInfo): Promise { return util.promisify(ylSdkInterface.OutgoingCall)(this.deviceId, cid, contact).then(() => { console.log(this.outgoingCallAsync.name, "returned"); }); } terminateCallAsync(cid: number): Promise { return util.promisify(ylSdkInterface.TerminateCall)(this.deviceId, cid).then(() => { console.log(this.terminateCallAsync.name, "returned"); }); } answerCallAsync(cid: number): Promise { return util.promisify(ylSdkInterface.AnswerCall)(this.deviceId, cid).then(() => { console.log(this.answerCallAsync.name, "returned"); }); } holdCallAsync(cid: number, contact: ContactInfo): Promise { return util.promisify(ylSdkInterface.HoldCall)(this.deviceId, cid, contact).then(() => { console.log(this.holdCallAsync.name, "returned"); }); } resumeCallAsync(cid: number): Promise { return util.promisify(ylSdkInterface.ResumeCall)(this.deviceId, cid).then(() => { console.log(this.resumeCallAsync.name, "returned"); }); } muteCallAsync(cid: number): Promise { return util.promisify(ylSdkInterface.MuteCall)(this.deviceId, cid).then(() => { console.log(this.muteCallAsync.name, "returned"); }); } unmuteCallAsync(cid: number): Promise { return util.promisify(ylSdkInterface.UnmuteCall)(this.deviceId, cid).then(() => { console.log(this.unmuteCallAsync.name, "returned"); }); } updateContactAsync(cid: number, contact: ContactInfo): Promise { return util.promisify(ylSdkInterface.UpdateContact)(this.deviceId, cid, contact).then(() => { console.log(this.updateContactAsync.name, "returned"); }); } isSetDateTimeSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsSetDateTimeSupported)(this.deviceId).then((result) => { console.log(this.isSetDateTimeSupportedAsync.name, "returned"); return result; }); } setDateTimeAsync(dataTime: DateTime): Promise { return util.promisify(ylSdkInterface.SetDateTime)(this.deviceId, dataTime).then(() => { console.log(this.setDateTimeAsync.name, "returned"); }); } isUploadRingtoneSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsUploadRingtoneSupported)(this.deviceId).then((result) => { console.log(this.isUploadRingtoneSupportedAsync.name, "returned"); return result; }); } uploadRingtoneAsync(path: string): Promise { return util.promisify(ylSdkInterface.UploadRingtone)(this.deviceId, path).then(() => { console.log(this.uploadRingtoneAsync.name, "returned"); }); } playRingtoneAsync(type: number): Promise { return util.promisify(ylSdkInterface.PlayRingtone)(this.deviceId, type).then(() => { console.log(this.playRingtoneAsync.name, "returned"); }); } isBusylightSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsBusylightSupported)(this.deviceId).then((result) => { console.log(this.isBusylightSupportedAsync.name, "returned"); return result; }); } setBusylightStatusAsync(busylightStatus: BusylightStatus): Promise { return util.promisify(ylSdkInterface.SetBusylightStatus)(this.deviceId, busylightStatus).then(() => { console.log(this.setBusylightStatusAsync.name, "returned"); }); } getBusylightStatusAsync(): Promise { return util.promisify(ylSdkInterface.GetBusylightStatus)(this.deviceId).then((result) => { console.log(this.getBusylightStatusAsync.name, "returned"); return result; }); // return util.promisify(ylSdkInterface.GetSupportedFeatures)(this.deviceId).then((result) => { // console.log(this.getSupportedFeaturesAsync.name, "returned"); // return BusylightStatus.BUSYLIGHT_RING; // }); } isEqualizerSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsEqualizerSupported)(this.deviceId).then((result) => { console.log(this.isEqualizerSupportedAsync.name, "returned"); return result; }); } getEqualizerModeAsync(): Promise { return util.promisify(ylSdkInterface.GetEqualizerMode)(this.deviceId).then((result) => { console.log(this.getEqualizerModeAsync.name, "returned"); return result; }); } setEqualizerModeAsync(mode: EqualizerMode): Promise { return util.promisify(ylSdkInterface.SetEqualizerMode)(this.deviceId, mode).then(() => { console.log(this.setEqualizerModeAsync.name, "returned"); }); } isWizardModeSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsWizardModeSupported)(this.deviceId).then((result) => { console.log(this.isWizardModeSupportedAsync.name, "returned"); return result; }); } setWizardModeAsync(mode: WizardModes): Promise { return util.promisify(ylSdkInterface.SetWizardMode)(this.deviceId, mode).then(() => { console.log(this.setWizardModeAsync.name, "returned"); }); } getWizardModeAsync(): Promise { return util.promisify(ylSdkInterface.GetWizardMode)(this.deviceId).then((result) => { console.log(this.getWizardModeAsync.name, "returned"); return result; }); } factoryResetAsync(): Promise { return util.promisify(ylSdkInterface.FactoryReset)(this.deviceId).then(() => { console.log(this.factoryResetAsync.name, "returned"); }); } rebootDeviceAsync(): Promise { return util.promisify(ylSdkInterface.RebootDevice)(this.deviceId).then(() => { console.log(this.rebootDeviceAsync.name, "returned"); }); } startExportAudioAsync(path: string): Promise { return util.promisify(ylSdkInterface.StartExportAudio)(this.deviceId, path).then(() => { console.log(this.startExportAudioAsync.name, "returned"); }); } stopExportAudioAsync(): Promise { return util.promisify(ylSdkInterface.StopExportAudio)(this.deviceId).then(() => { console.log(this.stopExportAudioAsync.name, "returned"); }); } isAudioModeSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsAudioModeSupported)(this.deviceId).then((result) => { console.log(this.isAudioModeSupportedAsync.name, "returned"); return result; }); } changeAudioModeAsync(mode: AudioModes): Promise { return util.promisify(ylSdkInterface.ChangeAudioMode)(this.deviceId, mode).then(() => { console.log(this.changeAudioModeAsync.name, "returned"); }); } hasDectInDockedAsync(): Promise { return util.promisify(ylSdkInterface.HasDectInDocked)(this.deviceId).then((result) => { console.log(this.hasDectInDockedAsync.name, "returned"); return result; }); } getRegionVersionAsync(): Promise { return util.promisify(ylSdkInterface.GetRegionVersion)(this.deviceId).then((result) => { console.log(this.getRegionVersionAsync.name, "returned"); return result; }) } setCurrentTalkContactAsync(contact: ContactInfo): Promise { return util.promisify(ylSdkInterface.SetCurrentTalkContact)(this.deviceId, contact).then(() => { console.log(this.setCurrentTalkContactAsync.name, "returned"); }); } setContactInfoListAsync(contactList: ContactInfoList): Promise { return util.promisify(ylSdkInterface.SetContactInfoList)(this.deviceId, contactList).then(() => { console.log(this.setContactInfoListAsync.name, "returned"); }); } getBatteryStatusAsync(): Promise<{ levelInPercent?: number, isCharging?: boolean, isBatteryLow?: boolean }> { return util.promisify(ylSdkInterface.GetBatteryStatus)(this.deviceId).then((result) => { console.log(this.getRegionVersionAsync.name, "returned"); return result; }) } getDeviceImagePathAsync(): Promise { return util.promisify(ylSdkInterface.GetDeviceImagePath)(this.deviceId).then((result) => { console.log(this.getDeviceImagePathAsync.name, "returned"); return result; }) } exportDevLogAsync(path: string): Promise { return util.promisify(ylSdkInterface.ExportDevLog)(this.deviceId, path).then(() => { console.log(this.exportDevLogAsync.name, "returned"); }); } uploadDevLogToCloudAsync(): Promise { return util.promisify(ylSdkInterface.UploadDevLogToCloud)(this.deviceId).then(() => { console.log(this.uploadDevLogToCloudAsync.name, "returned"); }); } // GetESN // settings /** * Gets the complete settings details (all groups and its settings) for a device. * @returns {Promise, YealinkError>} - Resolve setting `array` if successful otherwise Reject with `error`. */ getSettingsAsync(): Promise { return util.promisify(ylSdkInterface.GetSettings)(this.deviceId).then((result) => { return result; }); } /** * Gets the unique setting identified by a GUID of a device. * @param {string} guid - the unique setting identifier. * @returns {Promise, YealinkError>} - Resolve setting `array` if successful otherwise Reject with `error`. */ getSettingAsync(guid: string): Promise { return util.promisify(ylSdkInterface.GetSetting)(this.deviceId, guid).then((result) => { return result; }); } /** * Sets all the settings( including all groups and its settings) for a device. * @param {Array} settings - pass only changed settings in an array * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`, `reboot` etc. * * Nb. Currently this method returns an error with code=24 if rebooting as bi-result. * TODO: Change signature to return reboot information normally instead. */ setSettingsAsync(settings: DeviceSettings): Promise { return util.promisify(ylSdkInterface.SetSettings)(this.deviceId, settings).then(() => { }); } // Bluetooth /** * Connect/Reconnect Bluetooth device to the Yealink Bluetooth adapter. Ensure the Bluetooth device is switched on and within range. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ connectBTDeviceAsync(): Promise { return util.promisify(ylSdkInterface.ConnectBTDevice)(this.deviceId).then(() => { }); } /** * Get name of connected BT device with BT Adapter(Async). * @returns {Promise} - Resolve deviceName `string` if successful otherwise Reject with `error`. */ getConnectedBTDeviceNameAsync(): Promise { return util.promisify(ylSdkInterface.GetConnectedBTDeviceName)(this.deviceId).then((result) => { return result; }); } /** * Connect a new device. * @param {string} deviceName - name of device to be connected. * @param {string} deviceBTAddr - BTAddress of device to be connected. * @param {boolean} isConnected - current status of device to be connected. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ connectNewDeviceAsync(deviceName: string, deviceBTAddr: string, isConnected: boolean): Promise { return util.promisify(ylSdkInterface.ConnectNewDevice)(this.deviceId, deviceName, deviceBTAddr, isConnected).then(() => { }); } /** * Connect a device which was already paired. * @param {string} deviceName - name of device to be connected. * @param {string} deviceBTAddr - BTAddress of device to be connected. * @param {boolean} isConnected - current status of device to be connected. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. * - **Note** : After device connection, getPairingListAsync api has to be called to get updated connection status. */ connectPairedDeviceAsync(deviceName: string, deviceBTAddr: string, isConnected: boolean): Promise { return util.promisify(ylSdkInterface.ConnectPairedDevice)(this.deviceId, deviceName, deviceBTAddr, isConnected).then(() => { }); } /** * Disconnect Bluetooth device from Bluetooth adapter. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ disconnectBTDeviceAsync(): Promise { return util.promisify(ylSdkInterface.DisconnectBTDevice)(this.deviceId).then(() => { }); } /** * Disconnect a paired device. * @param {string} deviceName - name of device to be disconnected. * @param {string} deviceBTAddr - BTAddress of device to be disconnected. * @param {boolean} isConnected - current status of device to be disconnected. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. * - **Note** : After device disconnection, getPairingListAsync api has to be called to get updated connection status. */ disconnectPairedDeviceAsync(deviceName: string, deviceBTAddr: string, isConnected: boolean): Promise { return util.promisify(ylSdkInterface.DisconnectPairedDevice)(this.deviceId, deviceName, deviceBTAddr, isConnected).then(() => { }); } /** * Get Auto pairing mode enable or disable. * @returns {Promise} - Resolve `boolean` if successful otherwise Reject with `error`. * - `true` if auto pairing mode is enabled, `false` otherwise. */ getAutoConnectingAsync(): Promise { return util.promisify(ylSdkInterface.GetAutoConnecting)(this.deviceId).then((result) => { return result; }); } /** * When Bluetooth adapter is plugged into the PC it will attempt to connect with the last connected Bluetooth device. If it cannot connect, it will automatically search for new Bluetooth devices to connect to. * @param {boolean} value - enable or disable for auto pairing. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ setAutoConnectingAsync(value: boolean): Promise { return util.promisify(ylSdkInterface.SetAutoConnecting)(this.deviceId, value).then(() => { }); } /** * Checks if pairing list is supported by the device. * @returns {Promise} - Resolve `boolean` if successful otherwise Reject with `error`. * - Returns `true` if pairing list is supported, false if device does not support pairing list. */ isPairingListSupportedAsync(): Promise { return util.promisify(ylSdkInterface.IsPairingListSupported)(this.deviceId).then((result) => { return result; }); } /** * Gets the list of devices which are paired previously. * @returns { Promise, YealinkError>} - Resolve pairList `array` if successful otherwise Reject with `error`. */ getPairingListAsync(): Promise> { return util.promisify(ylSdkInterface.GetPairingList)(this.deviceId).then((result) => { return result; }); } /** * Clear list of paired BT devices from BT adapter. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ clearPairingListAsync(): Promise { return util.promisify(ylSdkInterface.ClearPairingList)(this.deviceId).then(() => { }); } /** * Set the bluetooth device in pairing mode. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ setBTDiscoverableAsync(): Promise { return util.promisify(ylSdkInterface.SetBTDiscoverable)(this.deviceId).then(() => { }); } /** * Search for available Bluetooth devices which are switched on, within range and ready to connect. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ scanNewDevicesAsync(): Promise { return util.promisify(ylSdkInterface.ScanNewDevices)(this.deviceId).then(() => { }); } /** * Stop search for available Bluetooth devices. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ stopBTScanAsync(): Promise { return util.promisify(ylSdkInterface.StopBTScan)(this.deviceId).then(() => { }); } /** * Clear a device from paired device list. * @param {string} deviceName - name of device to be connected. * @param {string} deviceBTAddr - BTAddress of device to be connected. * @param {boolean} isConnected - current status of device to be connected. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ clearPairedDeviceAsync(deviceName: string, deviceBTAddr: string, isConnected: boolean): Promise { return util.promisify(ylSdkInterface.ClearPairedDevice)(this.deviceId, deviceName, deviceBTAddr, isConnected).then(() => { }); } /** * Gets the list of new devices which are available to pair & connect. * @returns { Promise, YealinkError>} - Resolve pairList `array` if successful otherwise Reject with `error`. * - **Note**: `isConnected`, flag in Pairing List Object, will always be false as device does not give connection status for the found device. */ getSearchDeviceListAsync(): Promise> { return util.promisify(ylSdkInterface.GetSearchDeviceList)(this.deviceId).then((result) => { return result; }); } // firmware update /** * Get firmware version of the device. * @returns {Promise} - Resolve version `string` if successful otherwise Reject with `error`. */ getFirmwareVersionAsync(): Promise { return util.promisify(ylSdkInterface.GetFirmwareVersion)(this.deviceId).then((result) => { return result; }); } /** * Gets details of the latest firmware present in cloud. * @returns {Promise} - Resolve firminfo `object` if successful otherwise Reject with `error`. */ getLatestFirmwareInformationAsync(): Promise { return util.promisify(ylSdkInterface.GetLatestFirmwareInformation)(this.deviceId).then((result) => { return result; }); } /** * Downloads the specified firmware version file. * @param {string} version - Version for which file download needs to be initiated. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ downloadFirmwareAsync(version: string): Promise { return util.promisify(ylSdkInterface.DownloadFirmware)(this.deviceId, version).then(() => { }); } /** * Upgrades / Updates the firmware for the target device with specified version. * @param {string} fwPath - firmware file path. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ updateFirmwareAsync(fwPath: string): Promise { return util.promisify(ylSdkInterface.UpdateFirmware)(this.deviceId, fwPath).then((result) => { if (ReturnCode.Return_Ok == result || ReturnCode.Return_Async == result) { this.isInUpgradeProgress = true; } }); } /** * Get the file path of the downloaded file. * @param {string} version - Version for which the path is required. * @returns {Promise} - Resolve firmware file path `string` if successful otherwise Reject with `error`. * - **Note**: Call `downloadFirmwareAsync` first to ensure that data is current */ getFirmwareFilePathAsync(version: string): Promise { return util.promisify(ylSdkInterface.GetFirmwareFilePath)(this.deviceId, version).then((result) => { return result; }); } /** * Cancels the firmware download (Async). * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ cancelFirmwareDownloadAsync(): Promise { return util.promisify(ylSdkInterface.CancelFirmwareDownload)(this.deviceId).then(() => { }); } /** * Check if Firmware update available for device. * @returns {Promise} - Resolve `boolean` if successful otherwise Reject with `error`. * - `true` - if a new firmware update is available (existing firmware not up to date), `false` otherwise (existing firmware up to date). */ checkForFirmwareUpdateAsync(): Promise { return util.promisify(ylSdkInterface.CheckForFirmwareUpdate)(this.deviceId).then((result) => { return result; }); } // remotemmi /** * Gets the focus of the remote MMI specified. Once a remote MMI has * focus, the normal functionality of the MMI (button/LED) is suppressed until * #releaseRemoteMmiFocusAsync is called. * If only the LED output MMI functionality is required, action can be * specified as MMI_ACTION_NONE. * @param {enumRemoteMmiType} type Type of remote MMI to get focus of. * @param {enumRemoteMmiInput} input Action to get focus of, acts as a filter/mask for the * actions on the RemoteMmiCallback callback * @param {enumRemoteMmiPriority} priority Priority of focus. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ getRemoteMmiFocusAsync(type: RemoteMmiType, input: RemoteMmiInput, priority: RemoteMmiPriority): Promise { return util.promisify(ylSdkInterface.GetRemoteMmiFocus)(this.deviceId, type, input, priority).then((result) => { return result; }); } /** * Releases the focus of the remote MMI specified. Note that focus on * all actions are removed. * @param {enumRemoteMmiType} type Type of remote MMI to release focus of. * @returns {Promise} - Resolve `void` if successful otherwise Reject with `error`. */ releaseRemoteMmiFocusAsync(type: RemoteMmiType): Promise { return util.promisify(ylSdkInterface.ReleaseRemoteMmiFocus)(this.deviceId, type).then((result) => { return result; }); } /** * Gets the status of the remote MMI focus. * @param {enumRemoteMmiType} type Type of remote MMI to get focus status of. * @returns {Promise} returns true if in focus, false if not. */ isRemoteMmiInFocusaAsync(type: RemoteMmiType): Promise { return util.promisify(ylSdkInterface.IsRemoteMmiInFocus)(this.deviceId, type).then((result) => { return result; }); } /** * Sets an output action on the remote MMI. Note that * getRemoteMmiFocusAsync must be called once for the enumRemoteMmiType in * question prior to setting the output action, else YealinkError is * returned. * @param {enumRemoteMmiType} type type Type of remote MMI to set action of. * @param {RemoteMmiActionOutput} outputAction Output LED action to set. * @returns {Promise} returns true if in focus, false if not. */ setRemoteMmiActionAsync(type: RemoteMmiType, actionOutput: RemoteMmiActionOutput): Promise { return util.promisify(ylSdkInterface.SetRemoteMmiAction)(this.deviceId, type, actionOutput).then((result) => { return result; }); } getRemoteMmiTypesAsync(): Promise> { return util.promisify(ylSdkInterface.GetRemoteMmiTypes)(this.deviceId).then((result) => { return result; }); } // camera cameraIsReadyAsync(): Promise { NativeLogVerbose(this.cameraIsReadyAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraIsReady)(this.deviceId).then((result) => { NativeLogVerbose(this.cameraIsReadyAsync.name, `call returned`); return result; }) } cameraIsInIdleAsync(): Promise { NativeLogVerbose(this.cameraIsInIdleAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraIsInIdle)(this.deviceId).then((result) => { NativeLogVerbose(this.cameraIsInIdleAsync.name, `call returned`); return result; }) } cameraDirectionCtrlAsync(cmd: CameraDirectionCmd): Promise { NativeLogVerbose(this.cameraDirectionCtrlAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraDirectionCtrl)(this.deviceId, cmd).then(() => { NativeLogVerbose(this.cameraDirectionCtrlAsync.name, `call returned`); }) } cameraZoomCtrlAsync(cmd: CameraZoomCmd): Promise { NativeLogVerbose(this.cameraZoomCtrlAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraZoomCtrl)(this.deviceId, cmd).then(() => { NativeLogVerbose(this.cameraZoomCtrlAsync.name, `call returned`); }) } cameraPTZResetAsync(): Promise { NativeLogVerbose(this.cameraPTZResetAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraPTZReset)(this.deviceId).then(() => { NativeLogVerbose(this.cameraPTZResetAsync.name, `call returned`); }) } cameraAddPresetAsync(pathPic: string): Promise { NativeLogVerbose(this.cameraAddPresetAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraAddPreset)(this.deviceId, pathPic).then(() => { NativeLogVerbose(this.cameraAddPresetAsync.name, `call returned`); }) } cameraDelPresetAsync(presetIndex: number): Promise { NativeLogVerbose(this.cameraDelPresetAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraDelPreset)(this.deviceId, presetIndex).then(() => { NativeLogVerbose(this.cameraDelPresetAsync.name, `call returned`); }) } cameraDelAllPresetAsync(): Promise { NativeLogVerbose(this.cameraDelAllPresetAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraDelAllPreset)(this.deviceId).then(() => { NativeLogVerbose(this.cameraDelAllPresetAsync.name, `call returned`); }) } cameraGetAllPresetAsync(): Promise> { NativeLogVerbose(this.cameraGetAllPresetAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraGetAllPreset)(this.deviceId).then((result) => { NativeLogVerbose(this.cameraGetAllPresetAsync.name, `call returned`); return result; }) } cameraUpdatePresetAsync(presetIndex: number, pathPic: string): Promise { NativeLogVerbose(this.cameraUpdatePresetAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraUpdatePreset)(this.deviceId, presetIndex, pathPic).then(() => { NativeLogVerbose(this.cameraUpdatePresetAsync.name, `call returned`); }) } cameraApplyPresetAsync(presetIndex: number): Promise { NativeLogVerbose(this.cameraApplyPresetAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraApplyPreset)(this.deviceId, presetIndex).then(() => { NativeLogVerbose(this.cameraApplyPresetAsync.name, `call returned`); }) } cameraGetSmartTrackingOptInfoAsync(): Promise> { NativeLogVerbose(this.cameraGetSmartTrackingOptInfoAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraGetSmartTrackingOptInfo)(this.deviceId).then((result) => { NativeLogVerbose(this.cameraGetSmartTrackingOptInfoAsync.name, `call returned`); return result; }) } cameraSetSmartTrackingOptAsync(opt: CameraSmartTrackingOpt): Promise { NativeLogVerbose(this.cameraSetSmartTrackingOptAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraSetSmartTrackingOpt)(this.deviceId, opt).then(() => { NativeLogVerbose(this.cameraSetSmartTrackingOptAsync.name, `call returned`); }) } cameraGetSamrtTrackingOptAsync(): Promise { NativeLogVerbose(this.cameraGetSamrtTrackingOptAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraGetSamrtTrackingOpt)(this.deviceId).then((result) => { NativeLogVerbose(this.cameraGetSamrtTrackingOptAsync.name, `call returned`); return result; }) } cameraSetFaceDetectionAsync(enable: boolean): Promise { NativeLogVerbose(this.cameraSetFaceDetectionAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraSetFaceDetection)(this.deviceId, enable).then(() => { NativeLogVerbose(this.cameraSetFaceDetectionAsync.name, `call returned`); }) } cameraIsFaceDetectionEnableAsync(): Promise { NativeLogVerbose(this.cameraIsFaceDetectionEnableAsync.name, `call with #${this.deviceId}`); return util.promisify(ylSdkInterface.CameraIsFaceDetectionEnable)(this.deviceId).then((result) => { NativeLogVerbose(this.cameraIsFaceDetectionEnableAsync.name, `call returned`); return result; }) } /** * Add event handler for btnPress device events. * Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: 'btnPress', listener: DeviceTypeCallbacks.btnPress): this; /** * Add event handler for busyLightChange device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: 'busyLightChange', listener: DeviceTypeCallbacks.busyLightChange): this; /** * Add event handler for downloadFirmwareProgress device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: 'downloadFirmwareProgress', listener: DeviceTypeCallbacks.downloadFirmwareProgress): this; /** * Add event handler for onBTParingListChange device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: 'onBTParingListChange', listener: DeviceTypeCallbacks.onBTParingListChange): this; /** * Add event handler for onGNPBtnEvent device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: 'onGNPBtnEvent', listener: DeviceTypeCallbacks.onGNPBtnEvent): this; /** * Add event handler for onBatteryStatusUpdate device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: 'onBatteryStatusUpdate', listener: DeviceTypeCallbacks.onBatteryStatusUpdate): this; /** * Add event handler for remoteMmi events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: 'onRemoteMmiEvent', listener: DeviceTypeCallbacks.onRemoteMmiEvent): this; /** * Add event handler for onDevLogEvent device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: 'onDevLogEvent', listener: DeviceTypeCallbacks.onDevLogEvent): this; RegEvent(event: 'callAction', listener: DeviceTypeCallbacks.callAction): this; RegEvent(event: 'onDialNumebrChange', listener: DeviceTypeCallbacks.onDialNumebrChange): this; /** * Add event handler for one of the different device events. * Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ RegEvent(event: DeviceImplEvents, listener: DeviceTypeCallbacks.btnPress | DeviceTypeCallbacks.busyLightChange | DeviceTypeCallbacks.downloadFirmwareProgress | DeviceTypeCallbacks.onBTParingListChange | DeviceTypeCallbacks.onGNPBtnEvent | DeviceTypeCallbacks.onBatteryStatusUpdate | DeviceTypeCallbacks.onRemoteMmiEvent | DeviceTypeCallbacks.onDevLogEvent | DeviceTypeCallbacks.callAction | DeviceTypeCallbacks.onDialNumebrChange): this { this._eventEmitter.on(event, listener); return this; } /** * Add event handler for btnPress device events. * Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: 'btnPress', listener: DeviceTypeCallbacks.btnPress): this; /** * Add event handler for busyLightChange device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: 'busyLightChange', listener: DeviceTypeCallbacks.busyLightChange): this; /** * Add event handler for downloadFirmwareProgress device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: 'downloadFirmwareProgress', listener: DeviceTypeCallbacks.downloadFirmwareProgress): this; /** * Add event handler for onBTParingListChange device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: 'onBTParingListChange', listener: DeviceTypeCallbacks.onBTParingListChange): this; /** * Add event handler for onGNPBtnEvent device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: 'onGNPBtnEvent', listener: DeviceTypeCallbacks.onGNPBtnEvent): this; /** * Add event handler for onBatteryStatusUpdate device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: 'onBatteryStatusUpdate', listener: DeviceTypeCallbacks.onBatteryStatusUpdate): this; /** * Add event handler for remoteMmi events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: 'onRemoteMmiEvent', listener: DeviceTypeCallbacks.onRemoteMmiEvent): this; /** * Add event handler for onDevLogEvent device events. * *Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: 'onDevLogEvent', listener: DeviceTypeCallbacks.onDevLogEvent): this; UnregEvent(event: 'callAction', listener: DeviceTypeCallbacks.callAction): this; UnregEvent(event: 'onDialNumebrChange', listener: DeviceTypeCallbacks.onDialNumebrChange): this; /** * Add event handler for one of the different device events. * Please make sure your callback arguments matches the event type or you will get a misleading typescript error. See also {@link https://github.com/microsoft/TypeScript/issues/30843 30843}* */ UnregEvent(event: DeviceImplEvents, listener: DeviceTypeCallbacks.btnPress | DeviceTypeCallbacks.busyLightChange | DeviceTypeCallbacks.downloadFirmwareProgress | DeviceTypeCallbacks.onBTParingListChange | DeviceTypeCallbacks.onGNPBtnEvent | DeviceTypeCallbacks.onBatteryStatusUpdate | DeviceTypeCallbacks.onRemoteMmiEvent | DeviceTypeCallbacks.onDevLogEvent | DeviceTypeCallbacks.callAction | DeviceTypeCallbacks.onDialNumebrChange): this { this._eventEmitter.off(event, listener); return this; } }