Unsubscribe from stream-room-messages

I’ve trying to unsubscribe from channels without success on the App that I’m working on.
Basically I call a subscription like this:

{
  "msg": "sub",
  "name": "stream-room-messages",
  "params": [
    "ktGEyfXtSdJMW2wLF",
    false
  ],
  "id": "ddp-reactnative-5"
}

And then I receive a reply like this:

{
  "msg": "ready",
  "subs": [
    "ddp-reactnative-5"
  ]
}

When the user moves to a different screen on the App, I call unsubscribe like this:

{
  "msg": "unsub",
  "id": "ddp-reactnative-5"
}

But all I receive is this:

{
  "msg": "nosub",
  "id": "ddp-reactnative-5"
}

What am I doing wrong? I tried the versions 0.65.2, 0.66.0 and 0.62.2 but none of them work. Am I missing something?

1 Like

I have the same issue! Please can someone help? 2 weeks trying solve it…

that response looks ok… Are you just not happy with the reply, or are you still receiving events from that stream after unsubscribing?

I expected to receive a “msg”: “unsub” instead of “nosub”
And yes, I keep getting the events after this.

I think this is because streams are not normal subscriptions.

unsubscribing with streams may actually not be possible.

This is the package behind: https://github.com/RocketChat/meteor-streamer

@aaron.ogle So is this linked to https://github.com/RocketChat/meteor-streamer/issues/3 ?

Looks like that’s exactly the same issue you are coming across

But according to that issue, seems that streams can be removed by calling “stop()”.
Does this mean that Rocket Chat could have something on the unsubscribe method to invoke “stop” when referring a stream @aaron.ogle? Or is it definitely not possible?

I would ask in that issue and ask how one would stop the subscription over websocket/DDP or if its not possible.

Thanks @aaron.ogle. I just asked that. Will wait for some input :slight_smile:

1 Like

@reyalpsirc I cant see any problem with your “code” if you send an unsub you will receive a nosub, the only problem that I cant find is if your continue receiving streams after the unsubscribe…but I couldnt reproduce

@guilherme.gazzo in the App I’m building for a client which uses Rocket.Chat, there’s multiple chat rooms but only one is tracked at a time. Based on that, whenever I move from chat A to chat B and then back to chat A, I can notice that when a new message is sent, I will receive the same message 2 times. And the more I repeat this flow, the more it happens. For now, I just made it ignore the events with the same data but still, knowing that I call unsub with a correct stream id, I was expecting the stream event to be removed on the server end while actually is not being removed and instead, it will keep calling it while the App is alive.

@guilherme.gazzo If I send an unsub, shouldn’t I also receive an unsub response if the event exists and a nosub if the event didn’t actually exist?

if you send an unsub you should receive a nosub, that part is right… I will check if the server is doing this job :slight_smile:

sorry, but I made some tests and I think its working I tested over messages and typing…

1 Like

@guilherme.gazzo I just retested this and found out that the problem is on my DDP implementation. It does in fact only receive one notification from the server but I was only removing the subscription without removing the callbacks I had for the collection itself. Thanks

1 Like

@reyalpsirc pay attention about this ddp lib, we made some fixes last day