From 4fd1e42e7dec8eced79fa28797d8c051d4af88be Mon Sep 17 00:00:00 2001 From: Mike Depinet Date: Fri, 13 Dec 2024 16:21:26 -0800 Subject: [PATCH] Websocket client tool results (#12) This fixes large tool results sometimes failing to reach our server --- CHANGELOG.md | 4 ++++ example/pubspec.lock | 13 +++++++------ example/pubspec.yaml | 7 +++++++ lib/src/session.dart | 10 +++++++--- pubspec.yaml | 2 +- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2eb6fa..f9960ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,3 +31,7 @@ * Use simplifed `transcript` messages. * Expose `sendData` and `dataMessageNotifier` for bleeding edge use cases. * Update dependencies. + +# 0.0.8 + +* Send large data messages over our websocket instead of the WebRTC data channel to avoid dropped UDP packets. diff --git a/example/pubspec.lock b/example/pubspec.lock index 735e593..ebe9af0 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -82,12 +82,13 @@ packages: source: hosted version: "1.0.8" dart_webrtc: - dependency: transitive + dependency: "direct overridden" description: - name: dart_webrtc - sha256: c664ad88d5646735753add421ee2118486c100febef5e92b7f59cdbabf6a51f6 - url: "https://pub.dev" - source: hosted + path: "." + ref: HEAD + resolved-ref: e78507fdcc2b46621a389607e16f92fa942befd7 + url: "https://github.com/flutter-webrtc/dart-webrtc.git" + source: git version: "1.4.9" dbus: dependency: transitive @@ -475,7 +476,7 @@ packages: path: ".." relative: true source: path - version: "0.0.7" + version: "0.0.8" uuid: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 38984dc..a5d7e41 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -23,3 +23,10 @@ dev_dependencies: flutter: uses-material-design: true + +# Temporary fix for flutter 3.27.0 incompatibility with dart_webrtc 1.4.9 +dependency_overrides: + dart_webrtc: + git: + url: https://github.com/flutter-webrtc/dart-webrtc.git + ref: f27d27c7af41ceeebe31b295af4fb38e7b4d793e diff --git a/lib/src/session.dart b/lib/src/session.dart index c669312..4474803 100644 --- a/lib/src/session.dart +++ b/lib/src/session.dart @@ -5,7 +5,7 @@ import 'package:livekit_client/livekit_client.dart' as lk; import 'package:web_socket_channel/web_socket_channel.dart'; import 'dart:convert'; -const ultravoxSdkVersion = '0.0.7'; +const ultravoxSdkVersion = '0.0.8'; /// The current status of an [UltravoxSession]. enum UltravoxSessionStatus { @@ -320,8 +320,12 @@ class UltravoxSession { throw Exception("Data must contain a 'type' key"); } final message = jsonEncode(data); - await _room.localParticipant - ?.publishData(utf8.encode(message), reliable: true); + final messageBytes = utf8.encode(message); + if (messageBytes.length > 1024) { + _wsChannel.sink.add(message); + } else { + await _room.localParticipant?.publishData(messageBytes, reliable: true); + } } Future _disconnect() async { diff --git a/pubspec.yaml b/pubspec.yaml index ebb2e41..885d80b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: ultravox_client description: "Flutter client SDK for Ultravox." -version: 0.0.7 +version: 0.0.8 homepage: https://ultravox.ai repository: https://github.com/fixie-ai/ultravox-client-sdk-flutter topics: