Open marcoippolito opened 4 years ago
You have to remember you're looking at a really old POC, so you have to get the versions right. The HTML references 0.34.4, so that is https://github.com/ipfs/js-ipfs/blob/v0.34.4/src/core/index.js#L62
Hi @cretz ! The "closest" function I detected in the equivalent /core/index.js of the latest js-ipfs version is this function: https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs/src/core/index.js#L37
But using the 'create' function as follows in browser.js:
import ipfs from 'ipfs';
export function newIPFS(cb) {
ipfs.create({
repo: String(Math.random() + Date.now()),
EXPERIMENTAL: { pubsub: true },
config: {
Addresses: {
Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star']
}
}
})
// Wait for peers
ipfs.on('ready', () => {
const tryListPeers = () => {
ipfs.swarm.peers((err, peers) => {
if (err) throw err
debug('Peers', peers)
if (!peers || peers.length == 0) setTimeout(() => tryListPeers(), 1000)
else cb(ipfs)
})
}
tryListPeers()
})
}
Leads to this error, when calling newIPFS function within Offer.vue :
import * as browserjs from "@/services/js-ipfs-signaling/browser.js";
export default {
name: 'Offer',
data () {
return {
ipfs: null,
pc: null
}
},
created() {
// Make a random URL hash if not given
browserjs.createWindowHashIfNotPresent();
// Create IPFS and do everything else once ready
browserjs.newIPFS(ipfs => {
this.ipfs = ipfs;
// Create new RTC conn
this.pc = new RTCPeerConnection({
// Could have a TURN server too, not worth it for the demo
iceServers: [{ urls: 'stun:stun.l.google.com:19302'}]
})
console.log("this.pc : ", this.pc);
})
Pointing to this line in Offer.vue :
And to this line in browser.js :
I haven't found the equivalent of ipfs.on in core-api: https://github.com/ipfs/js-ipfs/tree/master/docs/core-api .
What is the purpose of function newIPFS https://github.com/cretz/webrtc-ipfs-signaling/blob/master/browser.js#L14 ? I'm trying to understand how to "convert" it to the latest version of js-ipfs
I'm not sure you should try to convert my code exactly here...rather, you should instead understand what is needed if you were to write it from scratch yourself (posting offers and answers to the same readable space). Re-reading the code again (this is proof-of-concept toy code from over a year ago), the purpose of that call is to return a promise w/ the IPFS object.
May be I'm oversimplifying, but based on what is stated here: https://www.html5rocks.com/en/tutorials/webrtc/infrastructure/ what constitutes a signaling service is a messaging service to exchange session metadata and application data. So why not using the libp2p for this purpose? https://github.com/libp2p/js-libp2p/tree/master/examples/echo Perhaps PubSub service can be deployed as well to send and receive messages based on their topic.
So why not using the libp2p for this purpose?
You have linked to a server-side nodejs example, this POC is all in-browser
Sorry for the mistake. Tomorrow morning I'm going to dive into libp2p and PubSub in order to try to use them together as messaging service to exchange session metadata and application data between peers.
I'm trying to use your excellent work as starting base for webrtc-signaling, but, in order to understand and correctly use the function newIPFS, I need to understand where Ipfs: https://github.com/cretz/webrtc-ipfs-signaling/blob/master/browser.js#L15 comes from. I didn't find it in the current core API: https://github.com/ipfs/js-ipfs/tree/master/docs/core-api