| 276 | |
| 277 | FrameProducer.prototype._connectService = function() { |
| 278 | function tryConnect(times, delay) { |
| 279 | return adb.openLocal(options.serial, 'localabstract:minicap') |
| 280 | .timeout(10000) |
| 281 | .then(function(out) { |
| 282 | return out |
| 283 | }) |
| 284 | .catch(function(err) { |
| 285 | if (/closed/.test(err.message) && times > 1) { |
| 286 | return Promise.delay(delay) |
| 287 | .then(function() { |
| 288 | return tryConnect(times - 1, delay * 2) |
| 289 | }) |
| 290 | } |
| 291 | return Promise.reject(err) |
| 292 | }) |
| 293 | } |
| 294 | log.info('Connecting to minicap service') |
| 295 | return tryConnect(5, 100) |
| 296 | } |