diff --git a/flutter_theolive_sdk/CHANGELOG.md b/flutter_theolive_sdk/CHANGELOG.md index 49f2a3a..0e9922f 100644 --- a/flutter_theolive_sdk/CHANGELOG.md +++ b/flutter_theolive_sdk/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.0.1 + +* Updated documentation. +* Consumed Pigeon communication errors internally. +* Introduced experimental `THEOLogger.instance.logger(THEOLoggerCallback? callback)` to listen for Pigeon errors. + ## 1.0.0 * Initial release. \ No newline at end of file diff --git a/flutter_theolive_sdk/example/ios/Podfile.lock b/flutter_theolive_sdk/example/ios/Podfile.lock index 59dcf20..82d3636 100644 --- a/flutter_theolive_sdk/example/ios/Podfile.lock +++ b/flutter_theolive_sdk/example/ios/Podfile.lock @@ -1,5 +1,7 @@ PODS: - Flutter (1.0.0) + - integration_test (0.0.1): + - Flutter - theolive_ios (0.0.1): - Flutter - THEOliveSDK (= 3.13.1) @@ -7,6 +9,7 @@ PODS: DEPENDENCIES: - Flutter (from `Flutter`) + - integration_test (from `.symlinks/plugins/integration_test/ios`) - theolive_ios (from `.symlinks/plugins/theolive_ios/ios`) SPEC REPOS: @@ -16,11 +19,14 @@ SPEC REPOS: EXTERNAL SOURCES: Flutter: :path: Flutter + integration_test: + :path: ".symlinks/plugins/integration_test/ios" theolive_ios: :path: ".symlinks/plugins/theolive_ios/ios" SPEC CHECKSUMS: Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + integration_test: 13825b8a9334a850581300559b8839134b124670 theolive_ios: 2896de0407753d35182217612388d009cda836bd THEOliveSDK: 37f625222047a9da4a471db45bbb26bfd8768dee diff --git a/flutter_theolive_sdk_platform_interface/lib/debug_helpers.dart b/flutter_theolive_sdk_platform_interface/lib/debug_helpers.dart index 4f74501..969f302 100644 --- a/flutter_theolive_sdk_platform_interface/lib/debug_helpers.dart +++ b/flutter_theolive_sdk_platform_interface/lib/debug_helpers.dart @@ -5,3 +5,53 @@ void dprint(Object? object) { print(object); } } + +void exceptionHandler({required String tag, required Exception exception, String? context = null, StackTrace? stacktrace = null}) { + if (kDebugMode) { + throw exception; + } else { + final prefix = "[$tag]"; + final ctx = context != null ? "[C:$context]" : ""; + var logMessage = "THEOLogger$prefix$ctx - Exception happened: $exception"; + if (!THEOLogger.instance.isListening()) { + logMessage += " - for more info, attach a logger to THEOLogger.instance!"; + } + print(logMessage); + THEOLogger.instance._log(exception, stacktrace); + } +} + +/** + * Logger class to capture logs and exceptions + * NOTE: + * - Experimental + * - Only used to catch PlatformExceptions for now + */ +class THEOLogger { + + THEOLoggerCallback? _loggerCallback; + + THEOLoggerCallback? get logger { + return _loggerCallback; + } + + void set logger(THEOLoggerCallback? callback) { + _loggerCallback = callback; + } + + static final THEOLogger instance = THEOLogger._constructor(); + THEOLogger._constructor(); + + void _log(Exception e, StackTrace? stackTrace) { + _loggerCallback?.onException(e, stackTrace ?? StackTrace.current ); + } + + bool isListening() { + return _loggerCallback != null; + } + +} + +abstract class THEOLoggerCallback { + void onException(Exception e, StackTrace stackTrace); +} \ No newline at end of file diff --git a/flutter_theolive_sdk_platform_interface/lib/theolive_view_controller_mobile.dart b/flutter_theolive_sdk_platform_interface/lib/theolive_view_controller_mobile.dart index 0a99b09..7d1a418 100644 --- a/flutter_theolive_sdk_platform_interface/lib/theolive_view_controller_mobile.dart +++ b/flutter_theolive_sdk_platform_interface/lib/theolive_view_controller_mobile.dart @@ -25,70 +25,84 @@ class THEOliveViewControllerMobile extends THEOliveViewController implements THE @override void preloadChannels(List list) { - _nativeAPI.preloadChannels(list); + _nativeAPI.preloadChannels(list) + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void loadChannel(String channelId) { - _nativeAPI.loadChannel(channelId).onError((error, stackTrace) => - //consume the exception, it is irrelevant to the flow, just for information - dprint("ERROR during loadChannel: $error")); + _nativeAPI.loadChannel(channelId) + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } - + @override void play() { - _nativeAPI.play(); + _nativeAPI.play() + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void pause() { - _nativeAPI.pause(); + _nativeAPI.pause() + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override Future isAutoplay() { - return _nativeAPI.isAutoplay(); + return _nativeAPI.isAutoplay() + .onError((error, stackTrace) { + exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace); + return false; + }); } @override void setMuted(bool muted) { - _nativeAPI.setMuted(muted); + _nativeAPI.setMuted(muted) + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void setBadNetworkMode(bool badNetworkMode) { - _nativeAPI.setBadNetworkMode(badNetworkMode); + _nativeAPI.setBadNetworkMode(badNetworkMode) + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void goLive() { - _nativeAPI.goLive(); + _nativeAPI.goLive() + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void reset() { - _nativeAPI.reset(); + _nativeAPI.reset() + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void updateNativePlayerConfiguration(NativePlayerConfiguration configuration) { final nativeConfig = PigeonNativePlayerConfiguration(sessionId: configuration.sessionId); - _nativeAPI.updateConfiguration(nativeConfig); + _nativeAPI.updateConfiguration(nativeConfig) + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void dispose() { - _nativeAPI.destroy(); + _nativeAPI.destroy() + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void onLifecycleResume() { - _nativeAPI.onLifecycleResume(); + _nativeAPI.onLifecycleResume() + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override void onLifecyclePause() { - _nativeAPI.onLifecyclePause(); + _nativeAPI.onLifecyclePause() + .onError((error, stackTrace) => exceptionHandler(exception: error, tag: "PIGEON", stacktrace: stackTrace)); } @override