Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

How to send pubsub message from Browser node to terminal node? #4208

Closed
satoshi999 opened this issue Sep 15, 2022 · 3 comments
Closed

How to send pubsub message from Browser node to terminal node? #4208

satoshi999 opened this issue Sep 15, 2022 · 3 comments
Assignees
Labels
good first issue Good issue for new contributors kind/unknown-in-helia need/analysis Needs further analysis before proceeding

Comments

@satoshi999
Copy link

I tried to sending pubsub message from Browser node to terminal node via websockets with following code.
It seems that has succeeded connection via websockets because opponent node id is in peer list
But, it can not receive pubsub message.

Is it possible that sending pubsub message between browser and terminal node?

On browser side.

  • "ipfs-core": "0.15.4",
  • "@libp2p/websockets": "3.0.2",
  • Node.js : 14.18.0
import {WebSockets} from '@libp2p/websockets'
import { all } from '@libp2p/websockets/filters'
import {create} from 'ipfs-core'

window.addEventListener('load', async() => {
  const ipfs = await create({
    repo:'IPFS-' + Math.random(),
    libp2p: {
      transports: [new WebSockets({filter:all})],
      config: {
        pubsub: {
          emitSelf:false
        }
      }
    }
  })
  
  await ipfs.swarm.connect('/ip4/127.0.0.1/tcp/4003/ws/p2p/QmVpoLX9Us7AF39vWsFFHSz274ShJfHaVY5VWoVsuAzpdb')

  await ipfs.pubsub.subscribe('message', (msg)=> {
    const data = new TextDecoder().decode(msg.data)
    console.log(data)
  })

  const id = await (await ipfs.id()).id

  setInterval(async() => {
    await ipfs.pubsub.publish('message', new TextEncoder().encode(`Hello from ${id}`))

    const peers = await ipfs.swarm.peers()
    for(const peer of peers) {
      console.log(peer.peer.toString())
    }
  }, 1000)
})

On terminal side

  • "ipfs": "0.54.0"
  • Node.js 14.18.0
const { create } = require('ipfs');

(async() => {
  const ipfs = await create({
    repo: 'IPFS',
    EXPERIMENTAL: {
      pubsub: true
    },
    libp2p: {
      config: {
        pubsub: {
          emitSelf:false
        }
      }
    }
  })
  const id = await (await ipfs.id()).id

  await ipfs.pubsub.subscribe('message', async(msg)=> {
    const data = new TextDecoder().decode(msg.data)
    console.log(data)
  })

  setInterval(async() => {
    await ipfs.pubsub.publish('message', new TextEncoder().encode(`Hello from ${id}`))

    const peers = await ipfs.swarm.peers()
    for(const peer of peers) {
      console.log(peer.peer.toString())
    }
  }, 1000)
})()
@satoshi999 satoshi999 added the need/triage Needs initial labeling and prioritization label Sep 15, 2022
@threshold862543
Copy link

I'm having a similar issue ipfs/js-kubo-rpc-client#70

@satoshi999
Copy link
Author

satoshi999 commented Sep 16, 2022

@threshold862543
It issue seems that my case is different from this issue

This issue as linked describes the behavior when accessing by http from a browser using ipfs-http-client to a local node.
The pubsub keyword is used, but it seems irrelevant since it is ipfs-http-client

I understand that in my case it is an issue related to the pubsub communication between IPFS node in the browser and the daemon node, In other words, it seems to be a websockets communication issue between the browser node and the daemon node

@achingbrain achingbrain added good first issue Good issue for new contributors need/analysis Needs further analysis before proceeding and removed need/triage Needs initial labeling and prioritization labels Oct 14, 2022
@tinytb tinytb moved this to Good First Issue in IP JS (PL EngRes) v2 Nov 3, 2022
@SgtPooki
Copy link
Member

SgtPooki commented May 16, 2023

Hello @satoshi999,

js-ipfs is being deprecated in favor of Helia. You can learn more about this deprecation and the corresponding migration guide here.

As a result, we are going to close this issue. If you think we have done this in error, please feel to reopen with any comments in the next week as we will circle back on the reopened issues.

We hope you will consider Helia for your IPFS in JS needs. If you believe this particular request belongs in Helia, feel free to open a Helia issue. We look forward to engaging with you more there.

Thanks,
@ipfs/helia-dev

@SgtPooki SgtPooki closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2023
@github-project-automation github-project-automation bot moved this from Good First Issue to Done in IP JS (PL EngRes) v2 May 16, 2023
@SgtPooki SgtPooki self-assigned this May 17, 2023
@SgtPooki SgtPooki moved this to ✅ Done in js-ipfs deprecation May 17, 2023
@SgtPooki SgtPooki moved this from ✅ Done to 🏃‍♀️ In Progress in js-ipfs deprecation May 17, 2023
@SgtPooki SgtPooki moved this from 🏃‍♀️ In Progress to ✅ Done in js-ipfs deprecation May 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good issue for new contributors kind/unknown-in-helia need/analysis Needs further analysis before proceeding
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants