-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support chrome.sockets.* APIs #664
Comments
Baby steps :) With some help I was able to confirm APIs are available in ipfs-companion background page after whitelisting extension. Notes below. How To Develop with Local (Unpacked) Extension (old
|
First checkpoint, let http = require('http')
let server = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('Hello from ipfs-companion exposing HTTP via chrome.sockets in Brave :-)\n')
})
server.listen(9091, '127.0.0.1') NextGetting js-ipfs working may take more than this, as |
Second checkpoint: I took js-ipfs
Next
|
@lidel great progress! How'd you get the Hapi route response to not throw an error? When I try to get a response from Aside from that, what are the next steps for handling the roadblocks you noted above? If we completely disable DHT - should the embedded js-ipfs Gateway run? |
@drbh I believe
As for remaining roadblocks:
|
Changes in
{
config: {
Addresses: {
Swarm: [],
API: '/ip4/127.0.0.1/tcp/5002',
Gateway: '/ip4/127.0.0.1/tcp/9090'
}
},
libp2p: {
config: {
dht: {
enabled: false
}
}
}
}
|
In the past API was exposed via HTTP Server only when jsipfs daemon was run from the commandline, so src/http/index.js was also responsible for orchestration that is not related to HTTP itself. This refactor moves code that is not related to HTTP Servers into standalone-daemon.js, which is easier to reason about, and unlocks use of HttpApi in contexts other than commandline jsipfs daemon, such as Firefox with libdweb or Chromium-based web browser with chrome.sockets APIs. Refs. ipfs/ipfs-companion#664 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
In the past API was exposed via HTTP Server only when jsipfs daemon was run from the commandline, so src/http/index.js was also responsible for orchestration that is not related to HTTP itself. This refactor moves code that is not related to HTTP Servers into standalone-daemon.js, which is easier to reason about, and unlocks use of HttpApi in contexts other than commandline jsipfs daemon, such as Firefox with libdweb or Chromium-based web browser with chrome.sockets APIs. Refs. ipfs/ipfs-companion#664 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
Changes in After some refactoring in ipfs/js-ipfs#1950, pinojs/pino#612 and some ah-hoc polyfills, I am stoked to present.. Embedded js-ipfs with self-hosted HTTP API and Gateway! 🎉
\o/ Known Issues
|
This changes browser.js to expose symbols and serializer methods used by hapi-pino. This is extremely niche use case, but some people want to run Hapi.js (HTTP server) in WebExtension context using chrome.sockets APIs. Ref. ipfs/ipfs-companion#664
Changes in Solved the problem with fetching raw file dataHapi's stream detection via I created a patch to detect browserified streams in Chrome App environment, which replaces tl;dr loading data from embedded gateway works: Fixed streaming of compressed payloadThere is a WIP js-ipfs patch to do proper streaming and content-type sniffing. It simplifies code responsible for streaming response and makes the streaming actually work by telling the payload compression stream to flush its content on every read(). IIUC previous version was buffering entire thing in Hapi's compressor memory, so the payload was returned when entire thing was fetched. Known Issues
Next
|
Changes in Companion UI is now aware of embedded GatewayEmbedded node is now the default if Implemented feature-detection for
|
In the past API was exposed via HTTP Server only when jsipfs daemon was run from the commandline, so src/http/index.js was also responsible for orchestration that is not related to HTTP itself. This refactor moves code that is not related to HTTP Servers into standalone-daemon.js, which is easier to reason about, and unlocks use of HttpApi in contexts other than commandline jsipfs daemon, such as Firefox with libdweb or Chromium-based web browser with chrome.sockets APIs. Refs. ipfs/ipfs-companion#664 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
* refactor: decouple HttpApi from cli/commands/daemon In the past API was exposed via HTTP Server only when jsipfs daemon was run from the commandline, so src/http/index.js was also responsible for orchestration that is not related to HTTP itself. This refactor moves code that is not related to HTTP Servers into standalone-daemon.js, which is easier to reason about, and unlocks use of HttpApi in contexts other than commandline jsipfs daemon, such as Firefox with libdweb or Chromium-based web browser with chrome.sockets APIs. Refs. ipfs/ipfs-companion#664 License: MIT Signed-off-by: Marcin Rataj <[email protected]> * fix: print HTTP listeners only when run as daemon This changes behavior in web browser. Instead of printing to console.log, it uses proper debug-based logger. Old behavior in terminal (when run via `jsipfs daemon`) does not change. License: MIT Signed-off-by: Marcin Rataj <[email protected]> * test: use StandaloneDaemon in test/http-api,gateway This replaces durect use of HttpApi with StandaloneDaemon, restoring all existing tests to operational state. License: MIT Signed-off-by: Marcin Rataj <[email protected]> * refactor: rename StandaloneDaemon to Daemon License: MIT Signed-off-by: Marcin Rataj <[email protected]>
Feature-detection for Remaining work around supercharging Embedded JS-IPFS in Brave 🦁 is tracked in #716 |
Detection via `stream instanceof Stream` does not work correctly in browser context, especially when different polyfils are used and mixed together. This change replaces instanceof check with feature-detection of stream-like objects. It enables Hapi to be used in Chrome Apps (browser environments with additional chrome.sockets APIs) Real life example: ipfs/ipfs-companion#664
Detection via `stream instanceof Stream` does not work correctly in browser context, especially when different polyfils are used and mixed together. This change replaces instanceof check with feature-detection of stream-like objects. It enables Hapi to be used in Chrome Apps (browser environments with additional chrome.sockets APIs) Real life example: ipfs/ipfs-companion#664
Detection via `stream instanceof Stream` does not work correctly in browser context, especially when different polyfils are used and mixed together. This change replaces instanceof check with feature-detection of stream-like objects. It enables Hapi to be used in Chrome Apps (browser environments with additional chrome.sockets APIs) Real life example: ipfs/ipfs-companion#664
About APIs
Chromium OS exposes
chrome.sockets.*
for its apps:We can access those APIs in Brave by adding ipfs-companion (beta+stable) as
blessed_extension
in brave-core/../_api_features.json (suggested by @bbondy)Potential use
(similar to @alanshaw's libdweb experiments on Firefox)
Relevant libraries
Created for and used in webtorrent:
MVP: Exposing HTTP Gateway
Quick notes about first steps:
chrome.sockets.*
APIs to temporary extensionschrome-net
andchrome-ngram
as replacements for Node APIs in browser contextschrome.sockets.*
The text was updated successfully, but these errors were encountered: