Skip to content

Commit 777fd43

Browse files
authored
Fix missing attributes in data stream (#865)
* Fix missing attributes * Update tests
1 parent e69bb1f commit 777fd43

File tree

7 files changed

+459
-151
lines changed

7 files changed

+459
-151
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ _build
8686

8787
# flutter web
8888
lib/generated_plugin_registrant.dart
89+
90+
# Test files - ignore any binary files in testfiles directory
91+
testfiles/*.bin

lib/src/data_stream/stream_writer.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import '../types/data_stream.dart';
99
import '../types/other.dart';
1010
import '../utils.dart';
1111

12+
1213
class BaseStreamWriter<T, InfoType extends BaseStreamInfo> {
1314
final StreamWriter<T> writableStream;
1415
Function()? onClose;
@@ -48,6 +49,7 @@ class WritableStream<T> implements StreamWriter<T> {
4849
int chunkId = 0;
4950
List<String>? destinationIdentities;
5051
Engine engine;
52+
5153
WritableStream({
5254
required this.streamId,
5355
required this.engine,

lib/src/participant/local.dart

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,22 @@ extension RPCMethods on LocalParticipant {
11521152
}
11531153
}
11541154

1155+
/// Helper function to convert string operation type to enum
1156+
lk_models.DataStream_OperationType _stringToOperationType(String? type) {
1157+
switch (type?.toLowerCase()) {
1158+
case 'create':
1159+
return lk_models.DataStream_OperationType.CREATE;
1160+
case 'update':
1161+
return lk_models.DataStream_OperationType.UPDATE;
1162+
case 'delete':
1163+
return lk_models.DataStream_OperationType.DELETE;
1164+
case 'reaction':
1165+
return lk_models.DataStream_OperationType.REACTION;
1166+
default:
1167+
return lk_models.DataStream_OperationType.CREATE;
1168+
}
1169+
}
1170+
11551171
extension DataStreamParticipantMethods on LocalParticipant {
11561172
Future<TextStreamInfo> sendText(String text,
11571173
{SendTextOptions? options}) async {
@@ -1181,6 +1197,7 @@ extension DataStreamParticipantMethods on LocalParticipant {
11811197
destinationIdentities: options?.destinationIdentities ?? [],
11821198
topic: options?.topic,
11831199
attachedStreamIds: fileIds ?? [],
1200+
attributes: options?.attributes ?? {},
11841201
));
11851202

11861203
await writer.write(text);
@@ -1230,13 +1247,13 @@ extension DataStreamParticipantMethods on LocalParticipant {
12301247
topic: info.topic,
12311248
timestamp: Int64(info.timestamp),
12321249
totalLength: Int64(options?.totalSize ?? 0),
1250+
attributes: options?.attributes.entries,
12331251
textHeader: lk_models.DataStream_TextHeader(
12341252
version: options?.version,
12351253
attachedStreamIds: options?.attachedStreamIds,
12361254
replyToStreamId: options?.replyToStreamId,
1237-
operationType: options?.type == 'update'
1238-
? lk_models.DataStream_OperationType.UPDATE
1239-
: lk_models.DataStream_OperationType.CREATE,
1255+
generated: options?.generated ?? false,
1256+
operationType: _stringToOperationType(options?.type),
12401257
),
12411258
);
12421259
final destinationIdentities = options?.destinationIdentities;
@@ -1307,7 +1324,6 @@ extension DataStreamParticipantMethods on LocalParticipant {
13071324
options.onProgress?.call((i + 1) / totalChunks);
13081325
}
13091326
await writer.close();
1310-
writer.info;
13111327
}
13121328

13131329
Future<ByteStreamWriter> streamBytes(StreamBytesOptions? options) async {
@@ -1333,6 +1349,7 @@ extension DataStreamParticipantMethods on LocalParticipant {
13331349
byteHeader: lk_models.DataStream_ByteHeader(
13341350
name: info.name,
13351351
),
1352+
attributes: options?.attributes.entries,
13361353
);
13371354

13381355
final destinationIdentities = options?.destinationIdentities;

lib/src/types/data_stream.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ class SendTextOptions {
1414

1515
Function(double)? onProgress;
1616

17+
/// user defined attributes map that can carry additional info
18+
Map<String, String> attributes;
19+
1720
SendTextOptions({
1821
this.topic,
1922
this.destinationIdentities = const [],
2023
this.attachments = const [],
2124
this.onProgress,
25+
this.attributes = const {},
2226
});
2327
}
2428

@@ -48,9 +52,15 @@ class StreamTextOptions {
4852
String? replyToStreamId;
4953
int? totalSize;
5054

51-
/// 'create' | 'update'
55+
/// 'create' | 'update' | 'delete' | 'reaction'
5256
String? type;
5357

58+
/// true if the text has been generated by an agent from a participant's audio transcription
59+
bool generated;
60+
61+
/// user defined attributes map that can carry additional info
62+
Map<String, String> attributes;
63+
5464
StreamTextOptions({
5565
this.topic,
5666
this.destinationIdentities = const [],
@@ -60,6 +70,8 @@ class StreamTextOptions {
6070
this.replyToStreamId,
6171
this.totalSize,
6272
this.type,
73+
this.generated = false,
74+
this.attributes = const {},
6375
});
6476
}
6577

pubspec.lock

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ packages:
268268
dependency: "direct main"
269269
description:
270270
name: flutter_webrtc
271-
sha256: "69095ba39b83da3de48286dfc0769aa8e9f10491f70058dc8d8ecc960ef7a260"
271+
sha256: "945d0a38b90fbca8257eadb167d8fb9fa7075d9a1939fd2953c10054454d1de2"
272272
url: "https://pub.dev"
273273
source: hosted
274-
version: "1.0.0"
274+
version: "1.1.0"
275275
frontend_server_client:
276276
dependency: transitive
277277
description:
@@ -384,6 +384,14 @@ packages:
384384
url: "https://pub.dev"
385385
source: hosted
386386
version: "4.0.0"
387+
logger:
388+
dependency: transitive
389+
description:
390+
name: logger
391+
sha256: "55d6c23a6c15db14920e037fe7e0dc32e7cdaf3b64b4b25df2d541b5b6b81c0c"
392+
url: "https://pub.dev"
393+
source: hosted
394+
version: "2.6.1"
387395
logging:
388396
dependency: "direct main"
389397
description:

0 commit comments

Comments
 (0)