diff --git a/bindings/fileTransfer.go b/bindings/fileTransfer.go index b2239b9c8cb0c38d710723f51b8e00df44d40dfe..3d5d645802fd67460c0b051809a2f624b471624a 100644 --- a/bindings/fileTransfer.go +++ b/bindings/fileTransfer.go @@ -268,9 +268,11 @@ func (f *FileTransfer) CloseSend(tidBytes []byte) error { // Parameters: // - tidBytes - file transfer ID // - callback - callback that reports file reception progress -// - period - duration to wait between progress callbacks triggering +// - period - Duration (in ms) to wait between progress callbacks triggering. +// This value should depend on how frequently you want to receive +// updates, and should be tuned to your implementation. func (f *FileTransfer) RegisterSentProgressCallback(tidBytes []byte, - callback FileTransferSentProgressCallback, period string) error { + callback FileTransferSentProgressCallback, period int) error { cb := func(completed bool, arrived, total uint16, st fileTransfer.SentTransfer, t fileTransfer.FilePartTracker, err error) { prog := &Progress{ @@ -282,10 +284,7 @@ func (f *FileTransfer) RegisterSentProgressCallback(tidBytes []byte, pm, err := json.Marshal(prog) callback.Callback(pm, &FilePartTracker{t}, err) } - p, err := time.ParseDuration(period) - if err != nil { - return err - } + p := time.Millisecond * time.Duration(period) tid := ftCrypto.UnmarshalTransferID(tidBytes) return f.w.RegisterSentProgressCallback(&tid, cb, p) @@ -299,9 +298,11 @@ func (f *FileTransfer) RegisterSentProgressCallback(tidBytes []byte, // Parameters: // - tidBytes - file transfer ID // - callback - callback that reports file reception progress -// - period - duration to wait between progress callbacks triggering +// - period - Duration (in ms) to wait between progress callbacks triggering. +// This value should depend on how frequently you want to receive +// updates, and should be tuned to your implementation. func (f *FileTransfer) RegisterReceivedProgressCallback(tidBytes []byte, - callback FileTransferReceiveProgressCallback, period string) error { + callback FileTransferReceiveProgressCallback, period int) error { cb := func(completed bool, received, total uint16, rt fileTransfer.ReceivedTransfer, t fileTransfer.FilePartTracker, err error) { prog := &Progress{ @@ -313,10 +314,8 @@ func (f *FileTransfer) RegisterReceivedProgressCallback(tidBytes []byte, pm, err := json.Marshal(prog) callback.Callback(pm, &FilePartTracker{t}, err) } - p, err := time.ParseDuration(period) - if err != nil { - return err - } + p := time.Millisecond * time.Duration(period) + tid := ftCrypto.UnmarshalTransferID(tidBytes) return f.w.RegisterReceivedProgressCallback(&tid, cb, p) }