orbit-db-pubsub
Advanced tools
Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "orbit-db-pubsub", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Message propagation module for orbit-db", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,17 +20,4 @@ 'use strict' | ||
if (this._ipfs.pubsub) { | ||
this._ipfs.pubsub.subscribe(hash, { discover: true }, (err, stream) => { | ||
if (err) | ||
logger.error(err) | ||
logger.debug(`Subscribed to '${hash}'`) | ||
if (stream && this._subscriptions[hash]) { | ||
this._subscriptions[hash].stream = stream | ||
stream.on('data', this._handleMessage.bind(this)) | ||
// TODO: handle end of stream | ||
// stream.on('end', () => console.log("Disconnected from pubsub")) | ||
} | ||
}) | ||
} | ||
if (this._ipfs.pubsub) | ||
this._ipfs.pubsub.subscribe(hash, { discover: true }, this._handleMessage.bind(this)) | ||
} | ||
@@ -41,5 +28,3 @@ } | ||
if(this._subscriptions[hash]) { | ||
if (this._subscriptions[hash].stream) | ||
this._subscriptions[hash].stream.cancel() | ||
this._ipfs.pubsub.unsubscribe(hash, this._handleMessage) | ||
delete this._subscriptions[hash] | ||
@@ -52,3 +37,3 @@ logger.debug(`Unsubscribed from '${hash}'`) | ||
if(this._subscriptions[hash] && this._ipfs.pubsub) | ||
this._ipfs.pubsub.publish(hash, message) | ||
this._ipfs.pubsub.publish(hash, new Buffer(message)) | ||
} | ||
@@ -62,9 +47,8 @@ | ||
_handleMessage(message) { | ||
const hash = message.topicIDs[0] | ||
const hash = message.topicCIDs[0] | ||
const data = message.data.toString() | ||
const subscription = this._subscriptions[hash] | ||
if(subscription && subscription.onMessage && data) { | ||
if(subscription && subscription.onMessage && data) | ||
subscription.onMessage(hash, data) | ||
} | ||
} | ||
@@ -71,0 +55,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2631
43