I'm experimenting with the Ratchet php library. In particular, I've been trying to integrate their push integration demo into a React application.
Their demo references a seemingly one-off version of the autobahn JS library, which works against my server implementation (a near duplicate of their demo).
However, when I try to use autobahn JS from npm everything melts down. It seems this implementes a newer version of the Web Sockets protocol?
The one-off version of autobahn passes wamp
for the Sec-WebSocket-Protocol
header, which Ratchet seems to support. The npm version of autobahn passes wamp.2.json, wamp.2.msgpack
...
Digging through the Ratchet code I found this
If any component in a stack supports a WebSocket sub-protocol return each supported in an array
So I implemented Ratchet\WebSocket\WsServerInterface
as such on my component
public function getSubProtocols()
{
return ['wamp.2.json', 'wamp.2.msgpack'];
}
Now the connection attempt gets a little further along, but still blows up
failing transport due to protocol violation: unexpected message type 0
Then the client fails to close the connection
Uncaught DOMException: Failed to execute 'close' on 'WebSocket': The code must be either 1000, or between 3000 and 4999. 1002 is neither.
What's going on here; does Ratchet support an older version of the Web Socket protocol, or is there a way to get these two libraries talking successfully?