2024-12-24 10:50:32 +08:00
|
|
|
|
import 'dart:convert';
|
2025-02-18 10:42:08 +08:00
|
|
|
|
import 'dart:io';
|
2024-12-24 10:50:32 +08:00
|
|
|
|
|
2024-12-05 13:51:28 +08:00
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
import 'package:star_lock/appRouters.dart';
|
2025-04-03 10:36:30 +08:00
|
|
|
|
import 'package:star_lock/app_settings/app_settings.dart';
|
2025-04-22 15:17:42 +08:00
|
|
|
|
import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart';
|
2025-01-23 14:30:31 +08:00
|
|
|
|
import 'package:star_lock/talk/starChart/constant/message_type_constant.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/starChart/constant/talk_status.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/starChart/entity/scp_message.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/starChart/handle/scp_message_base_handle.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/starChart/handle/scp_message_handle.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/starChart/proto/generic.pb.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/starChart/proto/talk_expect.pb.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/starChart/proto/talk_request.pb.dart';
|
2025-04-22 15:17:42 +08:00
|
|
|
|
import 'package:star_lock/tools/commonDataManage.dart';
|
2025-02-18 10:42:08 +08:00
|
|
|
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
2025-01-02 10:30:07 +08:00
|
|
|
|
import 'package:star_lock/tools/storage.dart';
|
2025-03-20 17:35:11 +08:00
|
|
|
|
import 'package:star_lock/translations/current_locale_tool.dart';
|
2024-12-05 13:51:28 +08:00
|
|
|
|
|
|
|
|
|
|
class UdpTalkRequestHandler extends ScpMessageBaseHandle
|
|
|
|
|
|
implements ScpMessageHandler {
|
2025-03-20 17:35:11 +08:00
|
|
|
|
RxString currentLanguage =
|
|
|
|
|
|
CurrentLocaleTool.getCurrentLocaleString().obs; // 当前选择语言
|
|
|
|
|
|
|
2024-12-09 09:22:58 +08:00
|
|
|
|
@override
|
2025-01-02 10:30:07 +08:00
|
|
|
|
void handleReq(ScpMessage scpMessage) async {
|
|
|
|
|
|
// 判断是否登录账户
|
|
|
|
|
|
final loginData = await Storage.getLoginData();
|
2025-04-02 09:34:02 +08:00
|
|
|
|
// 如果登录账户不为空,且不是被动接听状态,且不是接听成功状态
|
2025-01-09 14:10:10 +08:00
|
|
|
|
if (loginData != null &&
|
2025-04-03 10:36:30 +08:00
|
|
|
|
(talkStatus.status != TalkStatus.passiveCallWaitingAnswer ||
|
|
|
|
|
|
talkStatus.status != TalkStatus.answeredSuccessfully)) {
|
2025-01-09 14:10:10 +08:00
|
|
|
|
// 收到对讲请求
|
|
|
|
|
|
final TalkReq talkReq = scpMessage.Payload;
|
|
|
|
|
|
startChartManage.FromPeerId = scpMessage.ToPeerId!;
|
|
|
|
|
|
startChartManage.ToPeerId = scpMessage.FromPeerId!;
|
2025-01-24 11:05:28 +08:00
|
|
|
|
startChartManage.lockPeerId = scpMessage.FromPeerId!;
|
2025-01-09 14:10:10 +08:00
|
|
|
|
// 处理收到接听请求后的事件
|
2025-05-13 10:19:43 +08:00
|
|
|
|
_talkRequestEvent(
|
|
|
|
|
|
talkObjectName: talkReq.callerName,
|
|
|
|
|
|
lockPeerID: scpMessage.FromPeerId!,
|
|
|
|
|
|
);
|
2025-04-03 10:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
// 回复成功
|
|
|
|
|
|
replySuccessMessage(scpMessage);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 拒绝接听,回复失败
|
|
|
|
|
|
replyErrorMessage(scpMessage);
|
2025-04-08 14:35:36 +08:00
|
|
|
|
AppLog.log('正在接听,回复拒绝');
|
2024-12-24 10:50:32 +08:00
|
|
|
|
}
|
2024-12-09 09:22:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void handleResp(ScpMessage scpMessage) {
|
|
|
|
|
|
// 收到对讲请求回复
|
|
|
|
|
|
final GenericResp genericResp = scpMessage.Payload;
|
2025-01-09 14:10:10 +08:00
|
|
|
|
if (checkGenericRespSuccess(genericResp)) {
|
|
|
|
|
|
// 收到对讲请求的应答
|
|
|
|
|
|
startChartManage.FromPeerId = scpMessage.ToPeerId!;
|
|
|
|
|
|
startChartManage.ToPeerId = scpMessage.FromPeerId!;
|
2025-05-15 16:47:08 +08:00
|
|
|
|
startChartManage.lockPeerId = scpMessage.FromPeerId!;
|
2025-04-27 09:53:05 +08:00
|
|
|
|
// 处理预期数据格式
|
2025-05-15 16:47:08 +08:00
|
|
|
|
_handleResponseSendExpect(
|
|
|
|
|
|
lockPeerID: scpMessage.FromPeerId!,
|
|
|
|
|
|
);
|
2025-01-09 14:10:10 +08:00
|
|
|
|
// 发送预期数据
|
|
|
|
|
|
startChartManage.startTalkExpectTimer();
|
|
|
|
|
|
// 停止发送对讲请求
|
|
|
|
|
|
startChartManage.stopCallRequestMessageTimer();
|
2025-03-21 16:19:50 +08:00
|
|
|
|
// 收到应答后取消超时判断
|
|
|
|
|
|
talkeRequestOverTimeTimerManager.cancel();
|
|
|
|
|
|
// 启动发送ping
|
|
|
|
|
|
startChartManage.startTalkPingMessageTimer();
|
|
|
|
|
|
// 启动ping命令超时判断
|
|
|
|
|
|
talkePingOverTimeTimerManager.start();
|
2024-12-09 09:22:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
2024-12-10 17:27:37 +08:00
|
|
|
|
void handleInvalidReq(ScpMessage scpMessage) {}
|
2024-12-09 09:22:58 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
2024-12-10 17:27:37 +08:00
|
|
|
|
void handleRealTimeData(ScpMessage scpMessage) {}
|
2024-12-09 11:06:35 +08:00
|
|
|
|
|
|
|
|
|
|
// 来电事件的处理
|
2025-05-13 10:19:43 +08:00
|
|
|
|
void _talkRequestEvent({
|
|
|
|
|
|
required String talkObjectName,
|
|
|
|
|
|
required String lockPeerID,
|
|
|
|
|
|
}) async {
|
2025-01-02 10:30:07 +08:00
|
|
|
|
// 发送预期数据、通知锁板需要获取视频数据
|
2025-05-13 10:19:43 +08:00
|
|
|
|
_handleRequestSendExpect(lockPeerID: lockPeerID);
|
2025-01-02 10:30:07 +08:00
|
|
|
|
// 显示状态栏弹窗
|
2025-05-07 15:25:14 +08:00
|
|
|
|
// _showTalkRequestNotification(talkObjectName: talkObjectName);
|
2025-01-02 10:30:07 +08:00
|
|
|
|
// 设置为等待接听状态
|
2025-01-09 14:10:10 +08:00
|
|
|
|
talkStatus.setPassiveCallWaitingAnswer();
|
2024-12-09 11:06:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 收到来电请求时进行本地通知
|
|
|
|
|
|
Future<void> _showTalkRequestNotification(
|
|
|
|
|
|
{required String talkObjectName}) async {
|
2025-02-21 14:30:21 +08:00
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
|
final Map<String, dynamic> message = {
|
|
|
|
|
|
'platform': 'all',
|
|
|
|
|
|
'audience': 'all',
|
|
|
|
|
|
'notification': <String, Map<String, Object>>{
|
|
|
|
|
|
'android': <String, Object>{
|
|
|
|
|
|
'title': '呼叫提醒'.tr,
|
|
|
|
|
|
'alert': '${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}。',
|
|
|
|
|
|
'extras': <String, String>{
|
|
|
|
|
|
'image_url':
|
|
|
|
|
|
'https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=视频通话图标&step_word=&hs=0&pn=18&spn=0&di=7456461798821068801&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=3670633426%2C2210940696&os=2119936476%2C3383901310&simid=3670633426%2C2210940696&adpicid=0&lpn=0&ln=1216&fr=&fmq=1738909566404_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined©right=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=https%3A%2F%2Ftenfei03.cfp.cn%2Fcreative%2Fvcg%2Fnowarter800%2Fnew%2FVCG211249198901.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bev2_z%26e3Bv54AzdH3Fv6jwptejAzdH3F8dnla9lla0&gsm=1e&rpstart=0&rpnum=0&islist=&querylist=&nojc=undefined&dyTabStr=MCwxMiwzLDEsMiwxMyw3LDYsNSw5&lid=9610633549467928081'
|
|
|
|
|
|
}
|
2025-02-10 09:45:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-21 14:30:21 +08:00
|
|
|
|
};
|
2025-02-10 09:45:36 +08:00
|
|
|
|
|
2025-03-20 17:35:11 +08:00
|
|
|
|
if (currentLanguage.value == 'zh_CN') {
|
|
|
|
|
|
XSJPushProvider().showCustomNotification(message);
|
|
|
|
|
|
}
|
2025-02-21 14:30:21 +08:00
|
|
|
|
}
|
2025-02-18 10:42:08 +08:00
|
|
|
|
/*
|
2024-12-09 11:06:35 +08:00
|
|
|
|
const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
|
|
|
|
|
AndroidNotificationDetails('1', 'flutter_channel',
|
|
|
|
|
|
importance: Importance.max,
|
|
|
|
|
|
priority: Priority.high,
|
|
|
|
|
|
playSound: true,
|
|
|
|
|
|
ticker: 'ticker');
|
|
|
|
|
|
const NotificationDetails platformChannelSpecifics =
|
|
|
|
|
|
NotificationDetails(android: androidPlatformChannelSpecifics);
|
|
|
|
|
|
// 获取锁名
|
|
|
|
|
|
// String? getLockName = await Storage.getString(saveLockAlias);
|
|
|
|
|
|
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
|
|
|
|
|
FlutterLocalNotificationsPlugin();
|
|
|
|
|
|
// 执行本地通知
|
|
|
|
|
|
await flutterLocalNotificationsPlugin.show(0, '呼叫提醒'.tr,
|
|
|
|
|
|
'${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}。', platformChannelSpecifics,
|
|
|
|
|
|
payload: 'item x');
|
2025-02-18 10:42:08 +08:00
|
|
|
|
*/
|
2024-12-09 11:06:35 +08:00
|
|
|
|
}
|
2024-12-24 10:50:32 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
deserializePayload(
|
|
|
|
|
|
{required int payloadType,
|
|
|
|
|
|
required int messageType,
|
2024-12-27 13:35:56 +08:00
|
|
|
|
required List<int> byte,
|
2024-12-24 10:50:32 +08:00
|
|
|
|
int? offset,
|
|
|
|
|
|
int? PayloadLength,
|
|
|
|
|
|
int? spTotal,
|
|
|
|
|
|
int? spIndex,
|
|
|
|
|
|
int? messageId}) {
|
|
|
|
|
|
if (messageType == MessageTypeConstant.Resp) {
|
|
|
|
|
|
final GenericResp genericResp = GenericResp();
|
|
|
|
|
|
genericResp.mergeFromBuffer(byte);
|
|
|
|
|
|
return genericResp;
|
|
|
|
|
|
} else if (messageType == MessageTypeConstant.Req) {
|
|
|
|
|
|
final TalkReq talkReq = TalkReq();
|
|
|
|
|
|
talkReq.mergeFromBuffer(byte);
|
|
|
|
|
|
return talkReq;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String payload = utf8.decode(byte);
|
|
|
|
|
|
return payload;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-02 10:30:07 +08:00
|
|
|
|
|
2025-04-27 09:53:05 +08:00
|
|
|
|
/// app收到的对讲请求后,发送的预期数据
|
2025-05-13 10:19:43 +08:00
|
|
|
|
void _handleRequestSendExpect({
|
|
|
|
|
|
required String lockPeerID,
|
|
|
|
|
|
}) async {
|
2025-04-22 15:17:42 +08:00
|
|
|
|
final LockListInfoItemEntity currentKeyInfo =
|
|
|
|
|
|
CommonDataManage().currentKeyInfo;
|
|
|
|
|
|
|
2025-05-13 10:19:43 +08:00
|
|
|
|
var isH264 = currentKeyInfo.lockFeature?.isH264 == 1;
|
|
|
|
|
|
var isMJpeg = currentKeyInfo.lockFeature?.isMJpeg == 1;
|
|
|
|
|
|
|
|
|
|
|
|
final LockListInfoGroupEntity? lockListInfoGroupEntity =
|
|
|
|
|
|
await Storage.getLockMainListData();
|
|
|
|
|
|
if (lockListInfoGroupEntity != null) {
|
|
|
|
|
|
lockListInfoGroupEntity!.groupList?.forEach((element) {
|
|
|
|
|
|
final lockList = element.lockList;
|
|
|
|
|
|
if (lockList != null && lockList.length != 0) {
|
|
|
|
|
|
for (var lockInfo in lockList) {
|
|
|
|
|
|
final peerId = lockInfo.network?.peerId;
|
|
|
|
|
|
if (peerId != null && peerId != '') {
|
|
|
|
|
|
if (peerId == lockPeerID) {
|
|
|
|
|
|
isH264 = lockInfo.lockFeature?.isH264 == 1;
|
|
|
|
|
|
isMJpeg = lockInfo.lockFeature?.isMJpeg == 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-04-22 15:17:42 +08:00
|
|
|
|
// 优先使用H264,其次是MJPEG
|
|
|
|
|
|
if (isH264) {
|
|
|
|
|
|
// 锁支持H264,发送H264视频和G711音频期望
|
|
|
|
|
|
startChartManage.sendOnlyH264VideoTalkExpectData();
|
2025-05-16 17:07:05 +08:00
|
|
|
|
print(
|
|
|
|
|
|
'app收到的对讲请求后,发送的预期数据=========锁支持H264,发送H264视频格式期望数据,peerID=${lockPeerID}');
|
2025-04-22 15:17:42 +08:00
|
|
|
|
} else if (isMJpeg) {
|
|
|
|
|
|
// 锁只支持MJPEG,发送图像视频和G711音频期望
|
|
|
|
|
|
startChartManage.sendOnlyImageVideoTalkExpectData();
|
2025-05-16 17:07:05 +08:00
|
|
|
|
print(
|
|
|
|
|
|
'app收到的对讲请求后,发送的预期数据=========锁不支持H264,支持MJPEG,发送MJPEG视频格式期望数据,peerID=${lockPeerID}');
|
2025-04-22 15:17:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
// 默认使用图像视频
|
|
|
|
|
|
startChartManage.sendOnlyImageVideoTalkExpectData();
|
2025-05-16 17:07:05 +08:00
|
|
|
|
print(
|
|
|
|
|
|
'app收到的对讲请求后,发送的预期数据=========锁不支持H264和MJPEG,默认发送MJPEG视频格式期望数据,peerID=${lockPeerID}');
|
2025-04-22 15:17:42 +08:00
|
|
|
|
}
|
2025-01-02 10:30:07 +08:00
|
|
|
|
}
|
2025-04-27 09:53:05 +08:00
|
|
|
|
|
|
|
|
|
|
/// app主动发请求,收到回复后发送的预期数据
|
2025-05-15 16:47:08 +08:00
|
|
|
|
void _handleResponseSendExpect({
|
|
|
|
|
|
required String lockPeerID,
|
|
|
|
|
|
}) async {
|
2025-04-27 09:53:05 +08:00
|
|
|
|
final LockListInfoItemEntity currentKeyInfo =
|
|
|
|
|
|
CommonDataManage().currentKeyInfo;
|
|
|
|
|
|
|
2025-05-15 16:47:08 +08:00
|
|
|
|
var isH264 = currentKeyInfo.lockFeature?.isH264 == 1;
|
|
|
|
|
|
var isMJpeg = currentKeyInfo.lockFeature?.isMJpeg == 1;
|
|
|
|
|
|
|
|
|
|
|
|
final LockListInfoGroupEntity? lockListInfoGroupEntity =
|
|
|
|
|
|
await Storage.getLockMainListData();
|
|
|
|
|
|
if (lockListInfoGroupEntity != null) {
|
|
|
|
|
|
lockListInfoGroupEntity!.groupList?.forEach((element) {
|
|
|
|
|
|
final lockList = element.lockList;
|
|
|
|
|
|
if (lockList != null && lockList.length != 0) {
|
|
|
|
|
|
for (var lockInfo in lockList) {
|
|
|
|
|
|
final peerId = lockInfo.network?.peerId;
|
|
|
|
|
|
if (peerId != null && peerId != '') {
|
|
|
|
|
|
if (peerId == lockPeerID) {
|
|
|
|
|
|
isH264 = lockInfo.lockFeature?.isH264 == 1;
|
|
|
|
|
|
isMJpeg = lockInfo.lockFeature?.isMJpeg == 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-04-27 09:53:05 +08:00
|
|
|
|
// 优先使用H264,其次是MJPEG
|
|
|
|
|
|
if (isH264) {
|
|
|
|
|
|
// 锁支持H264,发送H264视频和G711音频期望
|
|
|
|
|
|
startChartManage.sendH264VideoAndG711AudioTalkExpectData();
|
2025-05-16 17:07:05 +08:00
|
|
|
|
AppLog.log(
|
|
|
|
|
|
'app主动发对讲请求,收到回复后发送的预期数据=======锁支持H264,发送H264视频格式期望数据,peerID=${lockPeerID}');
|
2025-04-27 09:53:05 +08:00
|
|
|
|
} else if (isMJpeg) {
|
|
|
|
|
|
// 锁只支持MJPEG,发送图像视频和G711音频期望
|
|
|
|
|
|
startChartManage.sendImageVideoAndG711AudioTalkExpectData();
|
2025-05-16 17:07:05 +08:00
|
|
|
|
AppLog.log(
|
|
|
|
|
|
'app主动发对讲请求,收到回复后发送的预期数据=======锁不支持H264,支持MJPEG,发送MJPEG视频格式期望数据,peerID=${lockPeerID}');
|
2025-04-27 09:53:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
// 默认使用图像视频
|
|
|
|
|
|
startChartManage.sendImageVideoAndG711AudioTalkExpectData();
|
2025-05-16 17:07:05 +08:00
|
|
|
|
AppLog.log(
|
|
|
|
|
|
'app主动发对讲请求,收到回复后发送的预期数据=======锁不支持H264和MJPEG,默认发送MJPEG视频格式期望数据,peerID=${lockPeerID}');
|
2025-04-27 09:53:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-05 13:51:28 +08:00
|
|
|
|
}
|