102 lines
3.1 KiB
Dart
102 lines
3.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:EasyDartModule/EasyDartModule.dart';
|
|
import 'package:EasyDartModule/base/logger/Logger.dart';
|
|
import 'package:EasyDartModule/base/redis/redis.dart';
|
|
import 'package:EasyDartModule/base/websocket/WebSocket.dart';
|
|
|
|
import './controller/AreaController.dart';
|
|
|
|
import 'const/ServiceConstant.dart';
|
|
|
|
import './const/CommonVariables.dart';
|
|
|
|
void main(List<String> args) async {
|
|
initEasyDartModule();
|
|
}
|
|
|
|
Future<void> initEasyDartModule() async {
|
|
try {
|
|
String? web = Platform.environment["web_port"] ?? "9200";
|
|
List<String> redis =
|
|
(Platform.environment["redis"] ?? "default@localhost:6379/0")
|
|
.split(":");
|
|
String host;
|
|
int port = 6379;
|
|
String? password;
|
|
int db = 0;
|
|
var hs = redis[0].split("@");
|
|
if (hs.length == 2) {
|
|
host = hs[1];
|
|
if (hs[0] != "default") {
|
|
password = hs[0];
|
|
}
|
|
} else {
|
|
host = hs[0];
|
|
}
|
|
var pd = redis[1].split("/");
|
|
if (pd.length == 2) {
|
|
db = int.parse(pd[1]);
|
|
port = int.parse(pd[0]);
|
|
} else {
|
|
port = int.parse(pd[0]);
|
|
}
|
|
|
|
EasyDartModule.init(
|
|
loggerConfig: LoggerConfig(
|
|
host: ServiceConstant.logService, serviceName: "快检报告服务"),
|
|
redisConfig: RedisConfig(
|
|
host: host, port: port, database: db, password: password),
|
|
webSocketConfig:
|
|
WebSocketConfig(ServiceConstant.webSocketService, (data) {
|
|
// 接收到服务消息
|
|
var json = jsonDecode(data);
|
|
// ef.log("[websokcet]:${json}");
|
|
EasyDartModule.logger.info("[websokcet数据]:${json}");
|
|
if (json['wsId'] != null) {
|
|
// ef.kvRoot.websocketId = json['wsId'];
|
|
}
|
|
if (json['code'] != null && json['code'] != 200) {
|
|
EasyDartModule.logger
|
|
.error("[websokcet数据]:websocket连接失败--》" + json['msg']);
|
|
}
|
|
if (json["path"] != null) {
|
|
var call = CommonVariables.callMap[json["path"]];
|
|
if (call != null) {
|
|
try {
|
|
if (json['path'] != "/smartbed/connect") {
|
|
call(json["data"]);
|
|
} else {
|
|
call(json);
|
|
}
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
} else {
|
|
print("未找到当前路径: ${json["path"]} 回调函数");
|
|
EasyDartModule.logger.error("未找到当前路径: ${json["path"]} 回调函数");
|
|
}
|
|
}
|
|
// print(data);
|
|
}, onOpen: () {
|
|
// 连接建立完毕
|
|
// EasyDartModule.websocket
|
|
// .sendData(jsonEncode({"path": "/aa/bb", "type": 1}));
|
|
print("object");
|
|
}));
|
|
|
|
while (!EasyDartModule.redis.isConnected()) {
|
|
await Future.delayed(Duration(seconds: 1));
|
|
}
|
|
// EasyDartModule.webServer.addHandler(StatisticsController());
|
|
EasyDartModule.webServer.addHandler(AreaController());
|
|
EasyDartModule.webServer.start(
|
|
int.parse(web),
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
EasyDartModule.logger.error("websocket连接失败--》:$e");
|
|
}
|
|
}
|