Installation
Include the package locally in your repository.
npm install @vbet/webjs-sdk
Examples
Usage
Init the librarby
import {init} from "@vbet/webjs-sdk";
const api = await init()
Acquire permisson to device
Note: Due to security policy of WebHID, you have to grant permisson before the device can be used
import {webhidConsent} from "@vbet/webjs-sdk";
const HIDConsent = async () => {
await webhidConsent();
};
Getting a list of available devices by subscribing to events
import {init} from "@vbet/webjs-sdk";
const api = await init()
api.deviceList.subscribe((devices) => {
console.log("changed", devices);
});
Subscribing to events showing individually added or removed devices
import {init} from "@vbet/webjs-sdk";
const api = await init()
api.deviceAdded.subscribe((device) => {
console.log("added", device);
});
api.deviceRemoved.subscribe((device) => {
console.log("removed", device);
});
Subscribing to connection event (Dongle only)
Subscribe to this event to receive wireless headset connection
import {DeviceType, IDongle} from "@vbet/webjs-sdk";
api.deviceAdded.subscribe((device) => {
console.log("added", device);
if (device.type === DeviceType.DONGLE) {
(device as IDongle).connection.subscribe((connection) => {
console.log(connection);
});
}
});
Subscribing to device signal
Subscribe to this event to monitor user interaction with device
import {init, DeviceSignalType} from "@vbet/webjs-sdk";
api.deviceAdded.subscribe((device) => {
console.log("added", device);
device.deviceSignal.subscribe((signal) => {
console.log("received device signal", signal);
if(signal === DeviceSignalType.ACCEPT_CALL){
//softphone accpet incomming call
}
});
});
Synchronize device state
It's important to synchronize the device state to the state of the softphone, so that the device can behave as expected on each phone call cycle
import {init, DeviceSignalType} from "@vbet/webjs-sdk";
api.deviceAdded.subscribe((device) => {
console.log("added", device);
//.....
//received an incomming call
try{
await device.ring()
}catech(error){
}
//call accepted
try{
await device.offHook()
}catech(error){
}
//call ended
try{
await device.onHook()
}catech(error){
}
});