-
Notifications
You must be signed in to change notification settings - Fork 4
addInboundMessageListener on ChatRoom not working since upgrade from 0.7.4 #179
Copy link
Copy link
Open
Description
I've recently upgraded an internal project that used babbler 0.7.4 (Java 8) to 0.9.1 (Java 11) with maven.
It uses MUC with a conference room, and previously I was using ChatRoom.addInboundMessageListener.
It seems this listener is no longer firing in 0.9.1. If I change it to xmppSession.addInboundMessageListener, it works, and luckily it's only joined to a single room, so the global listener works fine with the rest of our code.
TcpConnectionConfiguration tcpConfiguration = TcpConnectionConfiguration.builder()
.hostname(NWWSHost)
.port(5223)
.channelEncryption(ChannelEncryption.OPTIONAL)
.connector(new SocketConnector(createTrustAllSslSocketFactory()))
.keepAliveInterval(Duration.ofSeconds(60))
.build();
XmppSessionConfiguration sessionConfiguration = XmppSessionConfiguration.builder()
// .debugger(ConsoleDebugger.class)
.reconnectionStrategy(ReconnectionStrategy.truncatedBinaryExponentialBackoffStrategy(10, 3))
.defaultResponseTimeout(Duration.ofMillis(5000))
.extensions(Extension.of(NWWSMessage.class))
.build();
XmppClient xmppSession = XmppClient.create(NWWSHost, sessionConfiguration, tcpConfiguration);
xmppSession.addConnectionListener(e -> {
if(e.getType() == ConnectionEvent.Type.RECONNECTION_SUCCEEDED) {
System.out.println("Connection status: CONNECTED (reconnect succeeded)");
} else if(e.getType() == ConnectionEvent.Type.DISCONNECTED) {
System.out.println("Connection status: DISCONNECTED");
}
});
// Connect
xmppSession.connect();
// Login
try {
xmppSession.login(NWWSUser, NWWSPass, "nwws");
} catch (AuthenticationException e) {
// Login failed, because the server returned a SASL failure, most likely due to wrong credentials.
e.printStackTrace();
} catch (XmppException e) {
// Other causes, e.g. no response, failure during resource binding, etc.
e.printStackTrace();
}
MultiUserChatManager multiUserChatManager = xmppSession.getManager(MultiUserChatManager.class);
ChatService chatService = multiUserChatManager.createChatService(Jid.of("conference." + xmppSession.getDomain()));
ChatRoom chatRoom = chatService.createRoom("nwws");
chatRoom.addOccupantListener(e -> {
System.out.println("test occupant");
});
chatRoom.addOccupantListener(e -> {
if (e.getType() == OccupantEvent.Type.ENTERED) {
System.out.println(e.getOccupant().getNick() + " has entered the room");
}
});
chatRoom.addInboundMessageListener(inMsg -> {
Message rawStanza = inMsg.getMessage();
// Handle message
//System.out.println(rawStanza.getBody());
NWWSMessage alertMsg = rawStanza.getExtension(NWWSMessage.class);
//...
});
note that the chatRoom.addOccupantListener is also not working with 0.9.1.
The fix at least for the inbound messages was to change the line to:
xmppSession.addInboundMessageListener(inMsg -> {
The full code is in a private repo, but I'm happy to share access to it if you want to see the full project.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels