148 lines
5.3 KiB
Dart
148 lines
5.3 KiB
Dart
import 'dart:convert';
|
||
import 'dart:typed_data';
|
||
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:flutter_pcm_sound/flutter_pcm_sound.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:star_lock/app_settings/app_settings.dart';
|
||
import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart';
|
||
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/gateway_reset.pb.dart';
|
||
import 'package:star_lock/talk/starChart/proto/generic.pb.dart';
|
||
import 'package:star_lock/talk/starChart/proto/talk_accept.pb.dart';
|
||
import 'package:star_lock/talk/starChart/proto/talk_expect.pb.dart';
|
||
import 'package:star_lock/tools/commonDataManage.dart';
|
||
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||
import 'package:star_lock/tools/storage.dart';
|
||
|
||
import '../../star_chart_manage.dart';
|
||
|
||
class UdpTalkAcceptHandler extends ScpMessageBaseHandle
|
||
implements ScpMessageHandler {
|
||
@override
|
||
void handleReq(ScpMessage scpMessage) {
|
||
// 回复同意接听消息
|
||
replySuccessMessage(scpMessage);
|
||
}
|
||
|
||
@override
|
||
void handleResp(ScpMessage scpMessage) {
|
||
// 收到同意接听回复
|
||
final GenericResp genericResp = scpMessage.Payload;
|
||
if (checkGenericRespSuccess(genericResp)) {
|
||
// 停止同意接听的重发
|
||
startChartManage.stopTalkAcceptTimer();
|
||
// 接听之后增加期望音频的接收
|
||
_handleSendExpect(lockPeerID: scpMessage.FromPeerId!);
|
||
// 停止播放铃声
|
||
stopRingtone();
|
||
// 设置状态为接听成功
|
||
talkStatus.setAnsweredSuccessfully();
|
||
// 同意接听之后,停止对讲请求超时监听定时器
|
||
talkeRequestOverTimeTimerManager.renew();
|
||
talkeRequestOverTimeTimerManager.cancel();
|
||
|
||
// 同意接听之后代表已读消息
|
||
// 需要把对应的消息设置为已读
|
||
AppLog.log('msg:${scpMessage}');
|
||
AppLog.log('msg:${startChartManage.lockListPeerId}');
|
||
|
||
// 锁发过来的id
|
||
final fromPeerId = scpMessage.FromPeerId;
|
||
if (fromPeerId != null && fromPeerId != '') {
|
||
startChartManage.lockListPeerId.forEach((element) {
|
||
if (element != null &&
|
||
element.network != null &&
|
||
element.network!.peerId == fromPeerId) {
|
||
// 找到了对应的锁,设置为已读
|
||
eventBus.fire(ReadTalkMessageRefreshUI(element.lockName!));
|
||
}
|
||
});
|
||
}
|
||
|
||
// 启动发送rbcuInfo数据
|
||
// startChartManage.startSendingRbcuInfoMessages(
|
||
// ToPeerId: startChartManage.lockPeerId);
|
||
}
|
||
}
|
||
|
||
@override
|
||
void handleInvalidReq(ScpMessage scpMessage) {}
|
||
|
||
@override
|
||
void handleRealTimeData(ScpMessage scpMessage) {}
|
||
|
||
@override
|
||
deserializePayload(
|
||
{required int payloadType,
|
||
required int messageType,
|
||
required List<int> byte,
|
||
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 TalkAcceptReq talkAccept = TalkAcceptReq();
|
||
talkAccept.mergeFromBuffer(byte);
|
||
return talkAccept;
|
||
} else {
|
||
String payload = utf8.decode(byte);
|
||
return payload;
|
||
}
|
||
}
|
||
|
||
/// 收到同意接听回复之后增加音频的期望数据
|
||
void _handleSendExpect({
|
||
required String lockPeerID,
|
||
}) async {
|
||
final LockListInfoItemEntity currentKeyInfo =
|
||
CommonDataManage().currentKeyInfo;
|
||
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
// 优先使用H264,其次是MJPEG
|
||
if (isH264) {
|
||
// 锁支持H264,发送H264视频和G711音频期望
|
||
startChartManage.sendH264VideoAndG711AudioTalkExpectData();
|
||
print('锁支持H264,发送H264视频格式期望数据');
|
||
} else if (isMJpeg) {
|
||
// 锁只支持MJPEG,发送图像视频和G711音频期望
|
||
startChartManage.sendImageVideoAndG711AudioTalkExpectData();
|
||
print('锁不支持H264,支持MJPEG,发送MJPEG视频格式期望数据');
|
||
} else {
|
||
// 默认使用图像视频
|
||
startChartManage.sendImageVideoAndG711AudioTalkExpectData();
|
||
print('锁不支持H264和MJPEG,默认发送图像视频格式期望数据');
|
||
}
|
||
}
|
||
}
|