Giter Club home page Giter Club logo

adbkit's Introduction

I'm Uriel, a software engineer 😄

Anurag's github stats

Top Langs

adbkit's People

Contributors

bennlich avatar codeskyblue avatar dependabot-preview[bot] avatar drauggres avatar fiws avatar gunta avatar hamanaka-styly avatar hbc007 avatar jeannedark avatar koral-- avatar noahandrews avatar nwalters512 avatar pimterry avatar pretyk avatar redgell avatar sorccu avatar urielch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

adbkit's Issues

Scrcpy.start() does not resolve

Hi, I was trying to use the Scrcpy class you implemented but the start method does not resolve. The execution gets stuck. Here is a snippet of my current code:

const snippet = async () => {
	const devices = await client.listDevices();
	if (devices.length == 0) {
		return
	}

	const device = devices[0].getClient()
	const scrcpy = device.scrcpy({})
	console.log("Starting")
	await scrcpy.start()
	console.log("Started")
}

It never reaches the last console.log

take a screenshot with scrcpy, suggestion need

I don't know how to decode/encdoe from h264 to jpeg
without write to mp4 first and then call ffmpeg to get frame snapshot

here is my code

const scrcpy = client.scrcpy({
  crop: '640:480:0:300',
})
scrcpy.on('config', config => {
  console.log('config=', config)
})
scrcpy.on('frame', async data => {
  // how to decode data into jpeg, following code from test task
  let dm = await beamcoder.demuxer() // HELP NEED
  let dec = beamcoder.decoder({ demuxer: dm, stream_index: 0 }) // Create a decoder
  let packet = await dm.read()
  let decResult = await dec.decode(packet)
  let enc = beamcoder.encoder({ // Create an encoder for JPEG data
    name: 'mjpeg', // FFmpeg does not have an encoder called 'jpeg'
    width: dec.width,
    height: dec.height,
    pix_fmt: dec.pix_fmt.indexOf('422') >= 0 ? 'yuvj422p' : 'yuvj420p',
    time_base: [1, 1],
  })
  let jpegResult = await enc.encode(decResult.frames[0]) // Encode the frame
  await enc.flush() // Tidy the encoder
  await fs.promises.writeFile(`./out/snap_${new Date().getTime()}.jpeg`, jpegResult.packets[0].data)
})

let info = await scrcpy.start()
// firstFrame is undefined, it would be nice if firstFrame is a frame data
let frame = await info.firstFrame

PS. I want to make screenshot from some restrict app that not allow to.
Only scrcpy tools can cast stream out , but it can't take a screenshot.

Please help me with minicap

I got this error when try get screenshot.
return new errors_1.AdbFailError(error, this.lastMessage);
^

AdbFailError: Failure: '' lastMessage:DONE 1688539188
at Parser.readError (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\parser.js:233:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Parser.readCode (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\parser.js:106:19)
at async Sync._writeData (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\sync.js:278:13)
at async DeviceClient.push (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\DeviceClient.js:959:27)
at async Minicap.start (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\thirdparty\minicap\Minicap.js:135:24)
at async file:///D:/nodeuiandroid/test.js:57:5
Emitted 'error' event on PushTransfer instance at:
at PushTransfer.emit (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\sync\pushtransfer.js:20:47)
at Sync._writeData (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\sync.js:281:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async DeviceClient.push (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\DeviceClient.js:959:27)
at async Minicap.start (D:\nodeuiandroid\node_modules@u4\adbkit\dist\adb\thirdparty\minicap\Minicap.js:135:24)
at async file:///D:/nodeuiandroid/test.js:57:5 {
lastMessage: 'DONE 1688539188'
}

Unsafe assignment/member access/call of an `any` value.

@UrielCh I was having trouble with @devicefarmer/adbkit recently when I tried using device.openLogcat. Specifically, the problem with that seemed to have been for some reason the Logcat type information wasn't being detected. For instance, if you take a look at the following code.
2022-09-09-13 05 08@2x
You will notice that vscode does not give me any suggestions on the Logcat class implementation. I tried installing @devicefarmer/adbkit-logcat separately, but decided not to use it separately becuase it appeared as if @devicefarmer/adbkit library already had adbkit-logcat integrated. Anyway, I didn't want to dig any deeper into this issue with @DeviceFarmer and that's when I found your fork. Given that your version uses pure Typescript, I uninstalled bluebird and all the @DeviceFarmer packages and tried using your version.

I hoped it would have been pretty much plug and play, replace and move on, but it seems like there are a little more things I need to do before using your version properly.

So, basically, I imported your adbkit, and updated the code to execute createClient function directly, instead of doing something like Adb.createClient() as it was with @DeviceFarmer. After doing this, I started getting some eslint errors relating to unsafe assignment/member access/call of an any value.

2022-09-09-13 10 41@2x

I wasn't sure whether this was directly related to the way your adbkit pure Typescript version was written or if it had something to do with my usage of the library, but I thought I'd consult with you to check if you had any thoughts on it.

Cannot find module 'picocolors'

problem

test code

const Adb = require('@u4/adbkit')

const client = Adb.createClient()

(async () => {
  const device = await client.listDevice()
  console.log(device)
})()

throw error

internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'picocolors'
Require stack:
- D:\vueProject\testP\node_modules\@u4\adbkit\dist\adb\command\host-transport\ipRoute.js
- D:\vueProject\testP\node_modules\@u4\adbkit\dist\adb\command\host-transport\index.js
- D:\vueProject\testP\node_modules\@u4\adbkit\dist\adb\DeviceClient.js
- D:\vueProject\testP\node_modules\@u4\adbkit\dist\adb\command\host\devices.js
- D:\vueProject\testP\node_modules\@u4\adbkit\dist\adb\command\host\index.js
- D:\vueProject\testP\node_modules\@u4\adbkit\dist\adb\client.js
- D:\vueProject\testP\node_modules\@u4\adbkit\dist\adb.js
- D:\vueProject\testP\node_modules\@u4\adbkit\dist\index.js
- D:\vueProject\testP\adb.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (D:\vueProject\testP\node_modules\@u4\adbkit\dist\adb\command\host-transport\ipRoute.js:8:38)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19) {
  code: 'MODULE_NOT_FOUND',

analysis

move the picocolors to dependencies ?
1650015274(1)

TypeError: client.shell is not a function @u4/adbkit

Hello everyone, i get this error : "TypeError: client.shell is not a function". Here is my node server:
const express = require('express');
const { Readable } = require('stream');
const Adb = require('@u4/adbkit');

const app = express();
const client = Adb.createClient();

app.get("/",(req, res) => {
res.sendFile(__dirname + "/test.html");
});

app.get('/video', async (req, res) => {
const stream = client.shell('scrcpy -s R9HT10HL56R --no-display', 'device');
Adb.Utils.readAll(stream).then(output => {
const readable = new Readable();
readable.push(output);
readable.push(null);
res.set('Content-Type', 'video/mp4');
readable.pipe(res);
}).catch(err => {
console.error(err);
res.status(500).send('Error streaming video');
});
});
app.listen(3000, () => {
console.log('Server listening on port 8000');
});

If you have faced with this issue, please give a solution. Thank you.

Cannot get progress when using push or SyncService push

Hi

I cannot seem to successfully get the progress on a push or the syncservice push.

It seems like the promise is not returned before the push is complete or failed, resulting on the PushTransfer object being available after the promise is resolved.

Example code that works, but events are not triggered

  pushFileToDevices = async (
    device: Device,
    localFilePath: string,
    remoteFilePath: string
  ): Promise<void> => {
    try {
      const sync = await device.getClient().syncService()
      const transfer = await sync.push(localFilePath, remoteFilePath)
      transfer.on('progress', (stats) => {
        console.log(`[${device.id}] Pushed ${stats.bytesTransferred} bytes so far`)
      })
      transfer.on('end', () => {
        console.log(`[${device.id}] Push complete`)
      })
      console.log(`Pushed ${localFilePath} to ${device.id}:${remoteFilePath}`)
    } catch (err) {
      console.error(`Could not push ${localFilePath} to ${device.id}:${remoteFilePath}: ${err}`)
    }
  }

Same result when using then statement instead of awaiting the PushTransfer object.

Handle `device unauthorized` error when getting a device's status

This seems to be fixed in ADB 35.0.1, but with ADB 31.0.3, when you try to get the device status of an unauthorized device, the server will respond with an error that includes the text device unauthorized, instead of just reporting the device's status as, which is an unfortunate (and kind of comical) bug on Google's side. Since this library can be used with versions of the ADB server with this bug, it should handle it. I'm planning on submitting a PR.

Do you have code example that get the video stream and control stream?

Hello everyone , I want to use this libray to get the video live stream (h264) and control stream.
When i get the encode video stream, i will use h264-decoder to decode to video mp4 and display it on canvas.
And the control stream socket, i will use it to control the device via mouse wheel, click and keyboard.
If you have experience in project, please help me.
Or if you have code you can comment below.
Thank all you!!!

scrcpy do not work , scrcpy不能正常工作

hello,我添加了以下代码,
minicap可以正常工作

const minicap = deviceClient.minicap({});
    await minicap.start();
    minicap.on('data', (buf) => {
        let aa=cv.imdecode(buf)
        cv.imshow("aa",aa)
        cv.waitKey(1)
    })

scrcpy卡在 start()地方

const deviceClient = devices[0].getClient();
    const scrcpy = deviceClient.scrcpy({})
    await scrcpy.start()
    scrcpy.on('frame',(fram)=>{
        let aa=cv.imdecode(fram.data)
        cv.imshow("aa",aa)
        cv.waitKey(1)
    })

微信截图_20220818104923

deviceClient.execOut not working?

Hello my friend

import pkg from "@u4/adbkit";
const { createClient,Utils,} = pkg
const utilRead = new Utils();
const adbClient = createClient();
(async () => {
    const devices = await adbClient.listDevices();
    if(!devices) return console.log("No device detect");
    let deviceClient = devices[0].getClient();
    let serial = devices[0].id;
    console.log(serial);
   deviceClient.framebuffer(serial,(err,raw) =>{
        if(err) return console.log("Error at client.framebuffer:", err);
        console.log(raw);
    })
    const getVideoBuffer = await deviceClient.execOut('screenrecord--output-format=h264 --size 720x1600', "base64");
    console.log(getVideoBuffer)
})()
  • At "deviceClient.framebuffer" it throw an error:
-node:events:491
      throw er; // Unhandled 'error' event
      ^
Error: spawn gm ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:289:12)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn gm',
  path: 'gm',
  spawnargs: [ 'convert', '-size', '4608000x720', 'rgba:-', 'R9HT10C4V5X:-' ]
}
  • At " console.log(getVideoBuffer)" it is log only "L3N5c3RlbS9iaW4vc2g6IHNjcmVlbnJlY29yZC0tb3V0cHV0LWZvcm1hdD1oMjY0OiBpbmFjY2Vzc2libGUgb3Igbm90IGZvdW5kCg==".
  • If i change encoding to "utf8" it throw error :
    /system/bin/sh: screenrecord--output-format=h264: inaccessible or not found

Question:

  • How can I get frame video stream?

Thank all you

TypeError: Adb.createClient is not a function

First, thank you so much for modernizing adbkit.
Taking a look at the examples:

import Bluebird from 'bluebird';
import Adb from '@u4/adbkit';

const client = Adb.createClient();

const test = async () => {
    try {
        const devices = await client.listDevices();
        const supportedDevices = await Bluebird.filter(devices, async (device) => {
            const features = await client.getFeatures(device.id);
            return features['android.hardware.nfc'];
        });
        console.log('The following devices support NFC:', supportedDevices);
    } catch (err) {
        console.error('Something went wrong:', err.stack);
    }
};
➜  nodeadb DEBUG=adb:* node app.js
file:///home/user/code/gitlab/nodeadb/app.js:4
const client = Adb.createClient();
                   ^

TypeError: Adb.createClient is not a function
    at file:///home/user/code/gitlab/nodeadb/app.js:4:20
    at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

[email protected] /home/user/code/gitlab/nodeadb
├── @u4/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

I must be doing something trivial incorrectly.

scrcpy start后报错

我遇到了一个问题 在启动scrcpy start后报错
image
安卓版本是12 使用的redroid ,使用官方的scrcpy工具是正常的

[Feature Request] Add H264Configuration.data

scrcpy.on('frame', (data) => ffmpeg.stdin.write(data.data)) will always fail because config packets are never passed to ffmpeg, while there is no way to pipe the config packets to ffmpeg since it has been parsed in config event.

I think adding H264Configuration.data will make config packets can be passed to ffmpeg by scrcpy.on('config', (data) => ffmpeg.stdin.write(data.data)).

Alternatively, adding an event listener called data and use scrcpy.on('data', (data) => ffmpeg.stdin.write(data)) to pipe frames to ffmpeg.

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.