From a31054cc2f882d12024c814838f677776dffae9a Mon Sep 17 00:00:00 2001 From: Jumper Chen Date: Tue, 5 May 2020 14:58:50 +0800 Subject: [PATCH] Fix #72 Can't send Iterable as one packet --- CHANGELOG.md | 6 ++++++ lib/src/engine/transport/io_websocket_transport.dart | 7 ++++++- lib/src/socket.dart | 6 +++++- pubspec.yaml | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e968f13..222541c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.9.10 + +**Bug fix:** + +* [#72](https://github.com/rikulo/socket.io-client-dart/issues/72) Can't send Iterable as one packet + ## 0.9.9 **Bug fix:** diff --git a/lib/src/engine/transport/io_websocket_transport.dart b/lib/src/engine/transport/io_websocket_transport.dart index 6afe687..d0868fa 100644 --- a/lib/src/engine/transport/io_websocket_transport.dart +++ b/lib/src/engine/transport/io_websocket_transport.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'dart:io'; +import 'dart:typed_data'; //import 'dart:html'; import 'package:logging/logging.dart'; import 'package:socket_io_client/src/engine/transport/transport.dart'; @@ -97,7 +98,11 @@ class IOWebSocketTransport extends Transport { // throw an error try { // TypeError is thrown when passing the second argument on Safari - ws.add(data); + if (data is ByteBuffer) { + ws.add(data.asUint8List()); + } else { + ws.add(data); + } } catch (e) { _logger.fine('websocket closed before onclose event'); } diff --git a/lib/src/socket.dart b/lib/src/socket.dart index f14f213..3b79e92 100644 --- a/lib/src/socket.dart +++ b/lib/src/socket.dart @@ -1,3 +1,5 @@ +import 'dart:typed_data'; + /// /// socket.dart /// @@ -142,7 +144,9 @@ class Socket extends EventEmitter { super.emit(event, data); } else { var sendData = [event]; - if (data is Iterable) { + if (data is ByteBuffer || data is List) { + sendData.add(data); + } else if (data is Iterable) { sendData.addAll(data); } else if (data != null) { sendData.add(data); diff --git a/pubspec.yaml b/pubspec.yaml index 05de8d9..2ad0d8d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: socket_io_client description: Dartlang port of socket.io-client for web, flutter, dartvm to use -version: 0.9.9 +version: 0.9.10 author: jumperchen homepage: https://www.zkoss.org repository: https://github.com/rikulo/socket.io-client-dart @@ -11,7 +11,7 @@ environment: dependencies: logging: ^0.11.3+2 - socket_io_common: ">=0.9.0+5 <2.0.0" + socket_io_common: ">=0.9.2 <2.0.0" dev_dependencies: test: ">=1.3.0 <2.0.0"