Example #1
0
    return new Promise((resolve, reject) => {
      if (!this.ready) {
        setTimeout(function() {
          reject("ADB_NOT_READY");
        });
        return;
      }

      const socket = client.connect();

      socket.s.onopen = function() {
        dumpn("runCommand onopen");
        const req = client.createRequest(command);
        socket.send(req);
      };

      socket.s.onerror = function() {
        dumpn("runCommand onerror");
        reject("NETWORK_ERROR");
      };

      socket.s.onclose = function() {
        dumpn("runCommand onclose");
      };

      socket.s.ondata = function(event) {
        dumpn("runCommand ondata");
        const data = event.data;

        const packet = client.unpackPacket(data, false);
        if (!client.checkResponse(data, OKAY)) {
          socket.close();
          dumpn("Error: " + packet.data);
          reject("PROTOCOL_ERROR");
          return;
        }

        resolve(packet.data);
      };
    });
Example #2
0
    socket.s.onclose = function() {
      dumpn("trackDevices onclose");

      // Report all devices as disconnected
      for (const dev in devices) {
        devices[dev] = false;
        EventEmitter.emit(ADB, "device-disconnected", dev);
      }

      Services.obs.notifyObservers(null, "adb-track-devices-stop");

      // When we lose connection to the server,
      // and the adb is still on, we most likely got our server killed
      // by local adb. So we do try to reconnect to it.
      setTimeout(function() { // Give some time to the new adb to start
        if (ADB.ready) { // Only try to reconnect/restart if the add-on is still enabled
          ADB.start().then(function() { // try to connect to the new local adb server
                                         // or, spawn a new one
            ADB.trackDevices(); // Re-track devices
          });
        }
      }, 2000);
    };
Example #3
0
 await new Promise(resolve => setTimeout(resolve, 100));