adbkit icon indicating copy to clipboard operation
adbkit copied to clipboard

Cannot get progress when using push or SyncService push

Open leifcr opened this issue 11 months ago • 0 comments

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.

leifcr avatar Jul 28 '23 10:07 leifcr