完善对讲功能
This commit is contained in:
parent
597ff218a9
commit
62b95c6d88
BIN
star_lock/images/main/icon_lockDetail_hangUp.png
Normal file
BIN
star_lock/images/main/icon_lockDetail_hangUp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
BIN
star_lock/images/main/icon_lockDetail_monitoringAnswerCalls.png
Normal file
BIN
star_lock/images/main/icon_lockDetail_monitoringAnswerCalls.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
BIN
star_lock/images/main/icon_lockDetail_monitoringUnTalkback.png
Normal file
BIN
star_lock/images/main/icon_lockDetail_monitoringUnTalkback.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
@ -127,8 +127,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
|
||||
|
||||
initAliyunPush();
|
||||
|
||||
// playLocalAudio();
|
||||
|
||||
// Uint8List uint8List = Uint8List.fromList([]);
|
||||
// CallTalk talkClass = CallTalk();
|
||||
// talkClass.getAVData(uint8List, 90);
|
||||
@ -192,9 +190,3 @@ Future _setCommonServices() async {
|
||||
// Get.log(PlatformInfoService.to.info.version);
|
||||
}
|
||||
|
||||
//播放本地音频
|
||||
void playLocalAudio() async {
|
||||
final audioPlayer = AudioPlayer();
|
||||
audioPlayer.setReleaseMode(ReleaseMode.loop);
|
||||
await audioPlayer.play(AssetSource('ring1.mp3'));
|
||||
}
|
||||
|
||||
@ -17,6 +17,15 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
});
|
||||
}
|
||||
|
||||
/// 收到接听状态
|
||||
StreamSubscription? _getUDPStatusRefreshUIEvent;
|
||||
void _getUDPStatusRefreshUIAction() {
|
||||
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
||||
_getTVDataRefreshUIEvent = eventBus.on<GetUDPStatusRefreshUI>().listen((event) {
|
||||
state.udpStatus.value = event.udpStatus;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
@ -24,6 +33,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
print("onReady()");
|
||||
|
||||
_getTVDataRefreshUIAction();
|
||||
_getUDPStatusRefreshUIAction();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -38,6 +48,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
// TODO: implement onClose
|
||||
print("锁详情界面销毁了");
|
||||
_getTVDataRefreshUIEvent!.cancel();
|
||||
_getUDPStatusRefreshUIEvent!.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,9 +2,15 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:network_info_plus/network_info_plus.dart';
|
||||
|
||||
import '../../../../appRouters.dart';
|
||||
import '../../../../app_settings/app_colors.dart';
|
||||
import '../../../../talk/udp/udp_manage.dart';
|
||||
import '../../../../talk/udp/udp_senderManage.dart';
|
||||
import '../../../../tools/showTFView.dart';
|
||||
import '../../../../tools/storage.dart';
|
||||
import '../../../../tools/toast.dart';
|
||||
import 'lockMonitoring_logic.dart';
|
||||
|
||||
class LockMonitoringPage extends StatefulWidget {
|
||||
@ -142,19 +148,97 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
||||
}
|
||||
|
||||
Widget bottomBottomBtnWidget() {
|
||||
return Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
|
||||
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringTalkback.png",
|
||||
"点击对讲", Colors.white, () {}),
|
||||
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png",
|
||||
"长按开锁", AppColors.mainColor, () {})
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Obx(() => bottomBtnItemWidget(getAnswerBtnImg(), getAnswerBtnName(), Colors.white, () async {
|
||||
var userMobileIP = await NetworkInfo().getWifiIP();
|
||||
var userMobile = await Storage.getMobile();
|
||||
|
||||
// 刚进来是接听状态,然后改为长按对讲
|
||||
UDPSenderManage.sendMainProtocol(
|
||||
command: 150,
|
||||
commandTypeIsCalling: 1,
|
||||
subCommand: 6,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: userMobile,
|
||||
userMobileIP: userMobileIP,
|
||||
endData: []);
|
||||
})),
|
||||
bottomBtnItemWidget("images/main/icon_lockDetail_hangUp.png", "挂断", Colors.red, () async {
|
||||
var userMobileIP = await NetworkInfo().getWifiIP();
|
||||
var userMobile = await Storage.getMobile();
|
||||
|
||||
// 挂断
|
||||
UDPSenderManage.sendMainProtocol(
|
||||
command: 150,
|
||||
commandTypeIsCalling: 1,
|
||||
subCommand: 30,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: userMobile,
|
||||
userMobileIP: userMobileIP,
|
||||
endData: []);
|
||||
}),
|
||||
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png", "开锁", AppColors.mainColor, () {
|
||||
showDeletPasswordAlertDialog(context);
|
||||
})
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
String getAnswerBtnImg(){
|
||||
switch (state.udpStatus.value) {
|
||||
case 8:
|
||||
{
|
||||
return "images/main/icon_lockDetail_monitoringUnTalkback.png";
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
return "images/main/icon_lockDetail_monitoringTalkback.png";
|
||||
}
|
||||
default:
|
||||
{
|
||||
return "images/main/icon_lockDetail_monitoringAnswerCalls.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String getAnswerBtnName(){
|
||||
switch (state.udpStatus.value) {
|
||||
case 8:
|
||||
{
|
||||
return "长按说话";
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
return "松开发送";
|
||||
}
|
||||
default:
|
||||
{
|
||||
return "接听";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget bottomBtnItemWidget(
|
||||
String iconUrl, String name, Color backgroundColor, Function() onClick) {
|
||||
var wh = 80.w;
|
||||
return GestureDetector(
|
||||
onTap: onClick,
|
||||
onLongPress: (){
|
||||
print("onLongPress");
|
||||
if(state.udpStatus.value == 8){
|
||||
state.udpStatus.value = 9;
|
||||
}
|
||||
},
|
||||
onLongPressUp: () {
|
||||
print("onLongPressUp");
|
||||
if(state.udpStatus.value == 9){
|
||||
state.udpStatus.value = 8;
|
||||
}
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 140.h,
|
||||
child: Column(
|
||||
@ -178,4 +262,43 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
void showDeletPasswordAlertDialog(BuildContext context) {
|
||||
showDialog(
|
||||
barrierDismissible:false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ShowTFView(
|
||||
title: "请输入开锁密码",
|
||||
tipTitle: "",
|
||||
controller: state.passwordTF,
|
||||
sureClick: () async {
|
||||
//发送删除锁请求
|
||||
if (state.passwordTF.text.isEmpty) {
|
||||
Toast.show(msg: "请输入开锁密码");
|
||||
return;
|
||||
}
|
||||
|
||||
var userMobileIP = await NetworkInfo().getWifiIP();
|
||||
var userMobile = await Storage.getMobile();
|
||||
|
||||
// 开锁
|
||||
UDPSenderManage.sendMainProtocol(
|
||||
command: 150,
|
||||
commandTypeIsCalling: 1,
|
||||
subCommand: 10,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: userMobile,
|
||||
userMobileIP: userMobileIP,
|
||||
endData: []);
|
||||
Get.back();
|
||||
},
|
||||
cancelClick: () {
|
||||
Get.back();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class LockMonitoringState {
|
||||
var isOpenVoice = false.obs;
|
||||
|
||||
var isOpenVoice = false.obs;
|
||||
var udpStatus = 0.obs; //0:初始状态 1:等待监视 2: 3:监视中 4:呼叫成功 5:主角通话中 6:被叫通话 8:被叫通话中 9:长按说话
|
||||
var passwordTF = TextEditingController();
|
||||
var listData = <int>[].obs;
|
||||
|
||||
Uint8List imageData = Uint8List.fromList([
|
||||
|
||||
@ -57,6 +57,7 @@ class CallTalk {
|
||||
// 用你的711音频数据替换这里的Uint8List
|
||||
Uint8List rawData = G711Decoder().decodeG711uLaw(bb);
|
||||
_playRawData(rawData);
|
||||
print('收到音频数据了');
|
||||
}
|
||||
// 视频数据
|
||||
else {
|
||||
|
||||
@ -16,7 +16,7 @@ class UDPMainProtocolCommand extends UDPSenderProtocol {
|
||||
String? lockIP;
|
||||
String? userMobile;
|
||||
String? userMobileIP;
|
||||
List<int>? data;
|
||||
List<int>? endData;
|
||||
|
||||
UDPMainProtocolCommand({
|
||||
this.command,
|
||||
@ -26,7 +26,7 @@ class UDPMainProtocolCommand extends UDPSenderProtocol {
|
||||
this.lockIP,
|
||||
this.userMobile,
|
||||
this.userMobileIP,
|
||||
this.data,
|
||||
this.endData,
|
||||
}) : super(CommandUDPType.heart);
|
||||
|
||||
@override
|
||||
|
||||
@ -12,36 +12,39 @@ import 'udp_senderManage.dart';
|
||||
|
||||
class UdpHelp{
|
||||
|
||||
Timer? timer;
|
||||
openUDP() async {
|
||||
// 从服务器获取ip跟端口
|
||||
var entity = await ApiRepository.to.getWifiLockServiceIpAndPort();
|
||||
if(entity.errorCode! == 0){
|
||||
UDPManage();
|
||||
// UDPManage().initUdp();
|
||||
// UDPManage().host = entity.data!.serviceList![0].serviceIp!;
|
||||
// UDPManage().port = int.parse(entity.data!.serviceList![0].port!);
|
||||
UDPManage().port = int.parse(entity.data!.serviceList![0].port!);
|
||||
|
||||
var serversList = <int>[];
|
||||
for(int i = 0; i<entity.data!.serviceList!.length; i++){
|
||||
var item = entity.data!.serviceList![i];
|
||||
if(item.serviceIp!.contains("192")){
|
||||
UDPManage().host = entity.data!.serviceList![0].serviceIp!;
|
||||
var itemList = item.serviceIp!.split(".");
|
||||
for (var element in itemList) {
|
||||
serversList.add(int.parse(element));
|
||||
}
|
||||
}else{
|
||||
List<InternetAddress> addresses = await InternetAddress.lookup(item.serviceIp!);
|
||||
UDPManage().host = addresses.first.address;
|
||||
var itemList = addresses.first.address.split(".");
|
||||
for (var element in itemList) {
|
||||
serversList.add(int.parse(element));
|
||||
}
|
||||
print('Resolved google.com to address: ${addresses.first.address} serversList:${serversList}');
|
||||
print('Resolved google.com to address: ${addresses.first.address} serversList:$serversList');
|
||||
}
|
||||
}
|
||||
|
||||
Timer timer = Timer.periodic(1.seconds, (timer) async {
|
||||
var mobile = await Storage.getMobile();
|
||||
timer = Timer.periodic(1.seconds, (timer) async {
|
||||
UDPSenderManage.sendHeart(
|
||||
userName: await Storage.getMobile(),
|
||||
userName: mobile,
|
||||
ipList: serversList,
|
||||
tokenStr: "b989fa15f75c2ac02718b7c9bb64f80e",
|
||||
);
|
||||
@ -49,11 +52,15 @@ class UdpHelp{
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getWifiLockServiceIpAndPort() async {
|
||||
var entity = await ApiRepository.to.getWifiLockServiceIpAndPort();
|
||||
if(entity.errorCode! == 0){
|
||||
// Future<void> getWifiLockServiceIpAndPort() async {
|
||||
// var entity = await ApiRepository.to.getWifiLockServiceIpAndPort();
|
||||
// if(entity.errorCode! == 0){
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
dispose(){
|
||||
timer!.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
@ -31,16 +30,18 @@ class UDPManage{
|
||||
|
||||
StreamSubscription<EventSendModel>? _streamSubscription;
|
||||
RawDatagramSocket? _udpSocket;
|
||||
String host = '47.106.143.213';
|
||||
int port = 8056;
|
||||
// String host = '47.106.143.213';
|
||||
// int port = 8056;
|
||||
// String? _mIp = '';
|
||||
// String host = '';
|
||||
// int port = 0;
|
||||
String host = '';
|
||||
int port = 0;
|
||||
String lockId = '';// 锁id 通过锁id来判断是哪把锁发对讲过来
|
||||
|
||||
void initUdp() async {
|
||||
var listAddress = InternetAddress.lookup(host!);
|
||||
listAddress.then((list) {
|
||||
list.forEach((element) {
|
||||
// print('Udp ----> element.address:${element.address} element.host:${element.host}');
|
||||
host = element.address;
|
||||
});
|
||||
});
|
||||
@ -52,6 +53,7 @@ class UDPManage{
|
||||
print('❌ Udp ----> _port == 0');
|
||||
return;
|
||||
}
|
||||
print('Udp ----> host:$host port:$port');
|
||||
var addressIListenFrom = InternetAddress.anyIPv4;
|
||||
int portIListenOn = 62288;
|
||||
RawDatagramSocket.bind(addressIListenFrom, portIListenOn).then((RawDatagramSocket socket){
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/talk/udp/udp_manage.dart';
|
||||
|
||||
import '../../blue/io_tool/io_tool.dart';
|
||||
import '../../tools/eventBusEventManage.dart';
|
||||
import '../../tools/toast.dart';
|
||||
import '../call/callTalk.dart';
|
||||
import 'udp_talkClass.dart';
|
||||
@ -14,7 +19,7 @@ class CommandUDPReciverManager {
|
||||
if (dataSize < 4) {
|
||||
return;
|
||||
}
|
||||
print("appDataReceiveUDPData:$data");
|
||||
// print("appReceiveUDPData:$data");
|
||||
|
||||
Uint8List data1 = Uint8List.fromList(data);
|
||||
if (data1.length == 1) {
|
||||
@ -26,6 +31,7 @@ class CommandUDPReciverManager {
|
||||
if (data[6] == 4) {
|
||||
if (data[7] == 2) {
|
||||
// print("心跳包反馈 在线状态");
|
||||
|
||||
} else if (data[7] == 3) {
|
||||
[Toast.show(msg: "您已在其他设备登录")];
|
||||
}
|
||||
@ -42,6 +48,11 @@ class CommandUDPReciverManager {
|
||||
case 1:
|
||||
{
|
||||
//被叫
|
||||
// lockId
|
||||
var lockId = data.sublist(9, 29);
|
||||
var lockIdStr = utf8String(lockId);
|
||||
UDPManage().lockId = lockIdStr;
|
||||
|
||||
UDPTalkClass().beCallW(data: data);
|
||||
}
|
||||
break;
|
||||
@ -51,6 +62,10 @@ class CommandUDPReciverManager {
|
||||
if ((data[7] & 0x3) == 2) {
|
||||
//被叫 接听反馈
|
||||
print("接听反馈");
|
||||
UDPTalkClass().status = 8;
|
||||
// 停止声音
|
||||
UDPTalkClass().stopLocalAudio();
|
||||
eventBus.fire(GetUDPStatusRefreshUI(UDPTalkClass().status));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -77,21 +92,29 @@ class CommandUDPReciverManager {
|
||||
case 10:
|
||||
{
|
||||
//开门反馈
|
||||
print("appReceiveUDPData:$data");
|
||||
if ((data[7] & 0x3) == 2) {
|
||||
print("开门成功");
|
||||
} else {}
|
||||
Toast.show(msg: "开门成功");
|
||||
} else {
|
||||
print("开门失败");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 30:
|
||||
{
|
||||
//开门反馈
|
||||
// 挂断
|
||||
if ((data[7] & 0x3) == 1) {
|
||||
//对方结束对讲
|
||||
// 对方结束对讲
|
||||
print("对方结束对讲");
|
||||
} else {
|
||||
//结束对讲反馈
|
||||
print("结束对讲反馈");
|
||||
}
|
||||
UDPTalkClass().status = 0;
|
||||
Get.back();
|
||||
UDPTalkClass().stopLocalAudio();
|
||||
eventBus.fire(GetUDPStatusRefreshUI(UDPTalkClass().status));
|
||||
}
|
||||
break;
|
||||
case 140:
|
||||
|
||||
@ -24,7 +24,7 @@ class UDPSenderManage {
|
||||
String? lockIP,
|
||||
String? userMobile,
|
||||
String? userMobileIP,
|
||||
List<int>? data,
|
||||
List<int>? endData,
|
||||
CommandUDPSendCallBack? callBack}) {
|
||||
CommandUDPSenderManager().managerSendData(command: UDPMainProtocolCommand(
|
||||
command: command,
|
||||
@ -34,7 +34,7 @@ class UDPSenderManage {
|
||||
lockIP: lockIP,
|
||||
userMobile: userMobile,
|
||||
userMobileIP: userMobileIP,
|
||||
data: data,
|
||||
endData: endData,
|
||||
), callBack: callBack);
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:fast_gbk/fast_gbk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@ -21,11 +22,12 @@ class UDPTalkClass{
|
||||
|
||||
UDPTalkClass._init();
|
||||
|
||||
var status = 0;// 0空闲
|
||||
var status = 0; //0:初始状态 1:等待监视 2: 3:监视中 4:呼叫成功 5:主角通话中 6:被叫通话 8:被叫通话中
|
||||
var remoteEquid;// 手机号
|
||||
late Timer timer;
|
||||
// 该字段是为了判断是否跳转到接听界面 挂断或者退出接听界面要记得变更状态
|
||||
var isBeCall = false;
|
||||
final audioPlayer = AudioPlayer();
|
||||
|
||||
beCallW({List<int>? data, String? ip, int? port}) async {
|
||||
// print("beCall");
|
||||
@ -70,6 +72,7 @@ class UDPTalkClass{
|
||||
Get.toNamed(Routers.lockMonitoringPage, arguments: {
|
||||
"lockId": "111"
|
||||
});
|
||||
playLocalAudio();
|
||||
}else{
|
||||
// 忙
|
||||
|
||||
@ -111,4 +114,16 @@ class UDPTalkClass{
|
||||
return equid;
|
||||
}
|
||||
|
||||
|
||||
//播放本地音频
|
||||
void playLocalAudio() async {
|
||||
audioPlayer.setReleaseMode(ReleaseMode.loop);
|
||||
await audioPlayer.play(AssetSource('ring1.mp3'));
|
||||
}
|
||||
|
||||
// 停止播放本地音频
|
||||
void stopLocalAudio() async {
|
||||
audioPlayer.setReleaseMode(ReleaseMode.loop);
|
||||
await audioPlayer.stop();
|
||||
}
|
||||
}
|
||||
@ -60,4 +60,10 @@ class LockSetChangeSetRefreshLockDetailWithType{
|
||||
class GetTVDataRefreshUI{
|
||||
List<int> tvList;
|
||||
GetTVDataRefreshUI(this.tvList);
|
||||
}
|
||||
|
||||
/// 获取到UDP接收状态然后刷新界面
|
||||
class GetUDPStatusRefreshUI{
|
||||
int udpStatus;
|
||||
GetUDPStatusRefreshUI(this.udpStatus);
|
||||
}
|
||||
@ -141,7 +141,7 @@ class Storage {
|
||||
if (data != null && data.isNotEmpty) {
|
||||
uid = LoginData.fromJson(jsonDecode(data)).uid.toString();
|
||||
}
|
||||
print("pubUid:$uid");
|
||||
// print("pubUid:$uid");
|
||||
return uid;
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ class Storage {
|
||||
if (data != null && data.isNotEmpty) {
|
||||
mobile = LoginData.fromJson(jsonDecode(data)).mobile.toString();
|
||||
}
|
||||
print("pubUserId:$mobile");
|
||||
// print("mobile:$mobile");
|
||||
return mobile;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user