Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Enable PubSub in the Browser #518
Update on this thread:
We currently have PubSub disabled on the browser as a way to prevent misunderstanding how the cancellation of the API works. Unfortunately, due to what is noted in -- #493 (comment) -- we simply can't cancel requests as go-ipfs expects in the browser. However, it seems to me that removing support for it entirely is not the optimal solution, as for a lot of use cases, only a few amount of PubSub channels will be open from a client, keeping the maintenance of those at bare minimum.
Proposal: enable PubSub and be explicit that cancels aren't actually being canceled, just silenced.
I've found and ultra-hacky workaround to cancel fetch requests without XHR here ( https://github.com/Morantron/poor-mans-cancelable-fetch ).
The whole idea is to make requests in a separate WebWorker, and sending a signal to the worker to terminate itself, which also aborts the request
Eventually fetch requests will be able to be aborted ( whatwg/fetch#447 ), but the final API hasn't been decided yet.
I know it's super hackish, but if it works
Hey, all, hate to ask a potentially obvious (and stupid) question.....but why not just use standard XHR which is cancellable? Believe me, I support the fetch standard and I love what it provides, but if we aren't using a service worker to intercept requests or anything like that, the main difference comes down to error handling.
XHR requests are cancellable and would solve the issue until the fetch standard includes true cancellable requests. The other alternative to this to cancel requests on the client side would be to run a service worker, and have the service worker respond to the request with a 400 Cancelled or something like that when a cancellation is requested. (Basically, you're manually sending a response to an initiated HTTP request to terminate it early.)
Seems Chrome has done some work on it (AbortController), last patch from February 5th this year https://bugs.chromium.org/p/chromium/issues/detail?id=750599
WebKit, no status yet: https://bugs.webkit.org/show_bug.cgi?id=174980
According to https://developer.mozilla.org/en-US/docs/Web/API/AbortController#Browser_compatibility most browsers now work with AbortController (except IE, shocker)
Hi, I'm new to the ipfs community and impressed by the all works done so far.
Here are my findings. Maybe I'm totally off the track, please let me know if anything is wrong.
Since js-ipfs-api uses
So, isn't this mean we can use same codebase as node to get this "cancellable fetch" working in the browser? I'd love to test my idea but I'm not sure how to do so yet, so just posting comment. Hope this helps.
--- UPDATED ---
Still not sure why the test on Chrome failed...
I've made a change to the /src/pubsub.js according to my findings above. But something is still wrong, and I was debugging that these few days. Unfortunately, I'm stuck now and need help...
I modified the pubsub.js as below. It's basically adding condition to detect whether the browser have the AbortController functionality.
Modified version seems to work properly inside browser, but failing the test in
To identify why the test is failing, I created the small app based on the example.
Looks like callback here is not called.
Furthermore, Inside the
Same function worked perfectly in node.js. Any comment and advice are welcome, thank you.