sacOO7 / socketcluster-client-swift

Native iOS/macOS client written in swift 4/swift 5
https://socketcluster.io/
Apache License 2.0
22 stars 39 forks source link

unsubscribe channel not working in socketcluster #24

Open niraj1991 opened 5 years ago

niraj1991 commented 5 years ago

Hi, @sacOO7

Unsubscribe channel not working on socketcluster.

I have to subscribe 20 channel. Now I want unsubscribe 10 channel. So We are use below code for subscribe.

//  For subscribe 
SoketManager.client.subscribeAck(channelName:"random") { (str, obj1, obj2) in
        print ("Got data for channel", str)
 }

//  Listening to channel                 
SoketManager.client.onChannel(channelName:"random", ack: {
         (channelName : String , data : AnyObject?) in
      print ("Got data for channel", channelName, " object data is ", data ?? "")
 })

We are use below code for unsubscribe.

//  For unsubscribe 
 SoketManager.client.unsubscribeAck(channelName:"random", ack : {
       (channelName : String, error : AnyObject?, data : AnyObject?) in
          if (error is NSNull) {
                        print("Successfully unsubscribed to channel ", channelName)
           } else {
                        print("Got error while unsubscribing ", error ?? "")
          }
 })

When I am call "unsubscribeAck" method always get error. Here is error.

{
    message = "Failed to unsubscribe socket from the [object Object] channel - Socket YFaGYE5Tbu1_8we2AAAG tried to unsubscribe from an invalid channel name";
    name = BrokerError;
}

Also I am trying with socketcluster demo as well but It not working for me. Github link: https://github.com/sacOO7/socketcluster-client-swift

Appreciate your help.

Thanks

jrvaja commented 5 years ago

@sacOO7 @niraj1991 Just reviewed it, it does work with web version but not with iOS.

I request to @sacOO7 to have a look into this and provide a guideline to make it work.

Thanks,

sacOO7 commented 5 years ago

Hi @niraj1991 @jrvaja , will look into it. Also it will be helpful if you can put your code here @jrvaja

jrvaja commented 5 years ago

@sacOO7

Thanks for writing to me.

We are using the same code as you mentioned in the demo for iOS. Github link: https://github.com/sacOO7/socketcluster-client-swift

//with acknowledgement
    client.unsubscribeAck(channelName: "yell", ack : {
        (channelName : String, error : AnyObject?, data : AnyObject?) in
        if (error is NSNull) {
            print("Successfully unsubscribed to channel ", channelName)
        } else {
            print("Got error while unsubscribing ", error)
        }
    })

The above method throws an error for invalid channel name, that's @niraj1991 has already mentioned in his post.

For Web Below is code that I am using for Web Application with VueJS which is working fine.

import socket from "./socketCluster";
Vue.prototype.$socket = socket;

subscribeChannel(channelName, watcher, clearWatcher = false) {
    const channel = this.$socket.subscribe(channelName);
    if (clearWatcher) channel.unwatch();

    channel.watch(data => {
        watcher(data);
    });
}
unsubscribeChannel(channelName) {
    this.$socket.unsubscribe(channelName);
}

JavaScript Package: "socketcluster-client": "^14.2.1"

Let me know if you need any other details, I would be happy to share you.

Regards,

KetaniPhone commented 5 years ago

Hello @sacOO7, @niraj1991 and @jrvaja

I have also faced the same issue. Please let me know if anyone will find the solution to that issue. I am also trying to above code which mentioned here by @niraj1991

Thanks,

gauravrami commented 5 years ago

Hello @sacOO7

I am also facing this issue, I am not able to unsubscribe the channel. Please, @sacOO7 please help me to fix this issue.

Hi, @niraj1991 & @KetaniPhone, if you got any solution then please can you post the answer for this issue.

Thanks in advance.

Regards, Gaurav

sachinsh76 commented 4 years ago

Hello, @niraj1991 @jrvaja @KetaniPhone @gauravrami I will look into it. We have updated SC server library, we are updating all clients in accordance with it.

AddoniOS commented 4 years ago

Hello @niraj1991 @jrvaja @KetaniPhone @gauravrami @sacOO7, i have faced same issue in iOS. if you got any solution then please can you post the answer for this issue.

Thanks everybody