Skip to content

Commit 579bfa4

Browse files
authored
Fix stream progress (#884)
Make sure progress is within 0.0 ~ 1.0
1 parent a4871f5 commit 579bfa4

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/src/participant/local.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,7 @@ extension DataStreamParticipantMethods on LocalParticipant {
11711171
handleProgress(num progress, int idx) {
11721172
progresses[idx] = progress;
11731173
final totalProgress = progresses.reduce((acc, val) => acc + val);
1174-
options?.onProgress
1175-
?.call(totalProgress.toDouble() / (fileIds?.length ?? 1));
1174+
options?.onProgress?.call(totalProgress.toDouble() / len);
11761175
}
11771176

11781177
final writer = await streamText(StreamTextOptions(

test/core/data_stream_test.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ void main() {
8484
final info = await room.localParticipant?.sendText(longText,
8585
options: SendTextOptions(
8686
topic: 'chat-long-text',
87-
onProgress: (p0) {
88-
print('progress: $p0');
87+
onProgress: (progress) {
88+
print('progress: $progress');
89+
expect(progress, greaterThanOrEqualTo(0.0));
90+
expect(progress, lessThanOrEqualTo(1.0));
8991
},
9092
));
9193
expect(info, isNotNull);
@@ -149,8 +151,10 @@ void main() {
149151
options: SendTextOptions(
150152
topic: 'chat-stream-with-files',
151153
attachments: attachmentsFiles,
152-
onProgress: (p0) {
153-
print('file from chat-stream-with-files: progress: $p0');
154+
onProgress: (progress) {
155+
print('file from chat-stream-with-files: progress: $progress');
156+
expect(progress, greaterThanOrEqualTo(0.0));
157+
expect(progress, lessThanOrEqualTo(1.0));
154158
},
155159
));
156160
expect(info, isNotNull);
@@ -307,8 +311,10 @@ void main() {
307311
final info = await room.localParticipant?.sendFile(fileToSend,
308312
options: SendFileOptions(
309313
topic: 'file',
310-
onProgress: (p0) {
311-
print('progress: ${p0 * 100} %');
314+
onProgress: (progress) {
315+
print('progress: ${progress * 100} %');
316+
expect(progress, greaterThanOrEqualTo(0.0));
317+
expect(progress, lessThanOrEqualTo(1.0));
312318
},
313319
));
314320
expect(info, isNotNull);

0 commit comments

Comments
 (0)