Files
Public/apps/native/lib/im/im_bridge.dart
T
daiyongkang 76f266645d Initial commit: 风影 OA 全栈源码(API/Web/Flutter/IM)
含 Phase 1.1 IM seq 排序、断线重连、多端已读同步与微信式语音转文字 UI。
排除 node_modules、构建产物、安装包与 .env 密钥。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 10:04:03 +00:00

39 lines
1.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/services.dart';
/// 与官方 MobileIMSDK 对齐的生命周期:登录前 init,退出 release。
/// Android 走 MethodChannelWindows/Linux 无原生插件时回落到 Dart TCP。
class ImBridge {
static const _ch = MethodChannel('com.fysxkj.oa/im');
bool nativeReady = false;
String engine = 'dart-tcp';
Future<void> init() async {
try {
final r = await _ch.invokeMethod<Map>('init');
nativeReady = r?['ok'] == true || r?['initialized'] == true;
engine = '${r?['engine'] ?? 'dart-tcp'}';
} on MissingPluginException {
nativeReady = false;
engine = 'dart-tcp';
} catch (_) {
nativeReady = false;
engine = 'dart-tcp';
}
}
Future<void> release() async {
try {
await _ch.invokeMethod('release');
} catch (_) {}
nativeReady = false;
}
Future<String> status() async {
try {
final r = await _ch.invokeMethod<String>('engine');
if (r != null && r.isNotEmpty) engine = r;
} catch (_) {}
return engine;
}
}