1

I've been working with a Javascript library, namely, canvas-lib and I'm using Node.JS/Socket.io on the server side so I can pass events between clients.

I'm using an architecture in which only 1 client at a time is allowed control over the canvas since I'm making kind of a "scratch" game which is controlled by a mobile device and displayed on an second (bigger) screen.

You can see a diagram of the architecture here.

The thing is, currently the canvas interaction is done on the client side on a script for that effect which causes the some problems:

  • There's no way of scaling the canvas
  • There's not a unified time limit counter
  • I have to manually load the page on the external screen

My objectives are:

  • To have the server pass the time to both devices (or screens)
  • To have the canvas loaded on the mobile device and scaled to the external screen (on new connection, and done automatically once the mobile device is connected, or out of the queue and into current active)

In order to achieve this, I believe I must get the canvas-lib to work on node, so how can I achieve this since the lib is not ready for that yet? How can I turn a regular library into a Node library?

2 Answers 2

1

Well,

if you're developing a library which does stuff specifically for browsers I can't see any point in making a Node package for it.

But anyway, please take a look at the Node Package Manager (NPM for short), it'll help you whenever you need to develop some Node library.

Sign up to request clarification or add additional context in comments.

1 Comment

I already know NPM ;) but there's just nothing there to achieve what I want. Maybe I'm constructing my code poorly but shouldn't I be able to order the browser to load a given page at the same time that page is loaded on a mobile device (if I get that to the server side)?
1

Some of the things I've done to make Fabric.js node-compatible:

  • Use node-canvas which provides canvas API in node environment.
  • Provide (or prevent) access to any DOM objects that library might be using. See jsdom.
  • Remove calls to proprietary (browser-only) API. See non-standard features.
  • Adapt library's test suite to run under node (if it doesn't yet). See mocha or qunit.
  • Run test suite and make sure everything still functions as expected.
  • (optionally) Create NPM package for convenience.

Or you can just use the library that already provides support for node ;)

2 Comments

Hi, thanks for the info. Although your method seems to be fine, it's not good enough for me. I'm "drawing" on the canvas based on touch input, and apparently Fabric.js is only good at working with other data types on top of a canvas. Node-canvas is not a good enough option too because it depends on .png images which will cause the real-time actions to be lost..
Touch-based free drawing? Yeah, it's not Fabric's best forte, although touch is supported (for transforming objects). There's also support for free drawing in Fabric, but I'm not 100% sure if it works with touch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.