交互
This commit is contained in:
@ -0,0 +1,17 @@
|
||||
import { Connect, Server } from "@Packages/message";
|
||||
import { extConnect } from "@Packages/message/extension";
|
||||
import { WindowServer } from "@Packages/message/window";
|
||||
|
||||
function main() {
|
||||
// 与sandbox建立连接
|
||||
const extClient = new Connect(extConnect());
|
||||
const server = new Server(new WindowServer(window));
|
||||
server.on("connection", (con) => {
|
||||
const wrapCon = new Connect(con);
|
||||
wrapCon.on("forward", (data, resp) => {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
|
@ -1 +1,11 @@
|
||||
eval('console.log("Hello from sandbox!");');
|
||||
import { Connect } from "@Packages/message";
|
||||
import { windowConnect } from "@Packages/message/window";
|
||||
|
||||
function main() {
|
||||
const client = new Connect(windowConnect(window, window.parent));
|
||||
client.emit("recv", "123", (resp: string) => {
|
||||
console.log("sandbox", resp);
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ExtServer } from "@Packages/message/extension";
|
||||
import { Server } from "@Packages/message";
|
||||
import { Connect, Server } from "@Packages/message";
|
||||
|
||||
async function setupOffscreenDocument() {
|
||||
// 创建运行后台脚本的沙盒环境
|
||||
@ -18,14 +18,17 @@ async function setupOffscreenDocument() {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// 监听消息
|
||||
const server = new Server(new ExtServer());
|
||||
server.on("connection", (con) => {
|
||||
const wrapCon = new Connect(con);
|
||||
wrapCon.on("recv", (data,resp) => {
|
||||
console.log(data);
|
||||
resp("service_wwww");
|
||||
});
|
||||
});
|
||||
// 初始化沙盒环境
|
||||
await setupOffscreenDocument();
|
||||
// 监听消息
|
||||
const extServer = new ExtServer();
|
||||
const server = new Server(extServer);
|
||||
server.on("", (con) => {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
|
Reference in New Issue
Block a user