Initial commit: 风影 OA 全栈源码(API/Web/Flutter/IM)
含 Phase 1.1 IM seq 排序、断线重连、多端已读同步与微信式语音转文字 UI。 排除 node_modules、构建产物、安装包与 .env 密钥。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
/// MobileIMSDK 官方 TCP 帧:4 字节大端长度 + UTF-8 JSON Protocal。
|
||||
class ClientType {
|
||||
static const login = 0;
|
||||
static const keepAlive = 1;
|
||||
static const commonData = 2;
|
||||
static const logout = 3;
|
||||
static const received = 4;
|
||||
static const echo = 5;
|
||||
}
|
||||
|
||||
class ServerType {
|
||||
static const login = 50;
|
||||
static const keepAlive = 51;
|
||||
static const error = 52;
|
||||
static const echo = 53;
|
||||
static const kickout = 54;
|
||||
}
|
||||
|
||||
class Protocal {
|
||||
Protocal({
|
||||
required this.type,
|
||||
this.dataContent = '',
|
||||
this.from = '0',
|
||||
this.to = '0',
|
||||
this.fp,
|
||||
this.qos = false,
|
||||
this.typeu = -1,
|
||||
this.sm = -1,
|
||||
});
|
||||
|
||||
int type;
|
||||
String dataContent;
|
||||
String from;
|
||||
String to;
|
||||
String? fp;
|
||||
bool qos;
|
||||
int typeu;
|
||||
int sm;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'bridge': false,
|
||||
'type': type,
|
||||
'dataContent': dataContent,
|
||||
'from': from,
|
||||
'to': to,
|
||||
'fp': fp,
|
||||
'QoS': qos,
|
||||
'typeu': typeu,
|
||||
'sm': sm,
|
||||
};
|
||||
|
||||
factory Protocal.fromJson(Map<String, dynamic> j) => Protocal(
|
||||
type: (j['type'] as num?)?.toInt() ?? 0,
|
||||
dataContent: '${j['dataContent'] ?? ''}',
|
||||
from: '${j['from'] ?? '0'}',
|
||||
to: '${j['to'] ?? '0'}',
|
||||
fp: j['fp']?.toString(),
|
||||
qos: j['QoS'] == true || j['qos'] == true,
|
||||
typeu: (j['typeu'] as num?)?.toInt() ?? -1,
|
||||
sm: (j['sm'] as num?)?.toInt() ?? -1,
|
||||
);
|
||||
}
|
||||
|
||||
Uint8List encodeFrame(Protocal p) {
|
||||
final body = utf8.encode(jsonEncode(p.toJson()));
|
||||
final header = ByteData(4)..setUint32(0, body.length);
|
||||
return Uint8List.fromList([...header.buffer.asUint8List(), ...body]);
|
||||
}
|
||||
|
||||
const maxBody = 6 * 1024;
|
||||
Reference in New Issue
Block a user