https://qianduan.life
`// Node.js主進程中調起子進程 await screen_window(); //function screen_window import { execFile } from 'child_process'; import path from 'path'; import ipcSend from '../main/utils/ipcSender'; function screen_window() { return new Promise((resolve, reject) => { const screen_window = execFile(path.resolve($dirname, '../screenshot/PrintScr.exe')); screen_window.on('exit', function(code) { if (code === 1) { ipcSend.insertImage(); } resolve(); }); }); } export default screen_window;`
https://github.com/JinJieTan/speex-in-h5
webAssembly
?https://www.wasm.com.cn/demo/Tanks/
,這是坦克!,Unity 教程
中的一個遊戲 導出成WebAssembly 的遊戲.但是我在國外網站上看到的內容是說: 每一個WebAssembly線程都在Web Worker中運行,至關於跟JS主解析線程是分開的,不會阻塞JS主線程的解析
https://hacks.mozilla.org/2017/06/a-crash-course-in-memory-management/
WebAssembly.compile(new Uint8Array(` 00 61 73 6d 01 00 00 00 01 0c 02 60 02 7f 7f 01 7f 60 01 7f 01 7f 03 03 02 00 01 07 10 02 03 61 64 64 00 00 06 73 71 75 61 72 65 00 01 0a 13 02 08 00 20 00 20 01 6a 0f 0b 08 00 20 00 20 00 6c 0f 0b`.trim().split(/[\s\r\n]+/g).map(str => parseInt(str, 16)) )).then(module => { const instance = new WebAssembly.Instance(module) const { add, square } = instance.exports console.log('2 + 4 =', add(2, 4)) console.log('3^2 =', square(3)) console.log('(2 + 5)^2 =', square(add(2 + 5))) })``
https://www.wasm.com.cn/getting-started/developers-guide/
在將來計劃中,WebAssembly 模塊可使用 ES6 模塊(使用<script type="module">
)加載,WebAssembly 目前只能經過 JavaScript 來加載和編譯。基礎的加載,只須要3步:前端
`/** * @param {String} path wasm 文件路徑 * @param {Object} imports 傳遞到 wasm 代碼中的變量 */ function loadWebAssembly (path, imports = {}) { return fetch(path) .then(response => response.arrayBuffer()) .then(buffer => WebAssembly.compile(buffer)) .then(module => { imports.env = imports.env || {} // 開闢內存空間 imports.env.memoryBase = imports.env.memoryBase || 0 if (!imports.env.memory) { imports.env.memory = new WebAssembly.Memory({ initial: 256 }) } // 建立變量映射表 imports.env.tableBase = imports.env.tableBase || 0 if (!imports.env.table) { // 在 MVP 版本中 element 只能是 "anyfunc" imports.env.table = new WebAssembly.Table({ initial: 0, element: 'anyfunc' }) } // 建立 WebAssembly 實例 return new WebAssembly.Instance(module, imports) }) }`
`loadWebAssembly('path/to/math.wasm') .then(instance => { const { add, square } = instance.exports // ... })`
https://zhuanlan.zhihu.com/p/27910351
使用方法:`self.importScripts('ffmpeg.js'); onmessage = function(e) { console.log('ffmpeg_run', ffmpeg_run); var files = e.data; console.log(files); ffmpeg_run({ arguments: ['-i', '/input/' + files[0].name, '-b:v', '64k', '-bufsize', '64k', '-vf', 'showinfo', '-strict', '-2', 'out.mp4'], files: files, }, function(results) { console.log('result',results); self.postMessage(results[0].data, [results[0].data]); }); }`
前端巔峯