fix:增加对讲的主动消息组装
This commit is contained in:
parent
4aeda1bfdf
commit
8f7ec774c1
@ -7,6 +7,11 @@ import 'package:star_lock/talk/startChart/constant/payload_type_constant.dart';
|
|||||||
import 'package:star_lock/talk/startChart/constant/protocol_flag_constant.dart';
|
import 'package:star_lock/talk/startChart/constant/protocol_flag_constant.dart';
|
||||||
import 'package:star_lock/talk/startChart/entity/scp_message.dart';
|
import 'package:star_lock/talk/startChart/entity/scp_message.dart';
|
||||||
import 'package:star_lock/talk/startChart/proto/gateway_reset.pb.dart';
|
import 'package:star_lock/talk/startChart/proto/gateway_reset.pb.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/proto/generic.pb.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/proto/talk_accept.pb.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/proto/talk_data.pb.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/proto/talk_ping.pb.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/proto/talk_reject.pb.dart';
|
||||||
|
|
||||||
class MessageCommand {
|
class MessageCommand {
|
||||||
/// 客户端去中继上线命令
|
/// 客户端去中继上线命令
|
||||||
@ -107,12 +112,13 @@ class MessageCommand {
|
|||||||
return _hexToBytes(serializedBytesString);
|
return _hexToBytes(serializedBytesString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通话保持消息
|
// 同意接听消息
|
||||||
static List<int> talkPingMessage({
|
static List<int> talkAcceptMessage({
|
||||||
required String FromPeerId,
|
required String FromPeerId,
|
||||||
required String ToPeerId,
|
required String ToPeerId,
|
||||||
}) {
|
}) {
|
||||||
String payload = 'hello';
|
final talkAcceptReq = TalkAcceptReq();
|
||||||
|
final payload = talkAcceptReq.writeToBuffer();
|
||||||
ScpMessage message = ScpMessage(
|
ScpMessage message = ScpMessage(
|
||||||
ProtocolFlag: ProtocolFlagConstant.scp01,
|
ProtocolFlag: ProtocolFlagConstant.scp01,
|
||||||
MessageType: MessageTypeConstant.Req,
|
MessageType: MessageTypeConstant.Req,
|
||||||
@ -122,7 +128,55 @@ class MessageCommand {
|
|||||||
FromPeerId: FromPeerId,
|
FromPeerId: FromPeerId,
|
||||||
ToPeerId: ToPeerId,
|
ToPeerId: ToPeerId,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
PayloadCRC: calculationCrc(_stringToUint8List(payload)),
|
PayloadCRC: calculationCrc(payload),
|
||||||
|
PayloadLength: payload.length,
|
||||||
|
PayloadType: PayloadTypeConstant.talkAccept,
|
||||||
|
);
|
||||||
|
String serializedBytesString = message.serialize();
|
||||||
|
return _hexToBytes(serializedBytesString);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拒绝接听消息
|
||||||
|
static List<int> talkRejectMessage({
|
||||||
|
required String FromPeerId,
|
||||||
|
required String ToPeerId,
|
||||||
|
}) {
|
||||||
|
final talkReject = TalkReject();
|
||||||
|
final payload = talkReject.writeToBuffer();
|
||||||
|
ScpMessage message = ScpMessage(
|
||||||
|
ProtocolFlag: ProtocolFlagConstant.scp01,
|
||||||
|
MessageType: MessageTypeConstant.Req,
|
||||||
|
MessageId: 1,
|
||||||
|
SpTotal: 0,
|
||||||
|
SpIndex: 0,
|
||||||
|
FromPeerId: FromPeerId,
|
||||||
|
ToPeerId: ToPeerId,
|
||||||
|
Payload: payload,
|
||||||
|
PayloadCRC: calculationCrc(payload),
|
||||||
|
PayloadLength: payload.length,
|
||||||
|
PayloadType: PayloadTypeConstant.talkReject,
|
||||||
|
);
|
||||||
|
String serializedBytesString = message.serialize();
|
||||||
|
return _hexToBytes(serializedBytesString);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 呼叫保持消息
|
||||||
|
static List<int> talkPingMessage({
|
||||||
|
required String FromPeerId,
|
||||||
|
required String ToPeerId,
|
||||||
|
}) {
|
||||||
|
final talkPing = TalkPing();
|
||||||
|
final payload = talkPing.writeToBuffer();
|
||||||
|
ScpMessage message = ScpMessage(
|
||||||
|
ProtocolFlag: ProtocolFlagConstant.scp01,
|
||||||
|
MessageType: MessageTypeConstant.RealTimeData,
|
||||||
|
MessageId: 1,
|
||||||
|
SpTotal: 0,
|
||||||
|
SpIndex: 0,
|
||||||
|
FromPeerId: FromPeerId,
|
||||||
|
ToPeerId: ToPeerId,
|
||||||
|
Payload: payload,
|
||||||
|
PayloadCRC: calculationCrc(payload),
|
||||||
PayloadLength: payload.length,
|
PayloadLength: payload.length,
|
||||||
PayloadType: PayloadTypeConstant.talkPing,
|
PayloadType: PayloadTypeConstant.talkPing,
|
||||||
);
|
);
|
||||||
@ -130,6 +184,84 @@ class MessageCommand {
|
|||||||
return _hexToBytes(serializedBytesString);
|
return _hexToBytes(serializedBytesString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 音视频数据
|
||||||
|
static List<int> talkDataMessage({
|
||||||
|
required String FromPeerId,
|
||||||
|
required String ToPeerId,
|
||||||
|
required TalkData talkData,
|
||||||
|
}) {
|
||||||
|
final payload = talkData.writeToBuffer();
|
||||||
|
ScpMessage message = ScpMessage(
|
||||||
|
ProtocolFlag: ProtocolFlagConstant.scp01,
|
||||||
|
MessageType: MessageTypeConstant.RealTimeData,
|
||||||
|
MessageId: 1,
|
||||||
|
SpTotal: 0,
|
||||||
|
SpIndex: 0,
|
||||||
|
FromPeerId: FromPeerId,
|
||||||
|
ToPeerId: ToPeerId,
|
||||||
|
Payload: payload,
|
||||||
|
PayloadCRC: calculationCrc(payload),
|
||||||
|
PayloadLength: payload.length,
|
||||||
|
PayloadType: PayloadTypeConstant.talkData,
|
||||||
|
);
|
||||||
|
String serializedBytesString = message.serialize();
|
||||||
|
return _hexToBytes(serializedBytesString);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenericRespSuccess 消息
|
||||||
|
static List<int> genericRespSuccessMessage({
|
||||||
|
required String FromPeerId,
|
||||||
|
required String ToPeerId,
|
||||||
|
required int PayloadType,
|
||||||
|
}) {
|
||||||
|
final genericResp = GenericResp();
|
||||||
|
genericResp.message = 'ok';
|
||||||
|
genericResp.code = 0;
|
||||||
|
final payload = genericResp.writeToBuffer();
|
||||||
|
ScpMessage message = ScpMessage(
|
||||||
|
ProtocolFlag: ProtocolFlagConstant.scp01,
|
||||||
|
MessageType: MessageTypeConstant.Resp,
|
||||||
|
MessageId: 1,
|
||||||
|
SpTotal: 0,
|
||||||
|
SpIndex: 0,
|
||||||
|
FromPeerId: FromPeerId,
|
||||||
|
ToPeerId: ToPeerId,
|
||||||
|
Payload: payload,
|
||||||
|
PayloadCRC: calculationCrc(payload),
|
||||||
|
PayloadLength: payload.length,
|
||||||
|
PayloadType: PayloadType,
|
||||||
|
);
|
||||||
|
String serializedBytesString = message.serialize();
|
||||||
|
return _hexToBytes(serializedBytesString);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenericRespError 消息
|
||||||
|
static List<int> genericRespErrorMessage({
|
||||||
|
required String FromPeerId,
|
||||||
|
required String ToPeerId,
|
||||||
|
required int PayloadType,
|
||||||
|
}) {
|
||||||
|
final genericResp = GenericResp();
|
||||||
|
genericResp.message = 'error';
|
||||||
|
genericResp.code = -1;
|
||||||
|
final payload = genericResp.writeToBuffer();
|
||||||
|
ScpMessage message = ScpMessage(
|
||||||
|
ProtocolFlag: ProtocolFlagConstant.scp01,
|
||||||
|
MessageType: MessageTypeConstant.Resp,
|
||||||
|
MessageId: 1,
|
||||||
|
SpTotal: 0,
|
||||||
|
SpIndex: 0,
|
||||||
|
FromPeerId: FromPeerId,
|
||||||
|
ToPeerId: ToPeerId,
|
||||||
|
Payload: payload,
|
||||||
|
PayloadCRC: calculationCrc(payload),
|
||||||
|
PayloadLength: payload.length,
|
||||||
|
PayloadType: PayloadType,
|
||||||
|
);
|
||||||
|
String serializedBytesString = message.serialize();
|
||||||
|
return _hexToBytes(serializedBytesString);
|
||||||
|
}
|
||||||
|
|
||||||
// 辅助方法:将16进制字符串转换为字节列表
|
// 辅助方法:将16进制字符串转换为字节列表
|
||||||
static List<int> _hexToBytes(String hex) {
|
static List<int> _hexToBytes(String hex) {
|
||||||
final bytes = <int>[];
|
final bytes = <int>[];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user