Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isBatterySupportedAsync, getBatteryStatusAsync sometimes not responding back #136

Open
mavitm opened this issue Feb 8, 2022 · 0 comments

Comments

@mavitm
Copy link

mavitm commented Feb 8, 2022

hi i am using electron js

"electron": "^11.4.5",
const j = require("@gnaudio/jabra-node-sdk");

class Jabra {
    constructor() {
        this.jabra              = null;
        this.device             = null;
        this.isBatterySupport   = false;
        this.batteryInfo        = {};
        this.attached           = false;

        this.connectResolve     = function () {};
        this.connectReject      = function () {};
    }

    async connect(){
        let that = this;
        return new Promise(function (resolve, reject) {

            that.connectResolve = resolve;
            that.connectReject  = reject;

            if(that.jabra !== null){
               that.connectResolve(that.device);
            }
            else {
                that._connect();
            }
        });
    }

    _connect(){
        let that = this;
        j.createJabraApplication('123').then((jabra) => {
            that.jabra = jabra;

            this.jabra.on('attach', this.attachDevice.bind(that));
            this.jabra.on('detach', this.detachDevice.bind(that));

            setTimeout(() => {
                if (that.attached !== true) {
                    that.connectReject("jabra sdk time out");
                    that.close();
                }
            }, 10000);

        }).catch(function (e) {
            that.connectReject("jabra sdk connection error");
            console.log(e);
        });
    }

    attachDevice(device){
        this.attached = true;
        this.device = device;
        this.connectResolve(this.device);
    }

    async detachDevice(device){
        if (this.jabra.getAttachedDevices().length < 1) {
            await this.close();
        }
    }

    async requestBatteryInfo(){
        let that = this;
        console.log("being pronounced battery ...");
        return new Promise(function (resolve, reject) {
            let getInfo = false;
            that.device.isBatterySupportedAsync().then(async (supported)=>{
                that.isBatterySupport = supported;
                if(that.isBatterySupport) {
                    that.device.getBatteryStatusAsync().then(function (b1) {
                        that.batteryInfo = b1;
                        console.log("BATTERY", that.batteryInfo);
                        resolve(that);
                        getInfo = true;
                    }).catch(function (e) {
                        getInfo = true;
                        reject(e);
                    });
                }else{
                    getInfo = true;
                    reject("device not supported battery info");
                }
            }).catch(function (e) {
                console.log(e);
                reject(e);
                getInfo = true;
            });

            setTimeout(() => {
                if (getInfo !== true) {
                    reject("jabra device time out");
                }
            }, 25000);
        });
    }

    async close(){
        let that = this;
        try {
            await that.jabra.disposeAsync();
            that.clear();
        }catch (e) {
            //console.log(e);
            that.clear();
        }
    }

    clear(){
        this.attached           = false;
        this.device             = null;
        this.jabra              = null;
    }
}
export default Jabra;

while using

app.on('ready', async () => {
       let that = this;
       let sendData = {battery: null};

       if (that.jabraSdk === null) {
            that.jabraSdk = new Jabra();
        }

        that.jabraSdk.connect().then(async (device) => {
            console.log("jabra device connected");

            that.jabraSdk.requestBatteryInfo().then(function (jabra) {
                if (jabra.isBatterySupport) {
                    sendData = {battery: jabra.batteryInfo};
                    app.events.emit("headset_battery_info", sendData);
                } else {
                    app.events.emit("headset_battery_info", sendData);
                }
            }).catch(function (e) {
                console.log(e);
                app.events.emit("headset_battery_info", sendData);
            });
        }).catch((e) => {
            console.log(e);
            app.events.emit("headset_battery_info", sendData);
        });
});

When the application first starts, there is no problem, I get the battery information, but if I refresh a few times, I start to get time out after a while.

requestBatteryInfo method waits for 25 seconds and gives time error, when I exit the application, zombie processes remain in the task manager and the application does not kill properly.

TypeError: Cannot read property 'getBatteryStatusAsync' of null
    at eval (webpack:///./src/background/headset/Jabra.js?:158:33)
TypeError: Cannot read property 'getBatteryStatusAsync' of null
    at eval (webpack:///./src/background/headset/Jabra.js?:158:33)
TypeError: Cannot read property 'getBatteryStatusAsync' of null
    at eval (webpack:///./src/background/headset/Jabra.js?:158:33)

sometimes it can also point to the isBatterySupportedAsync method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant