Socket
Socket
Sign inDemoInstall

ipfs-pubsub-1on1

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipfs-pubsub-1on1 - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

2

package.json
{
"name": "ipfs-pubsub-1on1",
"version": "0.0.7",
"version": "0.0.8",
"description": "1-to-1 communication channel over IPFS Pubsub between two peers",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -24,2 +24,4 @@ 'use strict'

this._closed = false
this._isClosed = () => this._closed
this._receiverID = receiverID

@@ -50,3 +52,3 @@

async connect () {
await waitForPeers(this._ipfs, [this._receiverID], this._id)
await waitForPeers(this._ipfs, [this._receiverID], this._id, this._isClosed)
}

@@ -59,2 +61,3 @@

async send (message) {
if (this._closed) return
let m = encode(message)

@@ -68,2 +71,3 @@ await this._ipfs.pubsub.publish(this._id, m)

close () {
this._closed = true
this.removeAllListeners('message')

@@ -94,2 +98,3 @@ this._ipfs.pubsub.unsubscribe(this._id, this._messageHandler)

async _openChannel () {
this._closed = false
await this._setup()

@@ -96,0 +101,0 @@ await this._ipfs.pubsub.subscribe(this._id, this._messageHandler)

'use strict'
const waitForPeers = async (ipfs, peersToWait, topic) => {
const waitForPeers = async (ipfs, peersToWait, topic, isClosed) => {
const checkPeers = async () => {

@@ -17,4 +17,6 @@ const peers = await ipfs.pubsub.peers(topic)

try {
if (await checkPeers()) {
if (isClosed()) {
clearInterval(interval)
} else if (await checkPeers()) {
clearInterval(interval)
resolve()

@@ -21,0 +23,0 @@ }

@@ -197,9 +197,17 @@ 'use strict'

return new Promise(async (resolve, reject) => {
assert.equal(c1._closed, false)
assert.equal(c1._isClosed(), false)
c1.close()
const topics1 = await ipfs1.pubsub.ls()
assert.deepEqual(topics1, [])
assert.equal(c1._closed, true)
assert.equal(c1._isClosed(), true)
assert.equal(c2._closed, false)
assert.equal(c2._isClosed(), false)
c2.close()
const topics2 = await ipfs2.pubsub.ls()
assert.deepEqual(topics1, [])
assert.equal(c2._closed, true)
assert.equal(c2._isClosed(), true)

@@ -257,3 +265,3 @@ setTimeout(async () => {

describe('non-participant peers can\'t send messages', function() {
it('doesn\'t receive unwated messages', async () => {
it('doesn\'t receive unwanted messages', async () => {
const c1 = await Channel.open(ipfs1, id2)

@@ -274,3 +282,3 @@ const c2 = await Channel.open(ipfs2, id1)

await ipfs3.pubsub.subscribe(c1.id, () => {})
await waitForPeers(ipfs1, [id3], c1.id)
await waitForPeers(ipfs1, [id3], c1.id, c1._isClosed.bind(c1))
await ipfs3.pubsub.publish(c1.id, Buffer.from('OMG!'))

@@ -277,0 +285,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc