Browse Source

update client tools

arthur.wu 2 years ago
parent
commit
5dd6aca5d6

+ 20 - 1
Tools/TestTools/client/lib/ConsultationList.dart

@@ -3,11 +3,14 @@ import 'dart:convert';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:get_it/get_it.dart';
+import 'package:provider/provider.dart';
 import 'package:sprintf/sprintf.dart';
 import 'package:http/http.dart' as http;
+import 'package:tencent_trtc_cloud/trtc_cloud_def.dart';
 
 import 'ApprovalConsultationScreen.dart';
 import 'Services/ConsultationService.dart';
+import 'models/meeting.dart';
 
 class ConsultationList extends StatefulWidget {
   ConsultationList({Key? key, required this.token, required this.consultations})
@@ -168,7 +171,23 @@ class _ConsultationListState extends State<ConsultationList> {
       var service = GetIt.instance.get<ConsultationService>();
 
       var result = await service.InitiateLiveConsultationAsync(id);
-      print("InitiateLiveConsultationAsync");
+      var sdkAppId = result['AppId'];
+      var userSign = result['UserSign'] as String;
+      var initializeCode = result['InitiatorCode'] as String;
+      var roomId = result['RoomNo'];
+
+      print("sdkAppId: $sdkAppId, userSign: $userSign");
+      var meetModel = context.read<MeetingModel>();
+      meetModel.setUserSettig({
+        "appId": sdkAppId,
+        "userSig": userSign,
+        "meetId": roomId,
+        "userId": initializeCode,
+        "enabledCamera": true,
+        "enabledMicrophone": true,
+        "quality": TRTCCloudDef.TRTC_AUDIO_QUALITY_SPEECH
+      });
+      Navigator.of(context).pushNamed('/meeting');
     } catch (ex) {
       print('OnStartLiveConsultation.to ex' + ex.toString());
     }

+ 19 - 28
Tools/TestTools/client/lib/Services/ConsultationService.dart

@@ -17,7 +17,7 @@ import 'package:intl/intl.dart';
 import 'package:event/event.dart';
 
 class NotificationReceivedArgs extends EventArgs {
-  Map<String, dynamic> jsonMessage;
+  dynamic jsonMessage;
 
   NotificationReceivedArgs(this.jsonMessage);
 }
@@ -26,7 +26,7 @@ class ConsultationService {
   Event<NotificationReceivedArgs> NotificationReceived =
       Event<NotificationReceivedArgs>();
 
-  RaiseConsultationNotificationReceived(Map<String, dynamic> jsonMessage) {
+  RaiseConsultationNotificationReceived(dynamic jsonMessage) {
     NotificationReceived.broadcast(NotificationReceivedArgs(jsonMessage));
   }
 
@@ -77,23 +77,18 @@ class ConsultationService {
     var organs = organSource.map<String>((json) => json.toString()).toList()
         as List<String>;
 
- 
-    
     body =
         '{"jsonrpc": "2.0", "method": "GetUserListAsync", "params": [{"Token": "$token", "OrganizationCode": "$orgCode","OrganizationQueryType":3,"ExceptSelf":true}], "id": 1 }';
     print('GetUserListAsync http.Client()' + body);
-    response = await client.post(
-        Uri.parse(AppSettings.host + '/IUserService'),
+    response = await client.post(Uri.parse(AppSettings.host + '/IUserService'),
         body: body);
 
-   
     print('GetUserListAsync response.body' + response.body);
     parsed = jsonDecode(response.body);
     datas = parsed['result'];
     final users = datas.map<Expert>((json) => Expert.fromJson(json)).toList()
         as List<Expert>;
 
-
     var model = new AppConsultationDataModel(experts, devices, organs, users);
     return model;
   }
@@ -191,6 +186,9 @@ class ConsultationService {
     var parsed =
         decodeResponseBody('InitiateLiveConsultationAsync', response.bodyBytes);
     var data = parsed['result'];
+    print("begin RaiseConsultationNotificationReceived");
+    RaiseConsultationNotificationReceived(data);
+    print("end RaiseConsultationNotificationReceived");
     return data;
   }
 
@@ -230,16 +228,14 @@ class ConsultationService {
     return data;
   }
 
-
-
   Future<bool> ApprovalConsultationAsync(
-    ApprovalConsultationRequest model) async {
-    String consultationCode=model.consultationCode;
-    String expertUserCode =model.expertUserCode;
-    DateTime consultationTime=model.consultationTime;
-    List<String> consultationMemberCodes=<String>[];
+      ApprovalConsultationRequest model) async {
+    String consultationCode = model.consultationCode;
+    String expertUserCode = model.expertUserCode;
+    DateTime consultationTime = model.consultationTime;
+    List<String> consultationMemberCodes = <String>[];
     model.consultationMemberCodes.forEach((element) {
-      consultationMemberCodes.add('"'+element+'"');
+      consultationMemberCodes.add('"' + element + '"');
     });
     var userService = GetIt.instance.get<UserService>();
     var user = userService.getCurrentUser();
@@ -253,7 +249,8 @@ class ConsultationService {
     var response = await client.post(
         Uri.parse(AppSettings.host + '/ILiveConsultationService'),
         body: body);
-    var parsed = decodeResponseBody('ApprovalConsultationAsync', response.bodyBytes);
+    var parsed =
+        decodeResponseBody('ApprovalConsultationAsync', response.bodyBytes);
     var data = parsed['result'];
     return data;
   }
@@ -265,7 +262,7 @@ class AppConsultationDataModel {
   final List<String> organs;
   final List<Expert> users;
 
-  AppConsultationDataModel(this.experts, this.devices, this.organs,this.users);
+  AppConsultationDataModel(this.experts, this.devices, this.organs, this.users);
 }
 
 class TokenRequest {
@@ -373,7 +370,6 @@ class Organ {
 }
 
 class ApprovalConsultationRequest extends TokenRequest {
-
   String consultationCode;
 
   String expertUserCode;
@@ -382,18 +378,13 @@ class ApprovalConsultationRequest extends TokenRequest {
 
   List<String> consultationMemberCodes;
 
-
-  ApprovalConsultationRequest(
-      this.consultationCode,
-      this.expertUserCode,
-      this.consultationTime,
-      this.consultationMemberCodes,
-      String token)
+  ApprovalConsultationRequest(this.consultationCode, this.expertUserCode,
+      this.consultationTime, this.consultationMemberCodes, String token)
       : super(token);
 
-      @override
+  @override
   String toString() {
     // TODO: implement toString
-     return 'consultationCode: $consultationCode,expertUserCode:$expertUserCode,consultationTime:$consultationTime,consultationMemberCodes:$consultationMemberCodes';
+    return 'consultationCode: $consultationCode,expertUserCode:$expertUserCode,consultationTime:$consultationTime,consultationMemberCodes:$consultationMemberCodes';
   }
 }

+ 53 - 38
Tools/TestTools/client/lib/Services/UserService.dart

@@ -42,6 +42,36 @@ class UserService {
     return currentUser;
   }
 
+  void UpdateCurrentUserDetail() async {
+    var user = getCurrentUser();
+    if (user != null) {
+      var token = user.accessToken;
+      var body = sprintf(
+          '{"jsonrpc": "2.0", "method": "GetUserInfoAsync", "params": [{"Token": "%s" }], "id": 1 }',
+          [token]);
+      var client = http.Client();
+      var response = await client
+          .post(Uri.parse(AppSettings.host + '/IUserService'), body: body);
+      print('GetUserInfoAsync response.body' + response.body);
+      var parsed = jsonDecode(response.body);
+      if (parsed != null) {
+        user.organizationCode = parsed['result']['OrganizationCode'];
+        var jsonUser = user.toJson();
+
+        this.storage.setItem(UserStroageKey, jsonUser);
+        var userAgenter = UserAgentClient(client, token);
+
+        print('jsonUser:' + jsonUser.toString());
+        var url = Uri.parse(AppSettings.host);
+        var wsUrl = 'ws://${url.host}:9301?token=$token';
+        print("wsUrl---" + wsUrl);
+        Channel = WebSocketChannel.connect(
+          Uri.parse(wsUrl),
+        );
+      }
+    }
+  }
+
   logout() {
     this.storage.deleteItem(UserStroageKey);
   }
@@ -59,33 +89,12 @@ class UserService {
     var parsed = jsonDecode(response.body);
     var token = parsed['result']['Token'];
     if (token != null) {
-      body = sprintf(
-          '{"jsonrpc": "2.0", "method": "GetUserInfoAsync", "params": [{"Token": "%s" }], "id": 1 }',
-          [token]);
-      response = await client
-          .post(Uri.parse(AppSettings.host + '/IUserService'), body: body);
-      print('GetUserInfoAsync response.body' + response.body);
-      var parsed = jsonDecode(response.body);
-      if (parsed != null) {
-        var organizationCode = parsed['result']['OrganizationCode'];
-        var user = new User(
-            userName: userName,
-            accessToken: token,
-            organizationCode: organizationCode);
-        var jsonUser = user.toJson();
+      var user = new User(
+          userName: userName, accessToken: token, organizationCode: '');
+      var jsonUser = user.toJson();
 
-        this.storage.setItem(UserStroageKey, jsonUser);
-        var userAgenter = UserAgentClient(client, token);
-
-        print('jsonUser:' + jsonUser.toString());
-        var url = Uri.parse(AppSettings.host);
-        print("object" + url.host);
-        Channel = WebSocketChannel.connect(
-          Uri.parse('ws://192.168.6.80:9301?token=${token}'),
-        );
-
-        return true;
-      }
+      this.storage.setItem(UserStroageKey, jsonUser);
+      return true;
     }
 
     return false;
@@ -109,9 +118,11 @@ class UserAgentClient extends http.BaseClient {
   final String token;
   late Timer? _timer;
   UserAgentClient(this._inner, this.token) {
+    print('heartrate client');
     //cancelTimer();
     final Duration duration = Duration(seconds: 300);
     _timer = Timer(duration, () => Run());
+    Run();
   }
 
   Future<http.StreamedResponse> send(http.BaseRequest request) {
@@ -121,19 +132,23 @@ class UserAgentClient extends http.BaseClient {
 
   void Run() {
     //cancelTimer();
-    var request =
-        http.Request('POST', Uri.parse(AppSettings.host + '/IUserService'));
-    request.body =
-        '{"jsonrpc": "2.0", "method": "HeartRateAsync", "params": [{"Token": "$token" }], "id": 1 }';
-    var response = send(request);
-
-    response.asStream().listen((event) {
-      print('heartrate response:${event.toString()}');
-    });
-    response.then(
-        (value) => {print('heartrate result:' + value.stream.toString())});
+    // var request =
+    //     http.Request('POST', Uri.parse(AppSettings.host + '/IUserService'));
+    // request.body =
+    //     '{"jsonrpc": "2.0", "method": "HeartRateAsync", "params": [{"Token": "$token" }], "id": 1 }';
+    print('heartrate send');
+    //Future<http.StreamedResponse> streamedResponse = send(request);
+    // Future.sync(() => send(request).then((value) =>
+    //     http.Response.fromStream(value)
+    //         .then((response) => print('heartrate response:${response.body}'))));
+    Future.sync(() => _inner
+        .post(Uri.parse(AppSettings.host + '/IUserService'),
+            body:
+                '{"jsonrpc": "2.0", "method": "HeartRateAsync", "params": [{"Token": "$token" }], "id": 1 }')
+        .then((response) => print('heartrate response:${response.body}')));
     //var parsed = jsonDecode(response.then((value) => {print(value)}));
     //return parsed['result'] as bool;
+    print('heartrate send done');
   }
 
   void cancelTimer() {
@@ -146,7 +161,7 @@ class JsonRpcResult {}
 class User {
   final String userName;
   final String accessToken;
-  final String organizationCode;
+  String organizationCode;
 
   User(
       {required this.userName,

+ 3 - 2
Tools/TestTools/client/lib/UserView.dart

@@ -31,6 +31,8 @@ class _UserView extends State<UserView> {
     if (user == null) {
       print("user is null");
       _showSignInScreen(context);
+    } else {
+      service.UpdateCurrentUserDetail();
     }
     var userName = user == null ? "" : user.userName;
     var accessToken = user == null ? "" : user.accessToken;
@@ -140,8 +142,7 @@ class _UserView extends State<UserView> {
                             Uint8List.fromList(messageConentList);
                         var messageText = Utf8Decoder().convert(messageConent);
                         //print("message text:" + messageText);
-                        Map<String, dynamic> messageObject =
-                            jsonDecode(messageText);
+                        var messageObject = jsonDecode(messageText);
                         //通知类型区分
                         if (messageObject["NotificationType"] as int ==
                             NotificationTypeEnum.ConnectionNotification.index) {

+ 13 - 8
Tools/TestTools/client/lib/main.dart

@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
 import 'package:ustest/ApplyConsultationScreen.dart';
 import 'package:ustest/Services/LocalStorageService.dart';
 import 'package:ustest/Services/UserService.dart';
@@ -7,8 +8,10 @@ import 'package:ustest/SignInScreen.dart';
 import 'package:ustest/MainScreen.dart';
 import 'package:get_it/get_it.dart';
 import 'package:colorize_logger/colorize_logger.dart';
+import 'package:ustest/meeting.dart';
 
 import 'Services/ConsultationService.dart';
+import 'models/meeting.dart';
 
 void main() {
   setup();
@@ -32,13 +35,15 @@ class MyApp extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
-    print("build MyApp");
-    return MaterialApp(
-      routes: {
-        '/': (context) => MainScreen(),
-        '/signin': (context) => const SignInScreen(),
-        '/applyconsultation': (context) => const ApplyConsultationScreen()      
-      },
-    );
+    return ChangeNotifierProvider(
+        create: (context) => MeetingModel(),
+        child: MaterialApp(
+          routes: {
+            '/': (context) => MainScreen(),
+            '/signin': (context) => const SignInScreen(),
+            '/meeting': (context) => MeetingPage(),
+            '/applyconsultation': (context) => const ApplyConsultationScreen()
+          },
+        ));
   }
 }

+ 30 - 21
Tools/TestTools/client/lib/meeting.dart

@@ -27,6 +27,8 @@ class MeetingPage extends StatefulWidget {
 }
 
 class MeetingPageState extends State<MeetingPage> with WidgetsBindingObserver {
+  MeetingPageState();
+
   final _scaffoldKey = GlobalKey<ScaffoldState>();
   var meetModel;
   var userInfo = {}; //Multiplayer video user list
@@ -63,21 +65,32 @@ class MeetingPageState extends State<MeetingPage> with WidgetsBindingObserver {
     meetModel = context.read<MeetingModel>();
     var userSetting = meetModel.getUserSetting();
     meetId = userSetting["meetId"];
-    var userService = GetIt.instance.get<UserService>();
-    //userService.currentUser?.userName
+    userInfo['appId'] = userSetting["appId"];
+    userInfo['userSig'] = userSetting["userSig"];
     userInfo['userId'] = userSetting["userId"];
     isOpenCamera = userSetting["enabledCamera"];
     isOpenMic = userSetting["enabledMicrophone"];
-    var consultationService = GetIt.instance.get<ConsultationService>();
-    consultationService.NotificationReceived.subscribe(
-      (args) {
-        iniRoom(0, '');
-        initScrollListener();
-      },
-    );
+
+    iniRoom();
+    initScrollListener();
+    // var consultationService = GetIt.instance.get<ConsultationService>();
+    // consultationService.NotificationReceived.subscribe(
+    //   (args) {
+    //     if (args != null) {
+    //       print("Sth. happened: ${args.jsonMessage?.toString()}");
+    //       var sdkAppId = int.tryParse(args.jsonMessage['AppId']) as int;
+    //       var userSign = args.jsonMessage['AppId'] as String;
+    //       var initializeCode = args.jsonMessage['InitiatorCode'] as String;
+    //       userInfo['userId'] = initializeCode;
+    //       print("sdkAppId: $sdkAppId, userSign: $userSign");
+    //       iniRoom(sdkAppId, userSign);
+    //       //initScrollListener();
+    //     }
+    //   },
+    // );
   }
 
-  iniRoom(int sdkAppId, String userSig) async {
+  iniRoom() async {
     // Create TRTCCloud singleton
     trtcCloud = (await TRTCCloud.sharedInstance())!;
     // Tencent Cloud Audio Effect Management Module
@@ -90,7 +103,7 @@ class MeetingPageState extends State<MeetingPage> with WidgetsBindingObserver {
     trtcCloud.registerListener(onRtcListener);
 
     // Enter the room
-    enterRoom(sdkAppId, userSig);
+    enterRoom();
 
     initData();
 
@@ -128,18 +141,10 @@ class MeetingPageState extends State<MeetingPage> with WidgetsBindingObserver {
   }
 
   // Enter the trtc room
-  enterRoom(int sdkAppId, String userSig) async {
-    try {
-      userInfo['userSig'] = userSig;
-      meetModel.setUserInfo(userInfo);
-    } catch (err) {
-      userInfo['userSig'] = '';
-      print(err);
-    }
-
+  enterRoom() async {
     await trtcCloud.enterRoom(
         TRTCParams(
-            sdkAppId: sdkAppId,
+            sdkAppId: userInfo['appId'],
             userId: userInfo['userId'],
             userSig: userInfo['userSig'],
             role: TRTCCloudDef.TRTCRoleAnchor,
@@ -148,6 +153,7 @@ class MeetingPageState extends State<MeetingPage> with WidgetsBindingObserver {
   }
 
   initData() async {
+    print('initData isOpenCamera:$isOpenCamera');
     if (isOpenCamera) {
       userList.add({
         'userId': userInfo['userId'],
@@ -194,6 +200,9 @@ class MeetingPageState extends State<MeetingPage> with WidgetsBindingObserver {
 
   /// Event callbacks
   onRtcListener(type, param) async {
+    print("onRtcListener");
+    print("onRtcListener type:$type, param:$param");
+
     if (type == TRTCCloudListener.onError) {
       if (param['errCode'] == -1308) {
         MeetingTool.toast('Failed to start screen recording', context);

File diff suppressed because it is too large
+ 0 - 0
Tools/TestTools/client/web/BeautyManagerWrapper.2.0.0-dev.0.0.2.bundle.js


File diff suppressed because it is too large
+ 0 - 0
Tools/TestTools/client/web/JsGenerateTestUserSig.2.0.0-dev.0.0.2.bundle.js


File diff suppressed because it is too large
+ 0 - 0
Tools/TestTools/client/web/TrtcWrapper.2.0.0-dev.0.0.2.bundle.js


+ 3 - 0
Tools/TestTools/client/web/index.html

@@ -22,6 +22,9 @@
   <meta name="apple-mobile-web-app-status-bar-style" content="black">
   <meta name="apple-mobile-web-app-title" content="ustest">
   <link rel="apple-touch-icon" href="icons/Icon-192.png">
+  <script src="JsGenerateTestUserSig.2.0.0-dev.0.0.2.bundle.js"></script>
+  <script src="TrtcWrapper.2.0.0-dev.0.0.2.bundle.js"></script>
+  <script src="BeautyManagerWrapper.2.0.0-dev.0.0.2.bundle.js"></script>
 
   <!-- Favicon -->
   <link rel="icon" type="image/png" href="favicon.png"/>

Some files were not shown because too many files changed in this diff