@vbet/webhid-sdk
v1.4.9
Published
Controls VT devices from WebHID
Readme
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.rejct()
- Rejects the incoming call.
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
device.muteOn()
- Mutes device's microphone
device.muteOff()
- Unmutes device's microphone
device.hold()
- Holds the current call
device.resume()
- Resumes the current call
device.subscribe(callback: (signal: DeviceSignalType) => void)
- Subscribes to device event
device.unsubscribe()
- Must be called to dispose device when not being used to free up memory
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.rejct()
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;
case DeviceSignalType.HOLD_CALL:
//call was held by the device, softphone should hold the call
//Remark: must call this function to sync device state either at here or somewhere at softphone state change confirmation callback
device.hold();
break;
case DeviceSignalType.RESUME_CALL:
//call was resumed by the device, softphone should resume the call
//Remark: must call this function to sync device state either at here or somewhere at softphone state change confirmation callback
device.resume();
break;
}
});
device.ring()
//......
//later
device.unsubscribe()