I'm Uriel, a software engineer 😄
urielch / adbkit Goto Github PK
View Code? Open in Web Editor NEWThis project forked from devicefarmer/adbkit
A pure Node.js client for the Android Debug Bridge.
License: Other
This project forked from devicefarmer/adbkit
A pure Node.js client for the Android Debug Bridge.
License: Other
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
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.
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'
}
@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.
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.
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.
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',
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.
Version ≤ 0.6.0 is vulnerable to CVE-2022-39353 and CVE-2021-32796
The package is now called @xmldom/xmldom
on NPM.
0.7 has some possible breaking changes mentioned in the release notes
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.
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.
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!!!
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)
})
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)
})()
-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:-' ]
}
/system/bin/sh: screenrecord--output-format=h264: inaccessible or not found
Question:
Thank all you
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.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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.