包详细信息

@vbet/webhid-sdk

peter-vbet6.7kISC1.4.5

Controls VBet devices from WebHID

自述文件

Installation

Include the package locally in your repository.

npm install @vbet/webhid-sdk

API Usage

import { webhidConsent, IDevice, DeviceSignalType, findDevice } from '@vbet/webhid-sdk';

device = webhidConsent({config: {productId?: number}})

  • Triggers WebHID consent dialogue in compatible browsers to grant device access

device = findDevice(name:string)

  • Gets a granted device by name

device.ring()

  • Starts "ringing" effect on the device

device.offHook()

  • Makes device to offhook, used to answer incomming call or start outgoing call

device.onHook()

  • Makes device to onhook, used to terminate current call or reject incomming call

device.muteOn()

  • Mutes device's microphone

device.muteOff()

  • Unmutes device's microphone

device.subscribe(callback: (signal: DeviceSignalType) => void)

  • Subscribes to device event

device.unsubscribe()

  • Unsubscribes to device event

Example of Usage

const device = await webhidConsent({productId:0x0014});

//listen to device's event
device.subscribe((signal) => {
    switch (signal) {
        case DeviceSignalType.ACCEPT_CALL:
          //call was accepted by the device, softphone should answer the call
          //Remark: must call this function to sync device state either at here or somewhere at softphone state change confirmation callback 
          device.offHook()
          break;
        case DeviceSignalType.END_CALL:
          //call was ended by the device, softphone should end the call
          //Remark: must call this function to sync device state either at here or somewhere at softphone state change confirmation callback 
          device.onHook()
          break;
        case DeviceSignalType.REJECT_CALL:
          //call was ended by the device, softphone should end the call
          //Remark: must call this function to sync device state either at here or somewhere at softphone state change confirmation callback 
          device.onHook()
          break;
        case DeviceSignalType.MUTE_CALL:
          //call was muted by the device, softphone should mute the call
          //Remark: must call this function to sync device state either at here or somewhere at softphone state change confirmation callback 
          device.muteOn()
          break;
        case DeviceSignalType.UNMUTE_CALL:
          //call was unmuted by the device, softphone should unmute the call
          //Remark: must call this function to sync device state either at here or somewhere at softphone state change confirmation callback 
          device.muteOff()
          break;
    }
});

device.ring()