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

canvas cannot be rendered automatically with socket data #1318

Closed
ferhtaydn opened this issue Apr 23, 2017 · 2 comments
Closed

canvas cannot be rendered automatically with socket data #1318

ferhtaydn opened this issue Apr 23, 2017 · 2 comments

Comments

@ferhtaydn
Copy link

Hi,

With v0.22 I can update the other browser tab content with view.draw(); while demoing some socket.io communication between separate browsers. (simply, drawing a path with one and see on the other side).

However, it is not working on v0.11.2 (latest). I also used mentioned here #675 but not worked. (I tried all browsers)

If I create new path, pointtext etc. they are rendered on the screen when got socket event but data coming from other socket is not rendered.

The example I am working on can be found at here: https://github.com/byrichardpowell/drawing

Thanks

@pinstripe-potatohead
Copy link

pinstripe-potatohead commented May 7, 2017

I have been facing this exact same problem.(Incidentally with the same Drawing example too).

The view doesn't refresh with view.draw(); or view.update(); - Path/Point items sent from the server to clients via socket.io are not rendered in the client with latest version (I'm using paper-jsdom-canvas v0.11.3), but the same works with v0.9.22.

@sasensi
Copy link
Contributor

sasensi commented Nov 13, 2018

The problem your are encountering is not related to view.draw() or view.update(), it is related to a change to how Paper.js objects are serialized when calling JSON.stringify() on them.
In version 0.2.2, calling JSON.stringify(new Point(5,5)) resulted in the string {"x":5,"y":5}. Once deserialized, this object is compatible with new Point() constructor.
In more recent versions of Paper.js, calling JSON.stringify(new Point(5,5)) result in the string ["Point",5,5]. Once deserialized, this object is not compatible with new Point() constructor, leading to a point with the string "Point" as x coordinate.
This is why you don't see the paths drawn in other browsers, because they have invalid coordinates.

In order to make this app work with recent versions of Paper.js, you need to manually map points to old serialized object version, before sending them. I forked the project here and included the needed changes in this commit.
Here is the method used to map points:

// Convert Point to simple object with x/y coordinates
// to allow backward compatibility with JSON serialization.
function formatPoint(point) {
    return {
        x: point.x,
        y: point.y
    };
}

I close this issue since there is nothing to fix in the library.

@sasensi sasensi closed this as completed Nov 13, 2018
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

3 participants