Created
March 3, 2017 16:40
-
-
Save marceloinacio/b47f70a080bcd5ce46bdfce1844edef7 to your computer and use it in GitHub Desktop.
PAM PNAccessDeniedCategory unsubscribe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.pubnub.api; | |
import com.pubnub.api.callbacks.SubscribeCallback; | |
import com.pubnub.api.enums.PNOperationType; | |
import com.pubnub.api.enums.PNStatusCategory; | |
import com.pubnub.api.models.consumer.PNStatus; | |
import com.pubnub.api.models.consumer.pubsub.PNMessageResult; | |
import com.pubnub.api.models.consumer.pubsub.PNPresenceEventResult; | |
import java.util.Arrays; | |
/** | |
* Created by Max on 3/3/17. | |
*/ | |
public class wut { | |
public static void main(String[] args) { | |
PNConfiguration pnc = new PNConfiguration(); | |
pnc.setSubscribeKey("your sub key"); | |
pnc.setPublishKey("your pub key"); | |
PubNub pubnub = new PubNub(pnc); | |
pubnub.addListener(new SubscribeCallback() { | |
@Override | |
public void status(PubNub pubnub, PNStatus status) { | |
System.out.println("Status Code: " + status.getStatusCode()); | |
System.out.println(status); | |
if (status.getCategory()== PNStatusCategory.PNAccessDeniedCategory && (status.getOperation() == PNOperationType.PNHeartbeatOperation || status.getOperation() == PNOperationType.PNSubscribeOperation)) { | |
pubnub.unsubscribe() | |
.channels(status.getAffectedChannels()) | |
.execute(); | |
} | |
} | |
@Override | |
public void message(PubNub pubnub, PNMessageResult message) { | |
} | |
@Override | |
public void presence(PubNub pubnub, PNPresenceEventResult presence) { | |
} | |
}); | |
pubnub.subscribe().channels(Arrays.asList("ch1", "ch2", "ch3")).execute(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment