How to use screenshot?
So I have this code:
return client.screencap(device.id)
.then(function(stream) {
// Well, what now?
});
What can I do with the object I get after calling screencap?
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.
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:

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?
You need to actually read data from stream. You are printing out a stream object, not its contents.
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")); });

thanks a lot @joaomirandasa it helped to solve my problem as well :)
` // 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); `