diff --git a/src/PubSub.js b/src/PubSub.js index d204054..f0e61a1 100644 --- a/src/PubSub.js +++ b/src/PubSub.js @@ -1,7 +1,6 @@ 'use strict'; const io = require('socket.io-client'); -const List = require('./list/OrbitList'); class Pubsub { constructor(ipfs) { @@ -16,22 +15,12 @@ class Pubsub { this._socket = io.connect(`http://${host}:${port}`, { 'forceNew': true }); this._socket.on('connect', resolve); this._socket.on('connect_error', (err) => reject(new Error(`Connection refused to ${host}:${port}`))); - - // TODO: cleanup - this._socket.on('disconnect', (socket) => { - // console.log(`Disconnected from http://${host}:${port}`) - }); - - this._socket.on('error', (e) => console.log('error:', e)); + this._socket.on('disconnect', (socket) => console.log(`Disconnected from http://${host}:${port}`)); + this._socket.on('error', (e) => console.log('Pubsub socket error:', e)); this._socket.on('message', this._handleMessage.bind(this)); this._socket.on('latest', (hash, message) => { console.log(">", hash, message); - if(this._subscriptions[hash]) { - this._subscriptions[hash].head = message; - - if(this._subscriptions[hash].onLatest) - this._subscriptions[hash].onLatest(hash, message); - } + this._handleMessage(hash, message); }); }); } @@ -41,9 +30,9 @@ class Pubsub { this._socket.disconnect(); } - subscribe(hash, password, callback, onLatest) { + subscribe(hash, password, callback) { if(!this._subscriptions[hash]) { - this._subscriptions[hash] = { head: null, callback: callback, onLatest: onLatest }; + this._subscriptions[hash] = { head: null, callback: callback }; this._socket.emit('subscribe', { channel: hash }); } }