mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-04-18 18:18:42 +00:00
Introduce a StdioServer module and mcploader entry script, and extend jsonrpc2 with an extract() helper. stdio-server.js provides an EventTarget-based wrapper for reading/writing via WScript stdio. mcploader.js uses the server and JsonRpc2.extract to parse incoming JSON-RPC messages and respond. Also change DEFAULT_JSONRPC2_URL to http://localhost:5555, export the new extract function, and bump jsonrpc2 version to 0.1.6.
31 lines
704 B
JavaScript
31 lines
704 B
JavaScript
// mcploader.js
|
|
// Copyright 2019-2026, Namhyeon Go <gnh1201@catswords.re.kr> and the WelsonJS contributors.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// https://github.com/gnh1201/welsonjs
|
|
//
|
|
var StdioServer = require("lib/stdio-server");
|
|
var JsonRpc2 = require("lib/jsonrpc2");
|
|
|
|
function main(args) {
|
|
var server = StdioServer.create();
|
|
|
|
server.addEventListener("message", function(e) {
|
|
var message = e.target.receive();
|
|
|
|
try {
|
|
JsonRpc2.extract(message, function(method, params, id) {
|
|
console.log("Received method: " + method);
|
|
});
|
|
} catch (e) {
|
|
console.log("Ignored");
|
|
}
|
|
|
|
// send message
|
|
e.target.send("Hello world");
|
|
});
|
|
|
|
server.listen();
|
|
}
|
|
|
|
exports.main = main;
|