Code Monkey home page Code Monkey logo

Comments (6)

joaomirandas avatar joaomirandas commented on August 26, 2024 1

I solved the problem in a different way, I already knew that I needed the gm installed but I was not getting for several days save the image file, now with this solution below I got it correctly!

it was something related to strem.pipe - I had not thought of this solution before.

NOTE: You need to make the documentation clearer as it is very superficial about what procedures are needed - I will version readme.md

SOLUTION:

client.screencap(POINTER['id']).then(function(stream) { stream.pipe(fs.createWriteStream("./public/screencaps/"+POINTER['id']+".png")); });

Captura de Tela 2019-12-23 às 15 47 06

from adbkit.

sorccu avatar sorccu commented on August 26, 2024

It's just a PNG stream, save it like any other stream in Node. You should be able to just:

var fs = require('fs')

client.screencap(device.id).then(function(stream) {
  fs.writeFileSync('screenshot.png', stream) // Synchronous - bad!
})

If it doesn't work then there may be some kind of a bug in there.

Preferably you'd replace the synchronous call with a Promise-wrapped asynchronous version, but that's a task for you.

from adbkit.

joaomirandas avatar joaomirandas commented on August 26, 2024

Guys, I'm not able to use the screencap function - when I try to use stream on console.log I just see a LineTransform object and when I try to save, no images are received. Only one 15kb file is generated.

This:
Captura de Tela 2019-12-23 às 12 14 08

GENERATE THIS:

LineTransform {
  savedR: null,
  autoDetect: false,
  transformNeeded: true,
  skipBytes: 1,
  _readableState:
   ReadableState {
     objectMode: false,
     highWaterMark: 16384,
     buffer: BufferList { head: null, tail: null, length: 0 },
     length: 0,
     pipes: null,
     pipesCount: 0,
     flowing: null,
     ended: false,
     endEmitted: false,
     reading: false,
     sync: false,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     paused: true,
     emitClose: true,
     autoDestroy: false,
     destroyed: false,
     defaultEncoding: 'utf8',
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null },
  readable: true,
  _events:
   [Object: null prototype] {
     prefinish: [Function: prefinish],
     unpipe: [Function: onunpipe],
     drain: [Function: pipeOnDrainFunctionResult],
     error: [Function: onerror],
     close:
      { [Function: bound onceWrapper] listener: [Function: onclose] },
     finish:
      { [Function: bound onceWrapper] listener: [Function: onfinish] } },
  _eventsCount: 6,
  _maxListeners: undefined,
  _writableState:
   WritableState {
     objectMode: false,
     highWaterMark: 16384,
     finalCalled: false,
     needDrain: false,
     ending: false,
     ended: false,
     finished: false,
     destroyed: false,
     decodeStrings: true,
     defaultEncoding: 'utf8',
     length: 0,
     writing: false,
     corked: 0,
     sync: false,
     bufferProcessing: false,
     onwrite: [Function: bound onwrite],
     writecb: null,
     writelen: 0,
     bufferedRequest: null,
     lastBufferedRequest: null,
     pendingcb: 1,
     prefinished: false,
     errorEmitted: false,
     emitClose: true,
     autoDestroy: false,
     bufferedRequestCount: 0,
     corkedRequestsFree:
      { next: null,
        entry: null,
        finish: [Function: bound onCorkedFinish] } },
  writable: true,
  allowHalfOpen: true,
  _transformState:
   { afterTransform: [Function: bound afterTransform],
     needTransform: true,
     transforming: false,
     writecb: null,
     writechunk: null,
     writeencoding: 'buffer' } }

Could you give me some help?

from adbkit.

koral-- avatar koral-- commented on August 26, 2024

You need to actually read data from stream.
You are printing out a stream object, not its contents.

from adbkit.

imagine-maven avatar imagine-maven commented on August 26, 2024

thanks a lot @joaomirandasa it helped to solve my problem as well :)

from adbkit.

imagine-maven avatar imagine-maven commented on August 26, 2024

`
// here, I am hard coding the IP address of android device in hostid variable
// function to capture screenshot

function capture(){
client.screencap(hostid)
// returned promise is a PNG stream 'stream'
.then(function(stream) {
stream.pipe(fs.createWriteStream("./" + hostid + ".png"))
console.log('saving screenshot in the current directory..')

})
.catch(function(err){
    console.error(err)
})

}

// call capture function with 2 seconds delay
setTimeout(capture , 2000);
`

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.