1.2.0 • Published 2 years ago

@vbet/webjs-sdk v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Installation

Include the package locally in your repository.

npm install @vbet/webjs-sdk

Examples

Demo

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){
    }
});
1.2.0

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago