-
Notifications
You must be signed in to change notification settings - Fork 299
Enable PubSub in the Browser #518
Comments
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 think we should enable PubSub on client and document cancelation issue. |
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 ™️ , it can serve as workaround until fetch requests are abortable. |
Great hack! I like it! |
Oh wow! @Morantron wanna submit a PR with that feature? Can you make sure to add a check to see if the browser has WebWorker support? |
@diasdavid Sure! I'm gonna see if I can turn the hack into some kind of FetchController polyfill, and then make the needed changes in js-ipfs-api. Looks like IE11 does not support fetch, so I guess PubSub won't work given that XHR does not play well with http streams. |
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.) |
@jedd-ahyoung xhr is not streamable, pubsub/subscribe is a stream. We need to use something like fetch or make this endpoint available Websockets. |
Yes, why not websockets? Or dataframes from WebRTC? |
This is not a decision at the level of this client library, it is rather at the http-api spec level. Moving to a complete RPC API where WebSockets is used as a transport has been proposed: https://github.com/ipfs/http-api-spec/issues/116 |
UpdateThe decision on this one is to either do: a) Enable PubSub and fake subscriptions - #518 (comment) Either is fine as a first iteration. |
It's important to notice that Edge 16 and Firefox 57 now can cancel fetch requests by using AbortController and AbortSignal. But Chrome still doesn't support this API... |
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. |
This sounds reasonable to me @shunkino - I'd ❤️ to see a proposal PR 😄 |
--- 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 Suspicious factors:
Same function worked perfectly in node.js. Any comment and advice are welcome, thank you. |
Is there a way to enable |
any updates here? |
This comment has been minimized.
This comment has been minimized.
@shunkino did you happen to make a PR with your progress? |
This PR enabled pubsub in the browser and paves the way for a switch to using `fetch` by default and allowing for cancelable requests via the use of `AbortController`. It's mostly the work done in ipfs-shipyard/js-ipfs-http-client-lite#1 but adapted a bit for use here. If approved, we can start work moving the other commands to use `fetch`. The work in https://github.com/ipfs-shipyard/js-ipfs-http-client-lite has proven the hard parts (uploading files) are all possible using the `fetch` API. Since `fetch` is promise based, when moving the other commands it makes sense to just switch to async/await as per ipfs/js-ipfs#1670 (and callbackify instead of promisify). Depends on: * [x] ipfs-inactive/interface-js-ipfs-core#505 resolves #518 refs ipfs/js-ipfs#2093 resolves #932 License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
PubSub will be unavailable as a browser API until https://github.com/ipfs/http-api-spec/issues/116 happens.
The text was updated successfully, but these errors were encountered: