From 24ebb0583684a7bd918cfdb18d7844973f292f88 Mon Sep 17 00:00:00 2001 From: Robert Sutton Date: Wed, 8 Jan 2020 10:08:34 +1100 Subject: [PATCH] fix for android build issue --- example/lib/main.dart | 4 +-- example/lib/src/callscreen.dart | 20 ++++++------- example/lib/src/utils/dart_html_dummy.dart | 12 ++++++++ example/lib/src/utils/key_value_store.dart | 2 +- .../lib/src/utils/key_value_store_web.dart | 6 ++-- lib/src/dialog.dart | 2 +- lib/src/logger.dart | 2 +- lib/src/web_socket_dummy.dart | 29 +++++++++++++++++++ lib/src/websocket_interface.dart | 3 +- lib/src/websocket_web_impl.dart | 4 +-- 10 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 example/lib/src/utils/dart_html_dummy.dart create mode 100644 lib/src/web_socket_dummy.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 5344a856..4a3a39a2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,3 @@ -import 'dart:io'; import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride; @@ -11,8 +10,9 @@ import 'src/callscreen.dart'; import 'src/about.dart'; void main() { - if (WebRTC.platformIsDesktop) + if (WebRTC.platformIsDesktop) { debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia; + } runApp(MyApp()); } diff --git a/example/lib/src/callscreen.dart b/example/lib/src/callscreen.dart index a0610ea7..312f0a0c 100644 --- a/example/lib/src/callscreen.dart +++ b/example/lib/src/callscreen.dart @@ -159,7 +159,7 @@ class _MyCallScreenWidget extends State } void _handelStreams(CallState event) async { - var stream = event.stream; + MediaStream stream = event.stream; if (event.originator == 'local') { if (_localRenderer != null) { _localRenderer.srcObject = stream; @@ -238,16 +238,16 @@ class _MyCallScreenWidget extends State return AlertDialog( title: Text('Enter target to transfer.'), content: TextField( - onChanged: (String text) { - setState(() { - _tansfer_target = text; - }); - }, - decoration: InputDecoration( - hintText: 'URI or Username', - ), - textAlign: TextAlign.center, + onChanged: (String text) { + setState(() { + _tansfer_target = text; + }); + }, + decoration: InputDecoration( + hintText: 'URI or Username', ), + textAlign: TextAlign.center, + ), actions: [ FlatButton( child: Text('Ok'), diff --git a/example/lib/src/utils/dart_html_dummy.dart b/example/lib/src/utils/dart_html_dummy.dart new file mode 100644 index 00000000..6d76d8bc --- /dev/null +++ b/example/lib/src/utils/dart_html_dummy.dart @@ -0,0 +1,12 @@ +/* + * Theses classes simply serve to remove compile errors + * when building for a flutter environment + */ +class Storage { + Map store = Map(); + + String operator [](String key) => store[key]; + operator []=(String key, String value) => store[key] = value; +} + +dynamic window; diff --git a/example/lib/src/utils/key_value_store.dart b/example/lib/src/utils/key_value_store.dart index 56e5eb5e..e2def1c2 100644 --- a/example/lib/src/utils/key_value_store.dart +++ b/example/lib/src/utils/key_value_store.dart @@ -5,7 +5,7 @@ class KeyValueStore { KeyValueStore(); SharedPreferences _preferences; - init() async { + void init() async { _preferences = await SharedPreferences.getInstance(); } diff --git a/example/lib/src/utils/key_value_store_web.dart b/example/lib/src/utils/key_value_store_web.dart index 0fc445a4..dacb2886 100644 --- a/example/lib/src/utils/key_value_store_web.dart +++ b/example/lib/src/utils/key_value_store_web.dart @@ -1,13 +1,13 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:html'; +import 'dart_html_dummy.dart' if (dart.library.js) 'dart:html'; class KeyValueStore { KeyValueStore(); Storage _storage; - init() async { - _storage = window.localStorage; + void init() async { + _storage = window.localStorage as Storage; } String getString(String key) => _storage[key]; diff --git a/lib/src/dialog.dart b/lib/src/dialog.dart index 123c7e58..d44f95d0 100644 --- a/lib/src/dialog.dart +++ b/lib/src/dialog.dart @@ -236,7 +236,7 @@ class Dialog { } else if (request.cseq > this._remote_seqnum) { this._remote_seqnum = request.cseq; } - EventManager eventHandlers = request.server_transaction as EventManager; + EventManager eventHandlers = request.server_transaction; // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-. if (request.method == SipMethod.INVITE || (request.method == SipMethod.UPDATE && request.body != null)) { diff --git a/lib/src/logger.dart b/lib/src/logger.dart index e3833270..0afad566 100644 --- a/lib/src/logger.dart +++ b/lib/src/logger.dart @@ -114,7 +114,7 @@ class MyLogPrinter extends LogPrinter { for (Stackframe frame in frames.frames) { i++; var path2 = frame.sourceFile.path; - if (!path2.contains(Log._localPath)) { + if (!path2.contains(Log._localPath) && !path2.contains("logger.dart")) { depth = i - 1; break; } diff --git a/lib/src/web_socket_dummy.dart b/lib/src/web_socket_dummy.dart new file mode 100644 index 00000000..a66edae2 --- /dev/null +++ b/lib/src/web_socket_dummy.dart @@ -0,0 +1,29 @@ +/* + * Theses classes simply serve to remove compile errors + * when building for a flutter environment + */ + +class WebSocket { + static var OPEN; + static var CONNECTING; + + WebSocket(String url, String s); + + get onOpen => null; + + get onMessage => null; + + get onClose => null; + + get readyState => null; + + void send(data) {} + + void close() {} +} + +class Blob {} + +dynamic callMethod(var a, var b, var c) {} + +Future promiseToFuture(var promise) {} diff --git a/lib/src/websocket_interface.dart b/lib/src/websocket_interface.dart index fddfe0f1..91ca4502 100644 --- a/lib/src/websocket_interface.dart +++ b/lib/src/websocket_interface.dart @@ -120,7 +120,8 @@ class WebSocketInterface implements Socket { this._ws.close(); } } catch (error) { - logger.error('close() | error closing the WebSocket: ' + error); + logger + .error('close() | error closing the WebSocket: ' + error.toString()); } } diff --git a/lib/src/websocket_web_impl.dart b/lib/src/websocket_web_impl.dart index b4ead7b5..cfdb32ca 100644 --- a/lib/src/websocket_web_impl.dart +++ b/lib/src/websocket_web_impl.dart @@ -1,5 +1,5 @@ -import 'dart:html'; -import 'dart:js_util' as JSUtils; +import 'web_socket_dummy.dart' if (dart.library.js) 'dart:html'; +import 'web_socket_dummy.dart' if (dart.library.js) 'dart:js_util' as JSUtils; import 'logger.dart'; typedef void OnMessageCallback(dynamic msg);