Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make artoolkit.api.js node.js compliant and remove references to DOM object in typescript version and javascript #128

Open
kalwalt opened this issue Mar 9, 2022 · 5 comments

Comments

@kalwalt
Copy link
Member

kalwalt commented Mar 9, 2022

There few key points to solve to make artoolkitNFT.api.js (to be precise the libs compiled with artoolkitNFT.api.js -> artoolkitNFT_wasm.js and artoolkitNFT.min.js) to use on node.js. At the moment it can not be used because there are DOM objects and self is not recognized as globalThis:

var scope;
if (typeof window !== 'undefined') {
scope = window;
} else {
scope = self;
}

self is accepted in a worker env but not under NODE.
I think that code should add a conditional with scope = global for the NODE env.
Plus we need to remove all references to canvas or document objects. We don't need them because we pass imageData. This is also applicable to the Typescript version and need a rewrite in this sense.

@kalwalt
Copy link
Member Author

kalwalt commented Mar 9, 2022

Inside artoolkitNFT.api.js and ARControllerNFT.ts will try to remove canvas, ctx, image, options, and orientation properties from ARControllerNFT class. Maybe i can remove other part of the code.

@kalwalt
Copy link
Member Author

kalwalt commented Mar 11, 2022

Inside artoolkitNFT.api.js and ARControllerNFT.ts will try to remove canvas, ctx, image, options, and orientation properties from ARControllerNFT class. Maybe i can remove other part of the code.

This is not enough, the lib will fail while loading the camera or other resources because it is based on XMLHttpRequest that is not supported on a Node.js environment. It's needed to change the ajax function to another that use FS.readFile(), we have already FS thanks to Emscripten, so it shouldn't be too difficult...

@kalwalt
Copy link
Member Author

kalwalt commented Mar 11, 2022

You can do this simple test, given this code:

var Module = require('../build/artoolkitNFT_wasm.js')

Module.onRuntimeInitialized = async function(){
 
    var ar = new ARControllerNFT(640, 480, '../examples/Data/camera_para.dat');
 
}

You will get this error:

ReferenceError: XMLHttpRequest is not defined
    at ajax (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:12857)
    at Object.loadCamera (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:12412)
    at ARCameraParamNFT.load (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:9344)
    at new ARCameraParamNFT (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:9043)
    at new ARControllerNFT (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:828)
    at Object.Module.onRuntimeInitialized (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/tests/test2.js:7:14)
    at doRun (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:781091)
    at run (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:781251)
    at runCaller (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:780759)
    at removeRunDependency (/home/walter/kalwalt-github/webarkit-org/jsartoolkitNFT/build/artoolkitNFT_wasm.js:1:23840)


@kalwalt
Copy link
Member Author

kalwalt commented Mar 11, 2022

Note that also the dist lib ARToolkitNFT.js will fails under node.js with a similar error.

@kalwalt
Copy link
Member Author

kalwalt commented Mar 11, 2022

We should build the dist lib with these instructions axios/axios#456 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant