Skip to content

Commit

Permalink
seperate worker
Browse files Browse the repository at this point in the history
  • Loading branch information
booploops committed Jun 27, 2024
1 parent 05147ce commit 08ac26a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
16 changes: 16 additions & 0 deletions airplay-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const {
Worker,
isMainThread,
parentPort,
workerData,
} = require("node:worker_threads");
var { WebSocketServer } = require("ws");
const wss = new WebSocketServer({ port: 8980 });
wss.on("connection", function connection(ws) {
ws.on("message", function message(data) {
parentPort.postMessage({ message: data });
});
parentPort.on("message", (data) => {
ws.send(data);
});
});
15 changes: 2 additions & 13 deletions izanami.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,8 @@ airtunes.on('device', function(key, status, desc) {
console.log("deviceStatus", key, status, desc);
})

var func = `
const {Worker, isMainThread, parentPort, workerData} = require('node:worker_threads');
var { WebSocketServer } = require('ws');
const wss = new WebSocketServer({ port: 8980 });
wss.on('connection', function connection(ws) {
ws.on('message', function message(data) {
parentPort.postMessage({message: data});
});
parentPort.on("message", data => {
ws.send(data);
});
});`;
var worker = new Worker(func, {eval: true});

var worker = new Worker('./airplay-worker.js');
worker.on("message", (result) => {
parsed_data = JSON.parse(ab2str(result.message));
if (parsed_data.type == "scanDevices") {
Expand Down
20 changes: 18 additions & 2 deletions scripts/esbuild.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
// @ts-check

async function main() {
await require("esbuild").build({
entryPoints: ["./airplay-worker.js"],
bundle: true,
platform: "node",
outdir: "dist",
external: ["./build"],
loader: {
".node": "file",
},
// minify: true,
// minifyIdentifiers: true,
sourcemap: true,
});

await require("esbuild").build({
entryPoints: ["./izanami.js"],
bundle: true,
platform: "node",
outdir: "dist",
external: ['./build'],
external: ["./build"],
loader: {
'.node': 'file',
".node": "file",
},
sourcemap: true,

// minify: true,
// minifyIdentifiers: true,
});
Expand Down

0 comments on commit 08ac26a

Please sign in to comment.