Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
EnvironmentChanges
We already know the ASAPMessageReceivedListener.
There are other listeners:
The ASAPEnvironmentChangesListener interface has got a single method.
voidonlinePeersChanged(Set<CharSequence> peerList);Applications interested in those changes have to implement and register a listener.
DiscoverPeerAndStartEGChat implements this usage in an example.
privateclassYourApplicationimplementsASAPEnvironmentChangesListener/*, .. */ {
privateSet<CharSequence> knowPeers = newHashSet<>();
@OverridepublicvoidonlinePeersChanged(Set<CharSequence> peerList) {
// peer list has changed - maybe there is a new peer aroundfor(CharSequencemaybeNewPeerName : peerList) {
CharSequencenewPeerName = maybeNewPeerName;
for (CharSequencepeerName : this.knowPeers) {
if(maybeNewPeerName.toString().equalsIgnoreCase(peerName.toString())) {
newPeerName = null; // not newbreak; // found in my known peers list, try next in peerList
}
}
if(newPeerName != null) {
// found one - enough for this examplethis.doSomethingWith(newPeerName); // examplebreak;
}
}
} // method
} // classThis class keeps a list of peers as member (knowPeers ). The listener method is called whenever a change of connections occurs. The algorithm looks for a peer that is not known yet. A method is performed for the first not yet known peer (doSomething()). A message is sent in this example.
Let the complete example run.
A listener is registered with a ASAPPeer.
privateclassYourApplicationimplementsASAPEnvironmentChangesListener/*, .. */ {
...
ASAPPeerpeer = ..;
// object itself implements this listener interface.peer.addASAPEnvironmentChangesListener(this);The object implements the interface itself in this case.
Your application can subscribe with an object that implements ASAPChannelContentChangedListener.
Your listener is informed about newly arrived message by a call of this method:
voidasapChannelContentChanged(CharSequenceformat, CharSequenceuri, intera) What is the difference to ASAPMessageReceivedListener? There are no message is either parameter but very specific description where to find new messages in the ASAPStorage. This listener comes in handy for application how make use of ASAPStorage. A messenger like application has no need for its own persistent storage. It can directly use ASAPChannels. It just needs to be informed about a change in a channel to update a user interface. In most cases, format and uri are fully sufficient information.