初始化
This commit is contained in:
82
bin/main.dart
Normal file
82
bin/main.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
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"] ?? "127.0.0.1:6379").split(":");
|
||||
if (redis.length == 1) {
|
||||
redis.add("6379");
|
||||
}
|
||||
EasyDartModule.init(
|
||||
loggerConfig: LoggerConfig(
|
||||
host: ServiceConstant.logService, serviceName: "快检报告服务"),
|
||||
redisConfig: RedisConfig(host: redis[0], port: int.parse(redis[1])),
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user