Skip to content
Permalink
Browse files

fix(grpc): comlink callback error

  • Loading branch information...
korhaliv committed Apr 26, 2019
1 parent 29e090c commit 1577a0c2ebe9db3cc44faa718899399bf710c4b5
Showing with 22 additions and 7 deletions.
  1. +6 −6 renderer/reducers/lnd.js
  2. +16 −1 services/grpc/grpc.js
@@ -68,9 +68,9 @@ export const connectGrpcService = () => async dispatch => {

try {
// Hook up event listeners for stream subscriptions.
grpc.services.Lightning.on('subscribeInvoices.data', handleInvoiceSubscription)
grpc.services.Lightning.on('subscribeTransactions.data', handleTransactionSubscription)
grpc.services.Lightning.on('subscribeChannelGraph.data', handleChannelGraphSubscription)
grpc.on('subscribeInvoices.data', handleInvoiceSubscription)
grpc.on('subscribeTransactions.data', handleTransactionSubscription)
grpc.on('subscribeChannelGraph.data', handleChannelGraphSubscription)

// Hook up event listeners to notify when each gRPC service becomes available.
grpc.on('GRPC_WALLET_UNLOCKER_SERVICE_ACTIVE', handleWalletUnlockerActive)
@@ -83,9 +83,9 @@ export const connectGrpcService = () => async dispatch => {
dispatch({ type: CONNECT_GRPC_FAILURE, error })

// Disconnect event listeners.
grpc.services.Lightning.off('subscribeInvoices.data', handleInvoiceSubscription)
grpc.services.Lightning.off('subscribeTransactions.data', handleTransactionSubscription)
grpc.services.Lightning.off('subscribeChannelGraph.data', handleChannelGraphSubscription)
grpc.off('subscribeInvoices.data', handleInvoiceSubscription)
grpc.off('subscribeTransactions.data', handleTransactionSubscription)
grpc.off('subscribeChannelGraph.data', handleChannelGraphSubscription)
grpc.off('GRPC_WALLET_UNLOCKER_SERVICE_ACTIVE', handleWalletUnlockerActive)
grpc.off('GRPC_LIGHTNING_SERVICE_ACTIVE', handleLightningActive)

@@ -33,6 +33,7 @@ class Grpc extends EventEmitter {
onAfterActivateLightning: this.onAfterActivateLightning.bind(this),
onBeforeDisconnect: this.onBeforeDisconnect.bind(this),
onAfterDisconnect: this.onAfterDisconnect.bind(this),
onLeaveActive: this.onLeaveActive.bind(this),
},
})
this.supportedServices = [WalletUnlocker, Lightning]
@@ -141,12 +142,26 @@ class Grpc extends EventEmitter {
* Rejig connections as needed before activating the lightning service.
*/
async onBeforeActivateLightning() {
await this.services.Lightning.connect()
const { Lightning } = this.services
await Lightning.connect()
// creates listener that re-emits specified event
const forwardEvent = event => data => this.emit(event, data)
Lightning.on('subscribeInvoices.data', forwardEvent('subscribeInvoices.data'))
Lightning.on('subscribeTransactions.data', forwardEvent('subscribeTransactions.data'))
Lightning.on('subscribeChannelGraph.data', forwardEvent('subscribeChannelGraph.data'))
}

async onAfterActivateLightning() {
this.emit('GRPC_LIGHTNING_SERVICE_ACTIVE')
}

onLeaveActive() {
const { Lightning } = this.services
Lightning.removeAllListeners('subscribeInvoices.data')
Lightning.removeAllListeners('subscribeTransactions.data')
Lightning.removeAllListeners('subscribeChannelGraph.data')
}

// ------------------------------------
// Helpers
// ------------------------------------

0 comments on commit 1577a0c

Please sign in to comment.
You can’t perform that action at this time.