Closed GoChartingAdmin closed 6 years ago
Hi, are you having problems with pako.js ? You should report it to creators of pako.js
While I could do that, but my intention is to use the faster and lighter version of pako to achieve the same result. I am using it in the browser, so lighter is better for me.
Let me know if your library can handle this. If no, I will open an issue with pako.
And it is not a pako example, but a code that I would like to run on the browser for my application. The nodejs version of this code uses pako today in our servers.
You can "unzip" (inflate) only a properly zipped (deflated) data. If pako.js fails to unzip your data, it is probably not properly deflated data, and neither UZIP.js would be able to inflate it.
I suggest that you make your project work with pako.js first, and then switch to UZIP.js to make things faster.
It works with Pako in nodejs. The code I have provided in the link works like a charm in nodejs. The websocket endpoint is the same and the data delivered is the same. Pako successfully inflates the same message in nodejs
I am simply having trouble inflating it in the browser using pako. Its gives an error message of Uncaught unknown compression method in the browser. But if you think its not worth a try with your library, I will revert to pako
Let me know if you tried my code at your end.
You wrote "But the inflation using pako fails on browser" . Is it true or not? If yes, you have to investigate it first with pako.js
I can not try your code, as I have no experience with node.js
Yes, the pako inflation fails on the browser.
Is your library meant for the browser?
If yes, I am assuming your library should also inflate a properly compressed message like the one I have shared in the browser.
I can share a browser version of the code if you think that will help you. I am assuming you are comfortable with js in the browser
UZIP.js is for any JS environment, but I tested it only in a browser.
pako.js is a very stable and trustworthy implementation (even though it is slow), and if it fails, I am 99.9% sure, that you have incorrect data (or use it in an incorrect way).
pako.js can be replaced by UZIP.js just by replacing each function call "pako.XYZ" by "UZIP.XYZ".
@GoChartingAdmin I tested your code. Are you sure it's not a CORS issue?
@wmhilton I am getting the feed from the websocket on the browser for sure. It is a Blob. Are you having CORS issue at your end
Yes I am. I think maybe it's because I'm in the US?
I will share my code by EOD. See if it helps.
The code in this fiddle connects me to huobi websocket exchange. Now you need to send a message like below:
{"sub":"market.btcusd.depth.step0","id":"btcusd"}
PS: Fiddle does not send any message but you could code that at your end
You can also enter the endpoint below and test it
https://www.websocket.org/echo.html
Endpoint: wss://api.huobi.pro/ws
You should receive two blobs...one of them is a "ping" and you must respond with a "pong" to keep the connection alive. The response is a Blob that we need to inflate using either pako or UZIP and then use in our application to either keep the connection alive (pong) or subscribe to a data feed
And, I am using a US server
Try using this:
socket = new WebSocket(websocketurl);
socket.binaryType = "arraybuffer";
I'm pretty sure both pako and uzip operate on ArrayBuffers. Node doesn't have Blobs so that might be why its websocket implementation defaults to Buffers and thus you don't have to set binaryType
in node 🤷♂️ .
I believe your lib is the faster version of pako. Awesome!!!!
I am having an issue deflating a message sent through a websocket in browser. The below code works like a charm in nodejs. But the inflation using pako fails on browser. Can your library receive inflate the messages received from the below websocket endpoint in the browser. Is yes, can you share a sample code how I would use your library to achieve the same. Thank you for your help
Pako Example Code