Topic doesn't have any active subscriptions


#1

I have problem with Websockets

Abstract:

I’m using Adonis WS for communication with Angular frontend and HttpController for being notified by another program.
I’m using only one topic, and need to communicate with particular users (there are no “rooms” and client shouldn’t know about each other)
So the thing is that I need notify particular client WHEN I get POST with notify.

My WSController’s constructor:

    Log.notice(`New WS Connection ${socket.id}`)
    this.socket = socket
    this.request = request
    this.auth = auth
    this.socket.emit('authorized')
  }
...some methods

async onNewpayment(txcount) {
    Log.notice(`User ${this.auth.user.uuid} made new payment request for ${txcount} BTC, getting new address`)
    const payment = await Blockchains.setNewPayment(this.socket.id, this.auth.user.uuid, txcount)
    this.socket.on('cancel', () => this.cancel())
    Blockchains.on('incoming', (payment) => {
      if (payment.userId === this.auth.user.uuid) {
        this.socket.emit('result', payment.resolved)
      }
    })
    this.socket.emit('payment', payment)
  }

Blockchains is Provider and EventEmitter

it receives notifies from other HttpController and emits ‘incoming’ event with payment

But this.socket.emit(‘result’, payment.resolved) produces error - ‘Topic doesn’t have any active subscribers’). Client didn’t disconnected and still pinging the backend…

Please help :wink:


#2

I have been getting this question for while, but I am waiting for someone to share a repo with me, with the required code to reproduce this issue.

I tried and it worked for me. So please share a repo with the required code to reproduce this issue


#3

I can’t just post whole idea of this program, but I’ll record private yt video where I’ll try reproduce the problem showing whole it’s path. I’m sorry it’s not Open Source and I don’t want to publish it yet


#4

Not asking u to publish the entire code, you just have to share the minimum required code to reproduce the issue.

It’s hard for me to watch videos and then write code and then find the issue


#5

OK I’ve resolved the problem

I forgot to disconnect the socket after transaction, so it worked only first time and created another connection for single client :slight_smile:

My first steps in websockets at all. Thanks for wishes for help, Sorry for bothering too :slight_smile:


#6

The principle of a wesocket connection is to be kept open and exchange message not to be closed after each message. In adonis implementation, you can’t send message if no client is connected to a topic. You should wrap your call in a try catch first. A small example of your controller would help to improve this response :wink: