diff --git a/documentation/extensions/index.html b/documentation/extensions/index.html new file mode 100644 index 000000000..b6a6805d6 --- /dev/null +++ b/documentation/extensions/index.html @@ -0,0 +1,15 @@ + + +
+ +The XMPP protocol includes a base protocol and many optional extensions. Smack provides the + org.jivesoftware.smack package for the core XMPP protocol, and the org.jivesoftware.smackx package for + many of the protocol extensions.
+ +This manual provides details about each of the "smackx" extensions, including what + it is, how to use it, and some simple example code. + + + \ No newline at end of file diff --git a/documentation/extensions/messageevents.html b/documentation/extensions/messageevents.html new file mode 100644 index 000000000..5b3851111 --- /dev/null +++ b/documentation/extensions/messageevents.html @@ -0,0 +1,224 @@ + + +
+ +For more information on each stage please follow these links:
+Use the static method MessageEventManager.addNotificationsRequests(Message message, boolean offline, boolean +delivered, boolean displayed, boolean composing) for requesting event notifications. +
+++// Connect to the server and log in + conn1 = new XMPPConnection(host); + conn1.login(server_user1, pass1); + + // Create a chat with user2 + Chat chat1 = conn1.createChat(user2); + + // Create a message to send + Message msg = chat1.createMessage(); + msg.setSubject("Any subject you want"); + msg.setBody("An interesting body comes here..."); + // Add to the message all the notifications requests (offline, delivered, displayed, + // composing) + MessageEventManager.addNotificationsRequests(msg, true, true, true, true); + + // Send the message that contains the notifications request + chat1.sendMessage(msg); ++
Note that DefaultMessageEventRequestListener is a default implementation of the +MessageEventRequestListener interface. +The class DefaultMessageEventRequestListener automatically sends a delivered notification to the sender of the message +if the sender has requested to be notified when the message is delivered. If you decide to create a new class that +implements the MessageEventRequestListener interface, please remember to send the delivered notification.
+++// Connect to the server and log in the users + conn1 = new XMPPConnection(host); + conn1.login(server_user1, pass1); + conn2 = new XMPPConnection(host); + conn2.login(server_user2, pass2); + + // User2 creates a MessageEventManager + MessageEventManager messageEventManager = new MessageEventManager(conn2); + // User2 adds the listener that will react to the event notifications requests + messageEventManager.addMessageEventRequestListener(new DefaultMessageEventRequestListener() { + public void deliveredNotificationRequested( + String from, + String packetID, + MessageEventManager messageEventManager) { + super.deliveredNotificationRequested(from, packetID, messageEventManager); + // DefaultMessageEventRequestListener automatically responds that the message was delivered when receives this request + System.out.println("Delivered Notification Requested (" + from + ", " + packetID + ")"); + } + + public void displayedNotificationRequested( + String from, + String packetID, + MessageEventManager messageEventManager) { + super.displayedNotificationRequested(from, packetID, messageEventManager); + // Send to the message's sender that the message was displayed + messageEventManager.sendDisplayedNotification(from, packetID); + } + + public void composingNotificationRequested( + String from, + String packetID, + MessageEventManager messageEventManager) { + super.composingNotificationRequested(from, packetID, messageEventManager); + // Send to the message's sender that the message's receiver is composing a reply + messageEventManager.sendComposingNotification(from, packetID); + } + + public void offlineNotificationRequested( + String from, + String packetID, + MessageEventManager messageEventManager) { + super.offlineNotificationRequested(from, packetID, messageEventManager); + // The XMPP server should take care of this request. Do nothing. + System.out.println("Offline Notification Requested (" + from + ", " + packetID + ")"); + } + }); + + // User1 creates a chat with user2 + Chat chat1 = conn1.createChat(user2); + + // User1 creates a message to send to user2 + Message msg = chat1.createMessage(); + msg.setSubject("Any subject you want"); + msg.setBody("An interesting body comes here..."); + // User1 adds to the message all the notifications requests (offline, delivered, displayed, + // composing) + MessageEventManager.addNotificationsRequests(msg, true, true, true, true); + + // User1 sends the message that contains the notifications request + chat1.sendMessage(msg); + Thread.sleep(500); + // User2 sends to the message's sender that the message's receiver cancelled composing a reply + messageEventManager.sendCancelledNotification(user1, msg.getPacketID()); ++
++ + + + \ No newline at end of file diff --git a/documentation/extensions/privatedata.html b/documentation/extensions/privatedata.html new file mode 100644 index 000000000..633f081cb --- /dev/null +++ b/documentation/extensions/privatedata.html @@ -0,0 +1,15 @@ + + + + +// Connect to the server and log in + conn1 = new XMPPConnection(host); + conn1.login(server_user1, pass1); + + // Create a MessageEventManager + MessageEventManager messageEventManager = new MessageEventManager(conn1); + // Add the listener that will react to the event notifications + messageEventManager.addMessageEventNotificationListener(new MessageEventNotificationListener() { + public void deliveredNotification(String from, String packetID) { + System.out.println("The message has been delivered (" + from + ", " + packetID + ")"); + } + + public void displayedNotification(String from, String packetID) { + System.out.println("The message has been displayed (" + from + ", " + packetID + ")"); + } + + public void composingNotification(String from, String packetID) { + System.out.println("The message's receiver is composing a reply (" + from + ", " + packetID + ")"); + } + + public void offlineNotification(String from, String packetID) { + System.out.println("The message's receiver is offline (" + from + ", " + packetID + ")"); + } + + public void cancelledNotification(String from, String packetID) { + System.out.println("The message's receiver cancelled composing a reply (" + from + ", " + packetID + ")"); + } + }); + + // Create a chat with user2 + Chat chat1 = conn1.createChat(user2); + + // Create a message to send + Message msg = chat1.createMessage(); + msg.setSubject("Any subject you want"); + msg.setBody("An interesting body comes here..."); + // Add to the message all the notifications requests (offline, delivered, displayed, + // composing) + MessageEventManager.addNotificationsRequests(msg, true, true, true, true); + + // Send the message that contains the notifications request + chat1.sendMessage(msg); ++
Follow these links to learn how to send and receive roster items:
+ +JEP related: JEP-93 +++// Connect to the server and log in + conn1 = new XMPPConnection(host); + conn1.login(server_user1, pass1); + + // Create a new roster exchange manager on conn1 + RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); + // Send user1's roster to user2 + rosterExchangeManager.send(conn1.getRoster(), user2); ++
++// Connect to the server and log in + conn1 = new XMPPConnection(host); + conn1.login(server_user1, pass1); + + // Create a new roster exchange manager on conn1 + RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); + // Send user1's RosterGroups to user2 + for (Iterator it = conn1.getRoster().getGroups(); it.hasNext(); ) + rosterExchangeManager.send((RosterGroup)it.next(), user2); ++
++// Connect to the server and log in + conn1 = new XMPPConnection(host); + conn1.login(server_user1, pass1); + + // Create a new roster exchange manager on conn1 + RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); + // Send a roster entry (any) to user2 + rosterExchangeManager1.send((RosterEntry)conn1.getRoster().getEntries().next(), user2); ++
++ + + \ No newline at end of file diff --git a/documentation/extensions/time.html b/documentation/extensions/time.html new file mode 100644 index 000000000..1cabc6fd8 --- /dev/null +++ b/documentation/extensions/time.html @@ -0,0 +1,15 @@ + + + + +// Connect to the server and log in the users + conn1 = new XMPPConnection(host); + conn1.login(server_user1, pass1); + conn2 = new XMPPConnection(host); + conn2.login(server_user2, pass2); + final Roster user2_roster = conn2.getRoster(); + + // Create a RosterExchangeManager that will help user2 to listen and accept + the entries received + RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(conn2); + // Create a RosterExchangeListener that will iterate over the received roster entries + RosterExchangeListener rosterExchangeListener = new RosterExchangeListener() { + public void entriesReceived(String from, Iterator rosterEntries) { + for (Iterator it = rosterEntries; it.hasNext();) { + try { + // Get the received entry + RosterEntry entry = (RosterEntry) it.next(); + // Display the entry on the console + System.out.println(entry); + // Add the entry to the user2's roster + user2_roster.createEntry(entry); + } + catch (XMPPException e) { + e.printStackTrace(); + } + } + } + }; + // Add the RosterExchangeListener to the RosterExchangeManager that user2 is using + rosterExchangeManager2.addRosterListener(rosterExchangeListener); + + // Create a RosterExchangeManager that will help user1 to send his roster + RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(conn1); + // Send user1's roster to user2 + rosterExchangeManager1.send(conn1.getRoster(), user2); ++