Private channel not receiving pusher events.
PunchhGaurav opened this issue · 9 comments
// 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);
}];
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?
yes. I am receiving with the public channel and also trigger the event from the client-side.
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.
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.
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.
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.
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?