本文整理汇总了Java中org.jivesoftware.smackx.muc.MultiUserChat.addMessageListener方法的典型用法代码示例。如果您正苦于以下问题:Java MultiUserChat.addMessageListener方法的具体用法?Java MultiUserChat.addMessageListener怎么用?Java MultiUserChat.addMessageListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smackx.muc.MultiUserChat
的用法示例。
在下文中一共展示了MultiUserChat.addMessageListener方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
public void init() throws XMPPException {
new TrackRooms().addTo(conn);
new TrackStatus(getMonitorRoomJID().toLowerCase()).addTo(conn);
new ListenForChat().addTo(conn);
monitorRoom = new MultiUserChat(conn, getMonitorRoomJID());
monitorRoom.addMessageListener(this);
monitorRoom.addParticipantStatusListener(this);
monitorRoom.join(StringUtils.parseName(conn.getUser()));
try {
// This is necessary to create the room if it doesn't already exist
monitorRoom.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
}
catch (XMPPException ex) {
// 403 code means the room already exists and user is not an owner
if (ex.getXMPPError().getCode() != 403) {
throw ex;
}
}
sendStatus(me);
}
示例2: joinMultiUserChat
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
/**
* 加入聊天室
* @param xmppConnection
* @param roomName
* @param password
* @return
*/
public static MultiUserChat joinMultiUserChat(XMPPConnection xmppConnection,String roomName,String password,PacketListener packetListener){
try {
// 使用XMPPConnection创建一个MultiUserChat窗口
MultiUserChat muc = new MultiUserChat(xmppConnection, roomName+ "@conference." + xmppConnection.getServiceName());
// 聊天室服务将会决定要接受的历史记录数量
DiscussionHistory history = new DiscussionHistory();
history.setMaxChars(0);
// 用户加入聊天室
muc.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout());
if(packetListener!=null){
muc.addMessageListener(packetListener);
}
return muc;
} catch (XMPPException e) {
e.printStackTrace();
return null;
}
}
示例3: joinMultiUserChat
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
/**
* 加入聊天室
* @param xmppConnection
* @param roomName
* @param password
* @param packetListener 消息监听器
* @return
*/
public static MultiUserChat joinMultiUserChat(XMPPConnection xmppConnection,String roomName,String password,PacketListener packetListener){
try {
// 使用XMPPConnection创建一个MultiUserChat窗口
MultiUserChat muc = new MultiUserChat(xmppConnection, roomName+ "@conference." + xmppConnection.getServiceName());
// 聊天室服务将会决定要接受的历史记录数量
DiscussionHistory history = new DiscussionHistory();
history.setMaxChars(0);
// history.setSince(new Date());
// 用户加入聊天室
muc.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout());
Log.i("MultiUserChat", "会议室【"+roomName+"】加入成功........");
if(packetListener!=null){
muc.addMessageListener(packetListener);
}
return muc;
} catch (XMPPException e) {
Log.e("MultiUserChat", "会议室【"+roomName+"】加入失败........");
e.printStackTrace();
return null;
}
}
示例4: sendMessage
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
public void sendMessage(String body, String chatJid, long timestamp) throws SmackException {
Random random = new Random(timestamp + body.length() + chatJid.length());
Log.d(TAG, "Sending message to : " + chatJid);
MultiUserChat chat = MultiUserChatManager.getInstanceFor(groupChatConnection)
.getMultiUserChat(chatJid);
chat.addMessageListener(this);
Message message = new Message();
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("date_sent", timestamp + "");
message.setStanzaId(StanzaIdUtil.newStanzaId());
message.setBody(body);
message.addExtension(extension);
message.setType(Message.Type.chat);
chat.sendMessage(message);
}
示例5: joinPublicChat
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
public void joinPublicChat(String chatJid, long lastMessageDate) {
try {
MultiUserChat mucChat;
if ((mucChat = publicChats.get(chatJid)) == null) {
mucChat = MultiUserChatManager.getInstanceFor(privateChatConnection).getMultiUserChat(chatJid);
mucChat.addMessageListener(this);
publicChats.put(chatJid, mucChat);
}
DiscussionHistory history = new DiscussionHistory();
if(lastMessageDate != 0)
history.setSince(new Date(lastMessageDate * 1000));
else
history.setMaxChars(0);
mucChat.join(
CurrentUser.getInstance().getCurrentUserId().toString(),
null,
history,
privateChatConnection.getPacketReplyTimeout());
} catch (Exception ex) {
Logger.logExceptionToFabric(ex);
}
}
示例6: join
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
public MultiUserChat join(JabberClient client, JabberPlayer me) throws XMPPException {
MultiUserChat chat = new MultiUserChat(client.getConnection(), getJID());
chat.join(StringUtils.parseName(me.getJid()));
if (!chat.isJoined()) {
return null;
}
try {
// This is necessary to create the room if it doesn't already exist
// Configure the options we needs explicitly, don't depend on the server supplied defaults
final Form configForm = chat.getConfigurationForm().createAnswerForm();
configForm.setAnswer(JABBER_MEMBERSONLY, isStartLocked());
configForm.setAnswer(JABBER_ALLOW_INVITES, false);
configForm.setAnswer(JABBER_CHANGE_SUBJECT, false);
configForm.setAnswer(JABBER_MODERATED, false);
configForm.setAnswer(JABBER_PASSWORD_PROTECTED, false);
configForm.setAnswer(JABBER_PERSISTENT, false);
configForm.setAnswer(JABBER_PUBLIC_ROOM, true);
chat.sendConfigurationForm(configForm);
ownedByMe = true;
owners.clear();
addOwner(jid);
}
catch (XMPPException e) {
// 403 code means the room already exists and user is not an owner
if (e.getXMPPError() != null && e.getXMPPError().getCode() != 403) {
throw e;
}
}
chat.addMessageListener(client);
return chat;
}
示例7: start
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
public void start(ITetradCallback callback) {
logger.debug("start");
logger.info(MessageFormat.format("Connecting to service {0} with username {1} and resource {2}",
service_domain,
username,
resource
));
this.callback = callback;
try {
XMPPConnection xmppConnection = new XMPPConnection(service_domain);
xmppConnection.connect();
xmppConnection.login(username, password, resource);
DiscussionHistory history = new DiscussionHistory();
history.setMaxStanzas(0);
for (String room : rooms) {
final String roomJID = room + "@" + getChatService();
logger.info(MessageFormat.format("Connecting to room {0}", roomJID));
MultiUserChat chat = new MultiUserChat(xmppConnection, roomJID);
chat.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout());
chat.addMessageListener(packet -> this.handleMessage((Message) packet, roomJID));
chat.changeNickname("β");
connectedRooms.put(room, chat);
}
} catch (XMPPException e) {
logger.error(MessageFormat.format("Error connecting to service {0} with username {1} and resource {2}. Message: {3}",
service_domain,
username,
resource,
e.getMessage()
));
}
}
示例8: enterRoom
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
private void enterRoom(String roomName) {
/*
* Enters a MUC and listens for messages to handle
* @param roomName The name of the MuC
*/
MultiUserChat muc = new MultiUserChat(conn,roomName+"@conference"+serverName);
try {
muc.join(username + "_" + hostname);
muc.addMessageListener(new PacketListener()
{
@Override
public void processPacket(Packet packet) {
// TODO Auto-generated method stub
{
Message msg = (Message) packet;
handleMessage(msg);
}
}
});
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Couldn't login at MUC");
}
}
示例9: doStart
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
try {
connection = endpoint.createConnection();
} catch (SmackException e) {
if (endpoint.isTestConnectionOnStartup()) {
throw new RuntimeException("Could not connect to XMPP server.", e);
} else {
LOG.warn(e.getMessage());
if (getExceptionHandler() != null) {
getExceptionHandler().handleException(e.getMessage(), e);
}
scheduleDelayedStart();
return;
}
}
chatManager = ChatManager.getInstanceFor(connection);
chatManager.addChatListener(this);
OrFilter pubsubPacketFilter = new OrFilter();
if (endpoint.isPubsub()) {
//xep-0060: pubsub#notification_type can be 'headline' or 'normal'
pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.headline));
pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.normal));
connection.addPacketListener(this, pubsubPacketFilter);
}
if (endpoint.getRoom() == null) {
privateChat = chatManager.getThreadChat(endpoint.getChatId());
if (privateChat != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
}
privateChat.addMessageListener(this);
} else {
privateChat = ChatManager.getInstanceFor(connection).createChat(endpoint.getParticipant(), endpoint.getChatId(), this);
if (LOG.isDebugEnabled()) {
LOG.debug("Opening private chat to " + privateChat.getParticipant());
}
}
} else {
// add the presence packet listener to the connection so we only get packets that concerns us
// we must add the listener before creating the muc
final AndFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class));
connection.addPacketListener(this, packetFilter);
muc = new MultiUserChat(connection, endpoint.resolveRoom(connection));
muc.addMessageListener(this);
DiscussionHistory history = new DiscussionHistory();
history.setMaxChars(0); // we do not want any historical messages
muc.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
if (LOG.isInfoEnabled()) {
LOG.info("Joined room: {} as: {}", muc.getRoom(), endpoint.getNickname());
}
}
this.startRobustConnectionMonitor();
super.doStart();
}
示例10: testSimpleUsingSmack
import org.jivesoftware.smackx.muc.MultiUserChat; //导入方法依赖的package包/类
@Test
public void testSimpleUsingSmack() throws Exception {
try (KixmppServer server = new KixmppServer(new InetSocketAddress(SocketUtils.findAvailableTcpPort()), "testChat",
new InetSocketAddress(SocketUtils.findAvailableTcpPort()), new ConstNodeDiscovery())) {
Assert.assertNotNull(server.start().get(2, TimeUnit.SECONDS));
((InMemoryAuthenticationService) server.module(
SaslKixmppServerModule.class).getAuthenticationService())
.addUser("testUser", "testPassword");
server.module(MucKixmppServerModule.class).addService("conference")
.addRoom("someRoom");
XMPPConnection connection = new XMPPTCPConnection(
new ConnectionConfiguration("localhost", server
.getBindAddress().getPort(), server.getDomain()));
try {
connection.connect();
connection.login("testUser", "testPassword");
final LinkedBlockingQueue<Message> messages = new LinkedBlockingQueue<>();
PacketListener messageListener = new PacketListener() {
public void processPacket(Packet packet)
throws NotConnectedException {
messages.offer((Message) packet);
}
};
MultiUserChat chat = new MultiUserChat(connection,
"[email protected]");
chat.addMessageListener(messageListener);
chat.join("testNick");
chat.sendMessage("hello!");
Message message = messages.poll(2, TimeUnit.SECONDS);
Assert.assertNotNull(message);
if (null == message.getBody()
|| "".equals(message.getBody().trim())) {
message = messages.poll(2, TimeUnit.SECONDS);
Assert.assertNotNull(message);
Assert.assertEquals("hello!", message.getBody());
}
} finally {
connection.disconnect();
}
}
}