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

Unable to create 2D/GL/Audio context under Node.js #28

Closed
Siorki opened this issue Jun 14, 2015 · 2 comments
Closed

Unable to create 2D/GL/Audio context under Node.js #28

Siorki opened this issue Jun 14, 2015 · 2 comments
Assignees
Labels
Milestone

Comments

@Siorki
Copy link
Owner

Siorki commented Jun 14, 2015

When attempting to hash the methods for 2D / WebGL / Audio context, an instance of that context is created and used to enumerate methods and properties thereof.

This does not work when run with Node.js - server-side js does not know about Canvas, rendering context nor Audio context, since all of these are usually client-side operations.

Upon attempting to create a canvas (for 2D or WebGL context)

ReferenceError: document is not defined
    at Object.ShapeShifter.preprocess (shapeShifter.js:75:17)

Upon attempting to create an AudioContext

ReferenceError: AudioContext is not defined
    at Object.ShapeShifter.preprocess (shapeShifter.js:115:22)
@Siorki
Copy link
Owner Author

Siorki commented Jun 14, 2015

There are implementations of Canvas under node, such as node-canvas, however they may or may not have exactly the same methods as the canvas found in browsers (and even these differ, see #20). Sometimes they offer more methods, or implement them in advance of the spec.
Unfortunately, one needs a similar result whether RegPack is run in a browser or with node.js

@Siorki Siorki added the bug label Jun 14, 2015
@Siorki Siorki added this to the 4.0 milestone Jun 14, 2015
@Siorki
Copy link
Owner Author

Siorki commented Nov 21, 2015

Proposed solution : introduce a class named ContextDescriptor, in charge of building a list of context properties, methods and constat values, with different implementations :

  • under a browser, it lists methods and properties of real instances of the appropriate context
  • under Node, it uses hardcoded lists, which were derived from browsers implementations. These need to be updated whenever a browser introduces a new method in these contexts.

I am not exactly satisfied with that, even though there is no relevant alternative (node-canvas and other implementations suffer the same drawbacks). This design will at least allow for easy replacement of the ContextDescriptor implementation should a better solution arise.

@Siorki Siorki self-assigned this Nov 21, 2015
Siorki added a commit that referenced this issue Nov 21, 2015
Added ContextDescriptor - one implementation for the browser, one for
node.js
Automated all unit tests with node.js (node allTests)
@Siorki Siorki closed this as completed Nov 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant