It shows how it could look like when two XMPP contacts are chatting with each other and having real-time text enabled. Enjoy!
Roughly speaking you have to create a new outbound real-time message and just update its text while typing:
// Create a chat session with another user. Chat chat = xmppClient.getManager(ChatManager.class).createChatSession(contact); RealTimeTextManager realTimeTextManager = xmppClient.getManager(RealTimeTextManager.class); // Create an new RTT message. OutboundRealTimeMessage realTimeMessage = realTimeTextManager.createRealTimeMessage(chat); TextArea textArea = new TextArea(); textArea.textProperty().addListener((observable, oldValue, newValue) -> { realTimeMessage.update(newValue); });
When done typing, commit the message (which will send the current message as normal chat message):
realTimeMessage.commit();
On the receiver side, you can listen for it like this (and e.g. display it to a Label).
Label label = new Label(); // Upon receiving a RTT message, display it. realTimeTextManager.addRealTimeMessageListener(e -> { InboundRealTimeMessage rtt = e.getRealTimeMessage(); rtt.addRealTimeTextChangeListener(e1 -> Platform.runLater(() -> label.setText(e1.getText()))); });