From 135f3110232f3a486b83438fdc0f15db165f7494 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 29 Dec 2019 15:12:32 +0100 Subject: [PATCH] Add speed and time to progress callbacks --- docs/docs/FILES.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/docs/FILES.md b/docs/docs/FILES.md index eb364541..32d1d3fc 100644 --- a/docs/docs/FILES.md +++ b/docs/docs/FILES.md @@ -407,8 +407,10 @@ $sentMessage = yield $MadelineProto->messages->sendMedia([ '_' => 'inputMediaUploadedDocument', 'file' => new \danog\MadelineProto\FileCallback( 'video.mp4', - function ($progress) use ($MadelineProto, $peer) { - yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Upload progress: '.$progress.'%']); + function ($progress, $speed, $time) use ($MadelineProto, $peer) { + try { + yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => "Upload progress: $progress%\nSpeed: $speed mbps\nTime elapsed since start: $time"]); + } catch (\Throwable $e) {} } ), 'attributes' => [ @@ -423,8 +425,10 @@ $output_file_name = yield $MadelineProto->downloadToFile( $sentMessage, new \danog\MadelineProto\FileCallback( '/tmp/myname.mp4', - function ($progress) use ($MadelineProto, $peer) { - yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Download progress: '.$progress.'%']); + function ($progress, $speed, $time) use ($MadelineProto, $peer) { + try { + yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => "Download progress: $progress%\nSpeed: $speed mbps\nTime elapsed since start: $time"]); + } catch (\Throwable $e) {} } ) ); @@ -432,6 +436,8 @@ $output_file_name = yield $MadelineProto->downloadToFile( This will send the file `video.mp4` to [@danogentili](https://t.me/danogentili): while uploading, he will receive progress messages `Upload progress: 24%` until the upload is complete; while downloading, he will receive progress messages `Download progress: 34%` until the download is complete. +You can also add two more parameters `$speed, $time` to the signature of the method to get a partial upload speed in mbps, along with the time elapsed since the start of the download. + A FileCallback object can be provided to `uploadMedia`, `sendMedia`, `uploadProfilePicture`, `upload`, `upload_encrypted`, `download_to_*`: the first parameter to its constructor must be the file path/object that is usually accepted by the function, the second must be a callable function or object. You can also write your own callback class, just implement `\danog\MadelineProto\FileCallbackInterface`: