I'm extedning the example browser-video-streaming. I'm storing some videos in my local ipfs, and it's corresponding metadata in dag. I'm wondering why is the video file streaming so slow on my browser local? Isn't it connected to my local node directly?
When I force the browser node to connect to my local node like:
function createNode(): Promise<any> {
const node = new IPFS();
return new Promise((resolve, reject) => {
node.on('ready', () => {
node.swarm.connect("/ip4/127.0.0.1/tcp/4001/ipfs/QmaeUxeAK3N5fyU5o5W8eFeHGy7SUgcxfscewNNGgFak8L");
resolve(node)
}
)
});
}
it throws
dial.js:365 Uncaught (in promise) Error: Circuit not enabled and all transports failed to dial peer QmaeUxeAK3N5fyU5o5W8eFeHGy7SUgcxfscewNNGgFak8L!
When I do:
const peers: Peer [] = await node.swarm.peers();
peers.forEach(peer => console.log(multiaddr(peer.addr).toString()));
it only shows:
/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd
/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3
/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm
I guess it is not aware of my local node at all, so it tries to resolve files over internet. Is there any way to share my local repo or just connect to my local node ?
Hi @stasbar, there are a couple of things happening here, I'll try answering them by parts.
The first one is that browsers do not support TCP and therefore, when you do the swarm.connect call, your node is figuring that the peer you want to connect is using a Transport that it doesn't has and so it is trying to use Circuit Relay to reach out to it, however, given that you don't have Circuit Relay Enabled, it is failing. Learn more about Circuit Relay here https://github.com/ipfs/js-ipfs/tree/master/examples/circuit-relaying#tutorial---understanding-circuit-relay
On the slowness, v0.34.0 #1721 will bring some drastic performance improvements and you will see things getting better. However, in your case because you don't have a direct connection, the file is actually being streamed by preload nodes that exist on the IPFS Infrastructure, so that extra hop adds a bit of delay.
Thank you for your answer @daviddias , you showed me where the problem is. But is there any solution? I would like to watch the video in my browser, even when offline. Is it possible at the moment?
@stasbar it is indeed. You just need to enable a WebSockets listener in your local Desktop node. The tutorial -- https://github.com/ipfs/js-ipfs/tree/master/examples/exchange-files-in-browser -- shows how to do it :)
Thank you, it worked 鉂わ笍
Awesome! Glad to help :)
Most helpful comment
@stasbar it is indeed. You just need to enable a WebSockets listener in your local Desktop node. The tutorial -- https://github.com/ipfs/js-ipfs/tree/master/examples/exchange-files-in-browser -- shows how to do it :)