Browse Source

修复release下js调用dart报错

melon 2 years ago
parent
commit
72235163e5

+ 11 - 3
assets/wwwroot/source.html

@@ -57,7 +57,7 @@
             });
         }
 
-        async function load(url) {
+        function load(url) {
             const player = new NodePlayer();
             let playing = false;
             // 开启屏幕常亮
@@ -110,7 +110,10 @@
         }
         // 通知Flutter
         function emit(name) {
-            const args = Array.from(arguments).slice(1);
+            let args = Array.from(arguments).slice(1);
+            if (args.length === 0) {
+                args.push('_');//release下 js 调 dart必须有入参,否则报错
+            }
             if (!!window.flutter_inappwebview) {
                 window.flutter_inappwebview.callHandler(name, ...args);
             } else {
@@ -119,7 +122,12 @@
                     fn();
                 } else {
                     if (args.length === 1) {
-                        fn(args[0]);
+                        let data = args[0];
+                        if (data instanceof Object) {
+                            fn(JSON.stringify(data));
+                        } else {
+                            fn(data);
+                        }
                     } else {
                         fn(JSON.stringify(args));
                     }

+ 1 - 1
example/lib/main.dart

@@ -36,7 +36,7 @@ class _MyHomePageState extends State<MyHomePage> {
 
   final controller = LiveController(
     source: LiveSource(
-      "https://liveplay.fis.plus/live/v37zag99oz8d0xgtg5ecj4xff5.flv",
+      "http://liveplay.fis.plus/live/71678_4c08d218d5ddb3f374c5af26c75392cd.flv",
     ),
   );
 

+ 4 - 4
lib/widgets/single/single_view_io.dart

@@ -53,10 +53,10 @@ class _SingleChannelViewState extends State<SingleChannelView> {
         c.addJavaScriptHandler(handlerName: 'onBuffering', callback: _onError);
       },
       onLoadStop: (c, url) {},
-      // onConsoleMessage: (c, consoleMessage) {
-      //   print(
-      //       "[WebView Console][${consoleMessage.messageLevel}] ${consoleMessage.message}");
-      // },
+      onConsoleMessage: (c, consoleMessage) {
+        print(
+            "[WebView Console][${consoleMessage.messageLevel}] ${consoleMessage.message}");
+      },
     );
   }
 

+ 4 - 1
lib/widgets/single/single_view_web.dart

@@ -1,3 +1,5 @@
+import 'dart:convert';
+
 import 'package:fis_live/controller/adapters/single/adapter_web.dart';
 import 'package:fis_live/controller/controller.dart';
 import 'package:fis_live/controller/exception.dart';
@@ -108,9 +110,10 @@ class _SingleChannelViewState extends State<SingleChannelView> {
   }
 
   dynamic _onError(dynamic args) {
+    final error = jsonDecode(args as String);
     controller.errorOccurred.emit(
       this,
-      FLivePlayerException(args['code'], args['msg']),
+      FLivePlayerException(error['code'], error['msg']),
     );
   }
 }