Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private channel not receiving pusher events. #285

Open
PunchhGaurav opened this issue Feb 18, 2021 · 9 comments
Open

Private channel not receiving pusher events. #285

PunchhGaurav opened this issue Feb 18, 2021 · 9 comments

Comments

@PunchhGaurav
Copy link

PunchhGaurav commented Feb 18, 2021

// Channel Subscribed******
self.channel = [self.pusherClient subscribeToPrivateChannelNamed:channelName];

// Channel Event Listening******
[self.channel bindToEventNamed:@"new-message" handleWithBlock:^(PTPusherEvent *channelEvent) {
// channelEvent.data is a NSDictianary of the JSON object received
NSLog(@"message received: %@", channelEvent.data);
}];

@benw-pusher
Copy link

Does your client correctly subscribe to the private channel? Have you set up a functioning auth endpoint that authenticates subscriptions to the channel?
Do events published on public channels work okay?

@PunchhGaurav
Copy link
Author

yes. I am receiving with the public channel and also trigger the event from the client-side.

@PunchhGaurav
Copy link
Author

PunchhGaurav commented Feb 19, 2021

With this listen to the events.
PTPusherChannel *channel = [self.pusherClient subscribeToChannelNamed:channelName];
[channel bindToEventNamed:@"my-event" handleWithBlock:^(PTPusherEvent *channelEvent) {
// channelEvent.data is a NSDictianary of the JSON object received
NSLog(@"message received: %@", channelEvent.data);
}];

With this not listen to the events.
 PTPusherPrivateChannel *channel = [self.pusherClient subscribeToPrivateChannelNamed:channelName];

[channel bindToEventNamed:@"my-event" handleWithBlock:^(PTPusherEvent *channelEvent) {
// channelEvent.data is a NSDictianary of the JSON object received
NSLog(@"message received: %@", channelEvent.data);
}];

this is not working. 

@benw-pusher
Copy link

Just to confirm, are you replacing the public channel code with the private channel code? If not, you may need to change the var name:
PTPusherPrivateChannel *private = [self.pusherClient subscribeToPrivateChannelNamed:channelName];

Do you see the subscription attempt is successful in the debug console for your app in the Pusher Dashboard?
Have you setup a functioning auth endpoint that authenticates subscriptions to the private channel? See our docs for more information on this.

@PunchhGaurav
Copy link
Author

PunchhGaurav commented Feb 19, 2021

yes. I have received the subscription is completed.
with this channel, I am able to trigger the event but not listen to the event.
PTPusherPrivateChannel *private = [self.pusherClient subscribeToPrivateChannelNamed:channelName];

my function looks like this:

- (void)subscribeToChannel:(NSString *)channelName
{
//  ************Channel Subscribed******************
    PTPusherPrivateChannel *private = [self.pusherClient subscribeToPrivateChannelNamed:channelName];
    [private bindToEventNamed:@"my-event" handleWithBlock:^(PTPusherEvent *channelEvent) {
      // channelEvent.data is a NSDictianary of the JSON object received
         NSLog(@"message received: %@", channelEvent.data);
    }];
//  ************Client Event Triggering******************
    [self.channel triggerEventNamed:@"my-event" data:@{ @"test" : @"hello"}];
}
- (void)pusher:(PTPusher *)pusher didSubscribeToChannel:(PTPusherChannel *)channel
{
  NSLog(@"[pusher-%@] Subscribed to channel %@", pusher.connection.socketID, channel);
}

In this returning PTPusherChannel instance. Here is the required private channel instance.

- (void)pusher:(PTPusher *)pusher willAuthorizeChannel:(PTPusherChannel *)channel withAuthOperation:(PTPusherChannelAuthorizationOperation *)operation
{
  [operation.mutableURLRequest setValue:@"" forHTTPHeaderField:@"Authorization"];
}
using this I am doing successful authorization.

@PunchhGaurav

This comment has been minimized.

@PunchhGaurav

This comment has been minimized.

@PunchhGaurav

This comment has been minimized.

@benw-pusher
Copy link

I've edited your comments into one longer comment.

Just to confirm, you are correctly seeing the didSubscribeToChannel callback output that you have subscribed to the private channel?

What is the channel name you are using, and have you confirmed the name is the same in your client and server code?
When you trigger events do you see them in the Pusher Dashboard debug console?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants