JisolGame/headless/index.js
PC-20230316NUNE\Administrator 5ab90ea221 提交配置表
2023-11-21 18:52:01 +08:00

53 lines
1.8 KiB
JavaScript

// const URL = "http://192.168.0.174:7457/web-desktop/web-desktop/index.html"
const express = require("express");
const app = express();
const URL = "http://127.0.0.1:3000/static/index.html"
const runCocos = () => {
const { JSDOM,ResourceLoader } = require('jsdom')
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const WebGL = require('gl');
const WebGLRenderingContext = WebGL.WebGLRenderingContext;
WebGLRenderingContext.prototype.texSubImage2D = function(){};
const gl = WebGL(64, 64, { preserveDrawingBuffer: true });
const resourceLoader = new ResourceLoader({
proxy: URL,
strictSSL: false,
// userAgent: "Mellblomenator/9000",
});
fetch(URL).then(res => res.text()).then(html => {
console.log("HTML Index 文件: ",html)
global.window = (new JSDOM(html, {
url: URL,
referrer: URL,
contentType: "text/html; charset=utf-8",
resources:resourceLoader,
storageQuota: 10000000 ,
runScripts: "dangerously"
})).window;
let HGContext = window.HTMLCanvasElement.prototype.getContext;
window.TextDecoder = global.TextDecoder;
window.HTMLCanvasElement.prototype.getContext = function(type,data) {
if(type == "2d") {
const TD = HGContext.bind(this)(type,data);
TD.RenderComponentHandle = ()=>{}
return TD;
}
return gl;
};
window.requestAnimationFrame = global.requestAnimationFrame;
window.fetch = fetch;
})
setTimeout(() => {}, 99999999);
}
app.use('/static', express.static('static'))
app.listen(3000, () => {
console.log("服务启动");
runCocos();
});