Skip to content

Commit

Permalink
window.postMessage(JSON.stringnify(res.dump()))
Browse files Browse the repository at this point in the history
  • Loading branch information
womendoushihaoyin committed Dec 31, 2024
1 parent f6706d0 commit 6695681
Show file tree
Hide file tree
Showing 77 changed files with 206,944 additions and 49,256 deletions.
2 changes: 1 addition & 1 deletion resources/web/flutter/.last_build_id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
692bc11668d092ce09f24224d1d2d6e7
9b1a33ccdfb365d646fd0a03d6abbb77
Binary file modified resources/web/flutter/assets/AssetManifest.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion resources/web/flutter/assets/AssetManifest.bin.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"DQEHMnBhY2thZ2VzL2N1cGVydGlub19pY29ucy9hc3NldHMvQ3VwZXJ0aW5vSWNvbnMudHRmDAENAQcFYXNzZXQHMnBhY2thZ2VzL2N1cGVydGlub19pY29ucy9hc3NldHMvQ3VwZXJ0aW5vSWNvbnMudHRm"
"DQA="
2 changes: 1 addition & 1 deletion resources/web/flutter/assets/AssetManifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"packages/cupertino_icons/assets/CupertinoIcons.ttf":["packages/cupertino_icons/assets/CupertinoIcons.ttf"]}
{}
2 changes: 1 addition & 1 deletion resources/web/flutter/assets/FontManifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"family":"MaterialIcons","fonts":[{"asset":"fonts/MaterialIcons-Regular.otf"}]},{"family":"packages/cupertino_icons/CupertinoIcons","fonts":[{"asset":"packages/cupertino_icons/assets/CupertinoIcons.ttf"}]}]
[]
318 changes: 295 additions & 23 deletions resources/web/flutter/assets/NOTICES

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/web/flutter/flutter_bootstrap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions resources/web/flutter/flutter_service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@ const MANIFEST = 'flutter-app-manifest';
const TEMP = 'flutter-temp-cache';
const CACHE_NAME = 'flutter-app-cache';

const RESOURCES = {"flutter_bootstrap.js": "c92ccc0e3d654d7074a982148aa54bad",
"version.json": "6aaf3dbc0345fe0ecf201ad7e63acbe1",
"index.html": "4cba545091aa91322b8268eb988f5347",
"/": "4cba545091aa91322b8268eb988f5347",
"main.dart.js": "22b98aded89baec573ea52f76481d2d8",
const RESOURCES = {"flutter_bootstrap.js": "998855bfaa183a7addca2d581dfea973",
"version.json": "e1c4f22753735d91caf5a154114c1370",
"index.html": "1ad14fded796c3d5935f7323dd2d9976",
"/": "1ad14fded796c3d5935f7323dd2d9976",
"main.dart.js": "ef34130afee7ec66a7fde97543a045bd",
"flutter.js": "383e55f7f3cce5be08fcf1f3881f585c",
"favicon.png": "5dcef449791fa27946b3d35ad8803796",
"icons/Icon-192.png": "ac9a721a12bbc803b44f645561ecb1e1",
"icons/Icon-maskable-192.png": "c457ef57daa1d16f64b27b786ec2ea3c",
"icons/Icon-maskable-512.png": "301a7604d45b3e739efc881eb04896ea",
"icons/Icon-512.png": "96e752610906ba2a93c65f8abe1645f1",
"manifest.json": "613fe7569c595f3399a3d8b2c4f6fdfa",
"assets/AssetManifest.json": "2efbb41d7877d10aac9d091f58ccd7b9",
"assets/NOTICES": "ae41ea2e645699fda4e4789a0e341ea5",
"assets/FontManifest.json": "dc3d03800ccca4601324923c0b1d6d57",
"assets/AssetManifest.bin.json": "69a99f98c8b1fb8111c5fb961769fcd8",
"assets/packages/cupertino_icons/assets/CupertinoIcons.ttf": "e986ebe42ef785b27164c36a9abc7818",
"manifest.json": "901d86fb8842ec0d66225a542131d689",
"assets/AssetManifest.json": "99914b932bd37a50b983c5e7c90ae93b",
"assets/NOTICES": "376d20da61b3df5046f0df87cc8a73b6",
"assets/FontManifest.json": "d751713988987e9331980363e24189ce",
"assets/AssetManifest.bin.json": "a1fee2517bf598633e2f67fcf3e26c94",
"assets/shaders/ink_sparkle.frag": "ecc85a2e95f5e9f53123dcaf8cb9b6ce",
"assets/AssetManifest.bin": "693635b5258fe5f1cda720cf224f158c",
"assets/fonts/MaterialIcons-Regular.otf": "8ea08ea2444cc58ec5807fd7669e488f",
"assets/AssetManifest.bin": "0b0a3415aad49b6e9bf965ff578614f9",
"canvaskit/skwasm.js": "5d4f9263ec93efeb022bb14a3881d240",
"canvaskit/skwasm.js.symbols": "c3c05bd50bdf59da8626bbe446ce65a3",
"canvaskit/canvaskit.js.symbols": "74a84c23f5ada42fe063514c587968c6",
Expand Down
214 changes: 93 additions & 121 deletions resources/web/flutter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="/flutter/">

Expand All @@ -24,153 +23,126 @@
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="web_flutter_module">
<meta name="apple-mobile-web-app-title" content="web">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>

<title>web_flutter_module</title>
<title>web</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<script src="flutter_bootstrap.js" async></script>

<script>
// SSWCP函数
function sw_SendGCodes(str, callback_name){
params = {
header: {
sequenceId: 4,
},

payload:{
cmd: "sw_SendGCodes",
callback_name: callback_name,
params:{
codes: ["T0", "T1", "T2", "T3", "T0"],

function getDeviceData() {
var devices = {
'90F3A2F30063C233': {
'ip': '172.18.1.33',
'port': '1883',
'name': 'lava-90F-233',
'sn': '90F3A2F30063C233',
},
'9BD4E436F33D0B56': {
'ip': '172.18.0.46',
'port': '1883',
'name': 'lava-9BD-B56',
'sn': '9BD4E436F33D0B56'
},
'BE667E5F8A060BDF': {
'ip': '172.18.1.91',
'port': '1883',
'name': 'lava-BE6-BDF',
'sn': 'BE667E5F8A060BDF'
},
'BC0810C948A828C0': {
'ip': '172.18.0.62',
'port': '1883',
'name': 'lava-BC0-8C0',
'sn': 'BC0810C948A828C0'
},
'58317961E7DBEF34': {
'ip': '172.18.1.54',
'port': '1883',
'name': 'lava-583-F34',
'sn': '58317961E7DBEF34'
},
'A4C0111397B11BBB': {
'ip': '172.18.0.65',
'port': '1883',
'name': 'lava-A4C-BBB',
'sn': 'A4C0111397B11BBB'
}
}


};
window.wx.postMessage(JSON.stringify(params));
}
function on_gcode_sent(response){
console.log(response);
return devices;
}
function sw_StopMachineFind(params, callback_name){
params = {
sequenceId: 3,
cmd: "sw_StopMachineFind",
data: {},
callback_name: "",
};

window.wx.postMessage(JSON.stringify(params));
}
var j_header;

function sw_StartMachineFind(parmas, callback_name){
// 接收来自于 Flutter 的消息
function onMessageFromFlutter(headerJson, payloadJson) {

params = {
header:{
sequenceId: 2,
},
payload:{
cmd: "sw_StartMachineFind",
params: {
event_id: "send_machine_list",
try {
// 反序列化 header 和 payload
const header = JSON.parse(headerJson);
const payload = JSON.parse(payloadJson);

j_header = header;

// console.log("Deserialized Header:", header);
// console.log("Deserialized Payload:", payload);
// console.log("Web receiveFromFlutter header: " + header.map + ", payload: ", payload.toString());
if (payload['cmd'] == 'sw_StartMachineFind') {
// 开始机器发现
var devices = getDeviceData(header, payload);
var tSend = {
"header": header,
"payload": {
'cmd': payload['cmd'],
'data': payload['data'],
},
};

var mokeData={
"header": header,
"payload": {
'code': 200,
'data': devices,
'msg': 'ok',
}
};
// console.log("Web sendToFlutter header: " + JSON.stringify(mokeData) );
// 延迟 2 秒后调用回调函数
setTimeout(() => {
// callback(JSON.stringify(mokeData));
// window.postMessage(JSON.stringify(mokeData), '*'); // 调用 window.postMessage 传递消息给 flutter
}, 2000);
}
};

window.wx.postMessage(JSON.stringify(params));
}

function on_machine_list_arrived(response){
console.log(response);
}


function test_sswcp(input, test_callback){
param = {
header:{
sequenceId: 1,
},
payload:{
cmd: "test",
params: input,
callback_name: test_callback,
},
};
window.wx.postMessage(JSON.stringify(param));
}

function test_callback(response){
console.log(response);
}

function test_sswcp_async(input, test_callback){
param = {
sequenceId: 1,
cmd: "test_async",
data: input,
callback_name: test_callback,
};
window.wx.postMessage(JSON.stringify(param));
}

function test_async_callback(response){
console.log(response);
}
// 定义一个 JS 函数
function receiveFromFlutter(data, callback) {
// 处理从 Flutter 传递过来的消息
// 这里可以根据实际情况处理消息
//message 为从 List
// console.log("Flutter Web Function: [receiveFromFlutter] from Flutter: ", data);

var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_login_or_register";
tSend['data']={};
tSend['data']['token']="AAAAA-VVVVV-SSSSS-UUUUU-YYYYY";
callback(JSON.stringify(tSend)); // 调用 JS 回调函数
}

function sendMessageToJs(data) {
//console.log("Flutter Web Function: [sendMessageToJs] from Flutter: ", data);
}

function registerCallback(data) {
// console.log("Flutter Web Function: [registerCallback] from Flutter: ", message);
}

function getToken(callback) {
console.log("Flutter Web Function: [getToken] from Flutter: ");
var token = "AAAAA-VVVVV-SSSSS-UUUUU-YYYYY";
// 获取用户 token
// 这里可以根据实际情况获取 token
callback(token); // 调用 JS 回调函数
return token;

window.wx.postMessage(JSON.stringify(tSend));
} catch (error) {
console.error("Error parsing JSON:", error);
}
}

function unregisterCallback(data) {
console.log("Flutter Web Function: [unregisterCallback] from Flutter: ", message);
function test(res) {
window.postMessage(JSON.stringify(res), '*'); // 调用 window.postMessage 传递消息给 flutter
}



// 注册 Flutter 传递过来的消息处理函数 或者直接使用 window.postMessage 发送消息
window.sswcp.sendMessageToFlutter = function (message) {
// 发送消息给Flutter
window.sendMessageToFlutter = function (message) {
// console.log("window.sendMessageToFlutter: " + message);
window.postMessage(message, '*'); // 调用 window.postMessage 传递消息给 flutter
}

window.addEventListener('message', function (event) {
// console.log("window.addEventListener: " + event.data + " from " + event.message);

}); // 监听 flutter 传递过来的消息

window.addEventListener('message', function (event) {
console.log("testtesttesttesttesttesttesttesttesttesttesttesttesttesttest");
console.log(event.data);
});
</script>

</body>
</html>
Loading

0 comments on commit 6695681

Please sign in to comment.