Skip to content

Commit

Permalink
🐛 [plugin/cli] cli-0.4.8 client-0.4.2 通信中需要获取的是对方的消息
Browse files Browse the repository at this point in the history
  • Loading branch information
waterbang committed Oct 26, 2023
1 parent 5b1848b commit 4ad0ffe
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion plaoc/cli/plaoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { doWebAdvCommand } from "./web-dav.ts";
await new Command()
.name("@plaoc/cli")
.description("plaoc front-end and back-end packaging tools.")
.version(`v0.4.7`)
.version(`v0.4.8`)
.command("serve", doServeCommand)
.example("developer service", "plaoc serve http://xx.xx.xx.xx:xxxx/")

Expand Down
12 changes: 2 additions & 10 deletions plaoc/demo/src/pages/DwebServiceWorker.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import LogPanel, { defineLogAction } from "../components/LogPanel.vue";
import { dwebServiceWorker, toastPlugin, updateControllerPlugin } from "../plugin";
import { dwebServiceWorker, updateControllerPlugin } from "../plugin";
const $logPanel = ref<typeof LogPanel>();
// let console: Console;
Expand Down Expand Up @@ -80,14 +80,6 @@ const download = defineLogAction(
{ name: "download", args: [], logPanel: $logPanel }
);
const check = defineLogAction(
async () => {
const { version } = await updateControllerPlugin.getVersion();
toastPlugin.show({ text: `当前版本:${version}` });
},
{ name: "check", args: [], logPanel: $logPanel }
);
const message = ref("这里显示收到的消息");
// 向desktop.dweb.waterbang.top.dweb 发送消息
Expand All @@ -100,6 +92,7 @@ const sayHi = async () => {
};
dwebServiceWorker.addEventListener("fetch", async (event) => {
console.log("Dweb Service Worker fetch!", event);
console.log("xxxx=>", await event.getRemoteManifest());
const url = new URL(event.request.url);
if (url.pathname.endsWith("/say/hi")) {
const hiMessage = url.searchParams.get("message");
Expand Down Expand Up @@ -135,7 +128,6 @@ const title = "Dweb Service Worker";
<h2 class="card-title">下载测试</h2>
<div class="justify-end card-actions btn-group">
<button class="inline-block rounded-full btn btn-accent" @click="download">下载新版本</button>
<button class="inline-block rounded-full btn btn-accent" @click="check">检查版本升级</button>
</div>
<div>
<progress class="w-56 progress progress-accent" :value="progress" max="100"></progress>
Expand Down
2 changes: 1 addition & 1 deletion plaoc/scripts/npm.cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"watchDir": "./src/cli",
"denoShim": true,
"name": "@plaoc/cli",
"version": "0.4.7",
"version": "0.4.8",
"lib": [
"ES2022",
"DOM"
Expand Down
2 changes: 1 addition & 1 deletion plaoc/scripts/npm.client.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"watchDir": "./src/client",
"denoShim": false,
"name": "@plaoc/plugins",
"version": "0.4.1",
"version": "0.4.2",
"importMap": "./import_map.json",
"lib": [
"ES2022",
Expand Down
5 changes: 3 additions & 2 deletions plaoc/src/client/components/dweb-service-worker/FetchEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export class ServiceWorkerFetchEvent extends Event {
}
/**查询连接者的信息 */
async getRemoteManifest():Promise<$JmmAppInstallManifest> {
const { ipc } = this.fetchEvent;
const mmid = ipc.remote.mmid;
const { request } = this.fetchEvent;
const mmid = request.headers.get("x-Dweb-Host");
console.log("getRemoteManifest查询id=>",mmid)
const res = await this.plugin.buildApiRequest("/query",{
pathPrefix:"dns.std.dweb",
search:{
Expand Down
1 change: 1 addition & 0 deletions plaoc/src/server/http-external-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class Server_external extends HttpServer {
}
const ext_options = this._getOptions();
// 请求跟外部app通信,并拿到返回值
event.headers.append("X-Dweb-Host",jsProcess.mmid)
return await jsProcess.nativeFetch(
`http://${ext_options.subdomain}.${mmid}:${ext_options.port}${event.pathname}${event.search}`,
{
Expand Down

0 comments on commit 4ad0ffe

Please sign in to comment.