vti / sockjs-perl

SockJS Perl Plack/PSGI implementation
Other
21 stars 4 forks source link

The example provided with this module failed #3

Closed akarelas closed 11 years ago

akarelas commented 11 years ago

In the top-level README.md of this module, you get "The Client-Side Part" and "The Server-Side Part". I tried those out with Twiggy, using both version 0.3.4 and version 0.2.1 of the client, and when I try to load my webpage I get the following error on FireBug (latest FF):

SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data
[Break On This Error]   
var info = JSON.parse(text); sockjs-0.2.1.js (line 1649)

So I look at the client code and insert a debugging line: console.log(text) right before JSON-parsing it, and see that text is not JSON at all! See for yourself below:

4f
{"origins":["*:*"],"entropy":3020163857,"websocket":true,"cookie_needed":false}
0

The "4f' and the "0" on the top & bottom are creating the problem.

Whose fault is it, vti? What can we do to fix it? I'm anxious to become a SockJS-Perl user!

Thanks

vti commented 11 years ago

Yes, this is a problem with Twiggy. See Issue #1

akarelas commented 11 years ago

I just installed your master version of Twiggy. Should that fix the problem? (I can't check just yet, have to install everything else, too)

vti commented 11 years ago

Yes, that should work. I use myself. I think... :)

akarelas commented 11 years ago

Why not mention in the README.md that your own Twiggy is required?

That way this here issue will be un-needed.

vti commented 11 years ago

On 03/06/2013 05:26 PM, Alexander Karelas wrote:

Why not mention in the README.md that your own Twiggy is required?

That way this here issue will be un-needed.

— Reply to this email directly or view it on GitHub https://github.com/vti/sockjs-perl/issues/3#issuecomment-14504861.

Yes. I am going to add that.

akarelas commented 11 years ago

Is "$stringifying" the session object the only way to get a unique id out of it?

vti commented 11 years ago

What do you need it for? 09.03.2013 7:23 ÐÏÌØÚÏ×ÁÔÅÌØ "Alexander Karelas" notifications@github.com ÎÁÐÉÓÁÌ:

Is "$stringifying" the session object the only way to get a unique id out of it?

Reply to this email directly or view it on GitHubhttps://github.com/vti/sockjs-perl/issues/3#issuecomment-14658354 .

akarelas commented 11 years ago

I will need to keep track of which clients are in each room (to emulate the rooms functionality from socket.io). Also which rooms each client is in. This requires at least two hashes with unique ids as keys.

akarelas commented 11 years ago

Also, is there a future-proof way to hook a new subroutine on the "user closed his connection" event?

I was thinking of replacing $socket->{"on_aborted"} with a subroutine that first executes what was there before, and then executes my own code. Does that seem right?

akarelas commented 11 years ago

For some reason, "on_aborted" is executed twice on browser-reload.

vti commented 11 years ago

Maybe providing a way for either subclassing and/or setting custom variables for the session object would be a good idea. This way you could save your own unique ids, and overwrite events.

As for "executed twice" this could a bug.

vti commented 11 years ago

Ok, now you can set/get custom values by using:

$session->set(foo => 'bar');
$session->get('foo');

And overwrite session creation by providing you own factory:

SockJS->new(session_factory => sub { MySessionClass->new })
akarelas commented 11 years ago

Both changes worked very well. Thank you.

rsarvas commented 11 years ago

Thanks, that helps. The demo still fails using FireFox 12 and 23 (makes initial contact, but aborts during the xhr post). IE 9 also appears to fail (xhr issues again?). On the plus side, the example code works fine now using web sockets in the latest version of Chrome.

I'm going to check the Perl module dependencies on my end again, then try to pull down the latest copy of the sockjs (JavaScript) library just to make sure this isn't a client or configuration issue.