Code Monkey home page Code Monkey logo

Comments (2)

fdgonthier avatar fdgonthier commented on August 26, 2024

Additional information. The problem seems to stem from Electron or at least Electron's version of Node.js.

I'm digging into ADBkit connection code and noticed the following:

  connect: ->
    console.log "test"
    @socket = new Net.Socket
    @socket.setNoDelay true
    @parser = new Parser @socket
    @socket.on 'connect', =>
      console.log "Connected"
      this.emit 'connect'
    @socket.on 'end', =>
      this.emit 'end'
    @socket.on 'drain', =>
      this.emit 'drain'
    @socket.on 'timeout', =>
      this.emit 'timeout'
    @socket.on 'error', (err) =>
      this._handleError err
    @socket.on 'close', (hadError) =>
      this.emit 'close', hadError
    @socket.connect @options
    return this

If I remove the first console.log statement, the connection goes through fine and I see the "Connected" console.log message. If I keep it there, the connection is never made. This code is very timing sensitive for some reasons... can't figure out why yet

from adbkit.

fdgonthier avatar fdgonthier commented on August 26, 2024

This sample only ever works reliably in Electron if there is NO console.log statement in ADBKit code, which means there is a race condition somewhere. I admit the bug is probably not in ADBKit...

var adb = require("adbkit");
var util = require("util");
var Promise = require("bluebird");

try {
    var Electron = require("electron");
} catch (e) {}

var main = function () {
    //console.log("Creating ADB client");

    adbClient = adb.createClient();

    adbClient.trackDevices()
        .then((tracker) => {
            tracker.on("add", (device) => {
                //console.log("Added: " + device.id);

                Promise.join(
                    adbClient.getFeatures(device.id),
                    adbClient.getProperties(device.id),
                    (features, props) => {
                        console.log("Features: " + util.inspect(features));
                        console.log("Properties: " + util.inspect(props));
                    });
            });
            tracker.on("remove", (device) => {
                console.log("Removed: " + device.id);
            });
            tracker.on("change", (device) => {
                console.log("Changed: " + device.id);
            });
            tracker.on("error", (err) => {
                console.log("Error: " + err);
            });
        });
};

if (Electron)
    Electron.app.on("ready", main);
else
    main();

from adbkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.