tristandunn / pusher-fake

A fake Pusher server for development and testing.
https://rubygems.org/gems/pusher-fake
MIT License
173 stars 32 forks source link

Incorrect JSON encoding of data hash and socket_id #26

Closed jarthod closed 10 years ago

jarthod commented 10 years ago

Hi,

I'm using pusher-fake to test a web app using the Pusher.js library, the pusher ruby gem and the pusher-client ruby gem (to do websocket server side).

I encountered an issue with pusher-client gem while writing specs and I realized it was caused by pusher-fake not strictly respecting the pusher protocol.

When a connection is established, real Pusher sends this:

{
    "event":"pusher:connection_established",
    "data":"{\"socket_id\":\"33722.7304974\"}"
}

The data part is double-encoded, this is on purpose: http://pusher.com/docs/pusher_protocol#double-encoding And the socket_id is a string.

Whereas with pusher-fake (0.14.0), this is sent:

{
    "event":"pusher:connection_established",
    "data":{"socket_id":70025017489700,"activity_timeout":120}
}

The data is not double-encoded and the socket is a number. The Pusher.js library seems to handle this well, but the pusher-fake gem doesn't.


pusher-client could be improved to accept this, but as this is not exactly how Pusher works, I though it would be better to update pusher-fake to better represent the current Pusher implementation.

WDYT ?

Thanks for your great work !

tristandunn commented 10 years ago

Thanks for reporting this.

Changed the socket ID to a string in 283c84dbe77aa8f87816ef1fa69ca1e2286f0281.

I started the double encoding but it was locking up my tests. I'll investigate further over the weekend.

tristandunn commented 10 years ago

Added double encoding in 0e66227cfcb9306a37b5265a176ea4de4a42e26e.

jarthod commented 10 years ago

Thanks @tristandunn ! I'm gonna try this out tomorrow.

jarthod commented 10 years ago

Perfectly working, thanks ;)