From e7c60497ad3e4b8d62092264864e5b83adccbe5f Mon Sep 17 00:00:00 2001 From: apple <> Date: Thu, 11 Aug 2022 18:30:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=89=93=E5=8C=85apk?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=BF=A1=E6=81=AF=E5=92=8C?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 29 +++++- lib/views/createRoom/CreateRoom.dart | 10 +- lib/views/palRoom/PalRoom.dart | 137 +++++++++++++++++---------- lib/views/party/Party.dart | 2 +- 4 files changed, 118 insertions(+), 60 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index fe3f8ee..114a6a0 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -25,6 +25,10 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" +def keystorePropertiesFile = rootProject.file("key.properties") +def keystoreProperties = new Properties() +keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) + android { compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion @@ -48,18 +52,37 @@ android { // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. minSdkVersion flutter.minSdkVersion - targetSdkVersion flutter.targetSdkVersion + // targetSdkVersion flutter.targetSdkVersion + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } + signingConfigs { + release { + keyAlias keystoreProperties['keyAlias'] + keyPassword keystoreProperties['keyPassword'] + storeFile file(keystoreProperties['storeFile']) + storePassword keystoreProperties['storePassword'] + } + } + buildTypes { release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.release + } + debug { signingConfig signingConfigs.debug } } + + // buildTypes { + // release { + // // TODO: Add your own signing config for the release build. + // // Signing with the debug keys for now, so `flutter run --release` works. + // signingConfig signingConfigs.debug + // } + // } } flutter { diff --git a/lib/views/createRoom/CreateRoom.dart b/lib/views/createRoom/CreateRoom.dart index f1542a9..8ce1cd2 100644 --- a/lib/views/createRoom/CreateRoom.dart +++ b/lib/views/createRoom/CreateRoom.dart @@ -84,17 +84,13 @@ class _CreateRoomPageState extends State { _onJoin(agoraToken, userName, roomId, ClientRole.Broadcaster); - // Future.delayed(Duration(seconds: 3), () { - // _onJoin(agoraToken, userName, roomId, ClientRole.Broadcaster); - // }); - // if (agoraToken != null && agoraToken.isNotEmpty) { // _engine = await RtcEngine.create(APP_ID); // 初始化引擎 // _engine.joinChannel(agoraToken, roomId, null, int.parse(uid)); // 加入频道 - // timer = Timer.periodic(Duration(seconds: 1), (timer) async { - // _lodingCreate(agoraToken); - // }); + // timer = Timer.periodic(Duration(seconds: 1), (timer) async { + // _lodingCreate(agoraToken); + // }); // } } diff --git a/lib/views/palRoom/PalRoom.dart b/lib/views/palRoom/PalRoom.dart index 7b60ca1..2382b83 100644 --- a/lib/views/palRoom/PalRoom.dart +++ b/lib/views/palRoom/PalRoom.dart @@ -54,7 +54,7 @@ class _PalRoomPageState extends State { late RtcEngine _engine; // RtcEngine 声网实例变量 late IOWebSocketChannel _wsChannel; // webSocket 实例变量 - + late Timer timer; // 轮询定时器 // 房间座位 List _list = [ {'nickname': '', 'flag': false, 'image': 'images/palRoom/voice2.png'}, @@ -75,14 +75,6 @@ class _PalRoomPageState extends State { super.initState(); initialize(); - - // if (widget.role == ClientRole.Broadcaster) { - // _infoStrings.insert(0, {'type': 'system', 'content': '您身份为主播,已经上麦状态'}); - // } else if (widget.role == ClientRole.Audience) { - // _infoStrings.insert(0, {'type': 'system', 'content': '您身份为观众,点击麦克风图标上麦'}); - // } - - wsInitalize(); } @override @@ -92,14 +84,15 @@ class _PalRoomPageState extends State { _engine.leaveChannel(); _engine.destroy(); _wsChannel.sink.close(); + timer.cancel(); } Future initialize() async { - _infoStrings.insert(0, { - 'type': 'system', - 'content': - '|令牌:${widget.agoraToken}|用户名:${widget.userName}|房间:${widget.channelName}|身份:${widget.role}' - }); + // _infoStrings.insert(0, { + // 'type': 'system', + // 'content': + // '|令牌:${widget.agoraToken}|用户名:${widget.userName}|房间:${widget.channelName}|身份:${widget.role}' + // }); // 判断appid是否存在 if (APP_ID.isEmpty) { @@ -113,6 +106,12 @@ class _PalRoomPageState extends State { return; } + if (widget.role == ClientRole.Broadcaster) { + _infoStrings.insert(0, {'type': 'system', 'content': '您身份为主播,已经上麦状态'}); + } else if (widget.role == ClientRole.Audience) { + _infoStrings.insert(0, {'type': 'system', 'content': '您身份为观众,点击麦克风图标上麦'}); + } + _engine = await RtcEngine.create(APP_ID); // 初始化引擎 await _engine.enableAudio(); // 启用音频模块 await _engine.setDefaultAudioRouteToSpeakerphone( @@ -120,35 +119,62 @@ class _PalRoomPageState extends State { await _engine.setAudioProfile(AudioProfile.SpeechStandard, AudioScenario.ChatRoomEntertainment); // 设置音频编码属性和音频场景 await _engine.setChannelProfile(ChannelProfile.LiveBroadcasting); + await _engine.setClientRole(widget.role!); _addAgoraEventHandlers(); // 调用状态文字信息列表方法 - if (widget.role == ClientRole.Broadcaster) { - await _engine.setClientRole(ClientRole.Broadcaster); - } + // if (widget.role == ClientRole.Broadcaster) { + // await _engine.setClientRole(ClientRole.Broadcaster); + // } String uid = await Storage.get('id'); await _engine.joinChannel( widget.agoraToken, widget.channelName, null, int.parse(uid)); // 加入频道 - _detail(); + timer = Timer.periodic(Duration(seconds: 1), (timer) async { + _lodingCreate(); + }); } - wsInitalize() async { - String uid = await Storage.get('id'); - _wsChannel = IOWebSocketChannel.connect( - 'ws://101.35.117.69:9093/chat/api/chat/room/${int.parse(uid)}'); // 建立链接 + void _lodingCreate() async { + var res = + await MyHttpUtil().get("/chat/api/room/create/${widget.channelName}"); + String userName = await Storage.get('userName'); // 用户名 + print('_lodingCreate:${res.data}'); + if (res.data == true) { + timer.cancel(); + wsInitalize(); + _detail(); + } + } + + Future wsInitalize() async { + Map headers = new Map(); + var token = await Storage.get('token'); + + print('/=/=/=/=/=//=/=/=/=/=//=/=/=/=/=//=/=/=/=/=/'); + + headers['Authorization'] = 'Bearer ${token}'; + + print(headers); + print(widget.channelName); + + _wsChannel = IOWebSocketChannel.connect( + 'ws://101.35.117.69:9093/chat/api/chat/room/${widget.channelName}', + headers: headers, + ); // 建立链接 + + print('/=/=/=/=/=//=/=/=/=/=//=/=/=/=/=//=/=/=/=/=/'); - print('object'); _wsChannel.stream.listen((data) { - var aa = jsonDecode(data); - print('收到服务器数据:${aa}'); + var information = jsonDecode(data); + print('收到服务器数据:${information}'); setState(() { _infoStrings.insert(0, { 'type': 'speak', - 'content': '${aa['message']}', - 'name': '${aa['username']}' + 'content': '${information['message']}', + 'name': '${information['nickname']}' }); }); }, onDone: () { @@ -194,6 +220,12 @@ class _PalRoomPageState extends State { } print('-----------------${_list}-----------------'); + + // // 房间空无一人的时候返回首页 + // if (newUserList.isEmpty) { + // Navigator.of(context).pushReplacementNamed('/'); + // return; + // } } void _addAgoraEventHandlers() { @@ -209,7 +241,7 @@ class _PalRoomPageState extends State { _detail(); // 用户加入 setState(() { - final info = '用户加入: uid $uid'; + final info = '用户用户$uid加入房间'; _infoStrings.insert(0, {'type': 'system', 'content': info}); // _users.add(uid); }); @@ -218,7 +250,7 @@ class _PalRoomPageState extends State { _detail(); // 加入频道成功 setState(() { - final info = '加入频道成功: $channel, uid: $uid'; + final info = '用户$uid加入频道号$channel成功'; _infoStrings.insert(0, {'type': 'system', 'content': info}); }); }, @@ -234,7 +266,7 @@ class _PalRoomPageState extends State { _detail(); // 用户离开当前频道 setState(() { - final info = '用户离开当前频道: $uid , reason: $reason'; + final info = '用户$uid离开当前频道, reason: $reason'; _infoStrings.insert(0, {'type': 'system', 'content': info}); // _users.remove(uid); }); @@ -251,7 +283,7 @@ class _PalRoomPageState extends State { _detail(); // 成功重新加入频道回调 setState(() { - final info = '用户成功重新加入: $uid'; + final info = '用户$uid重新加入成功'; _infoStrings.insert(0, {'type': 'system', 'content': info}); // _users.add(uid); }); @@ -330,6 +362,12 @@ class _PalRoomPageState extends State { // 下麦再将身份改回为观众(下麦不代表离开频道) _engine.setClientRole(ClientRole.Audience); Navigator.pop(context); + + // // 房间空无一人的时候返回首页 + if (newUserList.isEmpty) { + Navigator.of(context).pushReplacementNamed('/'); + return; + } }, ), ListTile( @@ -383,7 +421,8 @@ class _PalRoomPageState extends State { ), ), SizedBox(width: 5), - Text('以冬', style: TextStyle(color: Colors.white, fontSize: 14)), + Text(_list.length > 0 ? _list[0]['nickname'] : '加入中', + style: TextStyle(color: Colors.white, fontSize: 14)), ], ), ), @@ -578,27 +617,16 @@ class _PalRoomPageState extends State { ), child: TextField( textInputAction: TextInputAction.send, // 键盘右下角图标 - // onEditingComplete: () async { - // late String speak = _controller.text.trim(); - // if (speak.isEmpty) { - // showToast("请输入聊天内容~"); - // return; - // } - // String userName = await Storage.get('userName'); // 用户名 - - // _wsChannel.sink.add(speak); - - // // _controller.text = ''; - // }, - onSubmitted: (value) async { - late String speak = value.trim(); + onSubmitted: (value) { + late String speak = _controller.text.trim(); if (speak.isEmpty) { showToast("请输入聊天内容~"); return; } - String userName = await Storage.get('userName'); // 用户名 - + print(speak); _wsChannel.sink.add(speak); + + _controller.clear(); }, controller: _controller, decoration: InputDecoration( @@ -618,6 +646,17 @@ class _PalRoomPageState extends State { ), GestureDetector( // 加号图标 + onTap: () { + late String speak = _controller.text.trim(); + if (speak.isEmpty) { + showToast("请输入聊天内容~"); + return; + } + print(speak); + _wsChannel.sink.add(speak); + + _controller.clear(); + }, child: Icon(Icons.add, color: Color.fromRGBO(201, 201, 201, 1), size: 25.0), ), @@ -670,7 +709,7 @@ class _PalRoomPageState extends State { Row( children: [ Text( - '以冬', + _list.length > 0 ? _list[0]['nickname'] : '加入中', style: TextStyle(color: Colors.white, fontSize: 12), ), SizedBox(width: 5), diff --git a/lib/views/party/Party.dart b/lib/views/party/Party.dart index 061c0d1..ee97901 100644 --- a/lib/views/party/Party.dart +++ b/lib/views/party/Party.dart @@ -389,7 +389,7 @@ class _ViewsWidgetState extends State { ), SizedBox(width: 5), Text( - _data[index]['id'], + '${_data[index]['userCount']}人', overflow: TextOverflow.ellipsis, style: TextStyle( color: Color.fromRGBO(