Java Code Examples for org.jivesoftware.smackx.muc.MultiUserChat#join()

The following examples show how to use org.jivesoftware.smackx.muc.MultiUserChat#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void join(Message message) {
	// TODO 收到加入群的离线消息,被邀请进入群
	MucInvitation mi = message.getExtension("x", "xytalk:muc:invitation");
	String jid = mi.getRoomid();
	String roomname = mi.getRoomName();
	MultiUserChat muc;
	try {
		muc = MultiUserChatManager.getInstanceFor(Launcher.connection)
				.getMultiUserChat(JidCreate.entityBareFrom(jid));
		muc.join(Resourcepart.from(UserCache.CurrentUserName + "-" + UserCache.CurrentUserRealName));
		// 更新左侧panel,将群组UI新建出来
		createNewRoomByInvitation(jid, roomname);
	} catch (NotAMucServiceException | NoResponseException | XMPPErrorException | NotConnectedException
			| XmppStringprepException | InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example 2
Source File: XmppConnection.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 加入会议室
 * 
 * @param user 昵称
 * @param password 会议室密码
 * @param roomsName 会议室名
 */
public MultiUserChat joinMultiUserChat(String user, String roomsName, String password) {
	if (getConnection() == null)
		return null;
	try {
		// 使用XMPPConnection创建一个MultiUserChat窗口
		MultiUserChat muc = new MultiUserChat(getConnection(), roomsName + "@conference." + getConnection().getServiceName());
		// 聊天室服务将会决定要接受的历史记录数量
		DiscussionHistory history = new DiscussionHistory();
		history.setMaxChars(0);
		// history.setSince(new Date());
		// 用户加入聊天室
		muc.join(user, password, history, SmackConfiguration.getPacketReplyTimeout());
		Log.i("MultiUserChat", "会议室【" + roomsName + "】加入成功........");
		return muc;
	} catch (XMPPException e) {
		e.printStackTrace();
		Log.i("MultiUserChat", "会议室【" + roomsName + "】加入失败........");
		return null;
	}
}
 
Example 3
Source File: XmppManager.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 加入会议室
 * 
 * @param user 昵称
 * @param password 会议室密码
 * @param roomsName 会议室名
 */
public MultiUserChat joinMultiUserChat(String user, String password, String roomsName) {
	try {
		// 使用XMPPConnection创建一个MultiUserChat窗口  
		MultiUserChat muc = new MultiUserChat(getConnection(), roomsName + "@conference." + getConnection().getServiceName());
		// 聊天室服务将会决定要接受的历史记录数量  
		DiscussionHistory history = new DiscussionHistory();
		history.setMaxStanzas(0);
		//history.setSince(new Date());  
		// 用户加入聊天室  
		muc.join(user, password, history, SmackConfiguration.getPacketReplyTimeout());
		L.i(LOGTAG, "会议室加入成功........");
		return muc;
	} catch (XMPPException e) {
		e.printStackTrace();
		L.i(LOGTAG, "会议室加入失败........");
		return null;
	}
}
 
Example 4
Source File: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void joinAllRooms() throws XmppStringprepException, XMPPErrorException, NoResponseException,
		NotConnectedException, InterruptedException, NotAMucServiceException {
	// TODO 启动MUC房间订阅,订阅全部房间
	// 在sqlite库中查询MUC群组
	List<Room> dbMucRooms = Launcher.roomService.findByType("m");
	for (Room roomDb : dbMucRooms) {
		if (roomDb.getRoomId() != null && !roomDb.getRoomId().isEmpty() && roomDb.getRoomId().contains("@")) {
			MultiUserChat room = MultiUserChatManager.getInstanceFor(Launcher.connection)
					.getMultiUserChat(JidCreate.entityBareFrom(roomDb.getRoomId()));
			// 将room加入堆缓存,以便重复利用
			// roomCacheService.put(roomDb.getRoomId(),room);
			// 以“username-真实姓名”为nickname进入群
			// room.join(Resourcepart.from(UserCache.CurrentUserName + "-" +
			// UserCache.CurrentUserRealName));
			MucEnterConfiguration.Builder builder = room.getEnterConfigurationBuilder(
					Resourcepart.from(UserCache.CurrentUserName + "-" + UserCache.CurrentUserRealName));
			// 只获取最后10条历史记录
			// builder.requestMaxStanzasHistory(10);
			// 只获取该房间最后一条消息的时间戳到当前时间戳的离线
			int historySince = MucChatService.getHistoryOffsize(roomDb.getLastChatAt());
			builder.requestHistorySince(historySince);
			// 只获取2018-5-1以来的历史记录
			// builder.requestHistorySince(new Date(2018,5,1));
			MucEnterConfiguration mucEnterConfiguration = builder.build();
			room.join(mucEnterConfiguration);

		}
	}
}
 
Example 5
Source File: MUC.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    String room = sampler.getPropertyAsString(ROOM);
    String nick = sampler.getPropertyAsString(NICKNAME);
    res.setSamplerData("Join Room: " + room + "/" + nick);
    MultiUserChat muc = new MultiUserChat(sampler.getXMPPConnection(), room);
    muc.join(nick);
    return res;
}
 
Example 6
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public void reconnectAll ()
{
    MultiUserChatManager mucMgr = MultiUserChatManager.getInstanceFor(mConnection);
    mucMgr.setAutoJoinOnReconnect(true);

    Enumeration<MultiUserChat> eMuc = mMUCs.elements();
    while (eMuc.hasMoreElements())
    {
        MultiUserChat muc = eMuc.nextElement();

        MultiUserChat reMuc = mucMgr.getMultiUserChat(muc.getRoom());

        try {
            DiscussionHistory history = new DiscussionHistory();
            history.setMaxStanzas(Integer.MAX_VALUE);
            reMuc.join(Resourcepart.from(mUser.getName()), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());

            mMUCs.put(muc.getRoom().toString(),reMuc);
            ChatGroup group = mGroups.get(muc.getRoom().toString());

            addMucListeners(reMuc, group);
            loadMembers(muc, group);

            queryArchive(muc.getRoom());

        } catch (Exception e) {
            Log.w(TAG,"unable to join MUC: " + e.getMessage());
        }
    }
}
 
Example 7
Source File: IMAppender.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.
 */
@Override
public void activateOptions() {
    try {
        cb = new CyclicBuffer(bufferSize);

        // Create a connection to the XMPP server
        LogLog.debug("Stablishing connection with XMPP server");
        con = new XMPPConnection(InstantMessagingModule.getConnectionConfiguration());
        // Most servers require you to login before performing other tasks
        LogLog.debug("About to login as [" + username + "/" + password + "]");
        con.connect();
        con.login(username, password);

        // Start a conversation with IMAddress
        if (chatroom) {
            LogLog.debug("About to create ChatGroup");
            groupchat = new MultiUserChat(con, (String) recipientsList.get(0));
            LogLog.debug("About to join room");
            groupchat.join(nickname != null ? nickname : username);
        } else {
            final Iterator iter = recipientsList.iterator();
            while (iter.hasNext()) {
                chats.add(con.getChatManager().createChat((String) iter.next(), null));
            }
            // chat = con.createChat(recipients);
        }

    } catch (final XMPPException xe) {
        errorHandler.error("Error while activating options for appender named [" + name + "] Could not connect to instant messaging server with user: "
                + getUsername(), xe, ErrorCode.GENERIC_FAILURE);
    } catch (final Exception e) {
        errorHandler.error("Error while activating options for appender named [" + name + "]", e, ErrorCode.GENERIC_FAILURE);
    }
}
 
Example 8
Source File: IMAppender.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.
 */
@Override
public void activateOptions() {
    try {
        cb = new CyclicBuffer(bufferSize);

        // Create a connection to the XMPP server
        LogLog.debug("Stablishing connection with XMPP server");
        con = new XMPPConnection(InstantMessagingModule.getConnectionConfiguration());
        // Most servers require you to login before performing other tasks
        LogLog.debug("About to login as [" + username + "/" + password + "]");
        con.connect();
        con.login(username, password);

        // Start a conversation with IMAddress
        if (chatroom) {
            LogLog.debug("About to create ChatGroup");
            groupchat = new MultiUserChat(con, (String) recipientsList.get(0));
            LogLog.debug("About to join room");
            groupchat.join(nickname != null ? nickname : username);
        } else {
            final Iterator iter = recipientsList.iterator();
            while (iter.hasNext()) {
                chats.add(con.getChatManager().createChat((String) iter.next(), null));
            }
            // chat = con.createChat(recipients);
        }

    } catch (final XMPPException xe) {
        errorHandler.error("Error while activating options for appender named [" + name + "] Could not connect to instant messaging server with user: "
                + getUsername(), xe, ErrorCode.GENERIC_FAILURE);
    } catch (final Exception e) {
        errorHandler.error("Error while activating options for appender named [" + name + "]", e, ErrorCode.GENERIC_FAILURE);
    }
}
 
Example 9
Source File: XmppClient.java    From riotapi with Apache License 2.0 5 votes vote down vote up
public MultiUserChat joinChannelWithoutHashing(String name, String password) {
	MultiUserChat chat = new MultiUserChat(this, name);
	chatRooms.put(name, chat);
	try {
		chat.join(getUsername(), password);
		return chat;
	} catch (XMPPException.XMPPErrorException | SmackException e) {
		throw new IllegalStateException(e);
	}
}
 
Example 10
Source File: ConferenceUtils.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Joins a chat room without using the UI.
 *
 * @param groupChat the <code>MultiUserChat</code>
 * @param nickname  the nickname of the user.
 * @param password  the password to join the room with.
 * @return a List of errors, if any.
 */
public static List<String> joinRoom(MultiUserChat groupChat, Resourcepart nickname, String password) {
    final List<String> errors = new ArrayList<>();
    if ( !groupChat.isJoined() )
    {
        try
        {
            if ( ModelUtil.hasLength( password ) )
            {
                groupChat.join( nickname, password );
            }
            else
            {
                groupChat.join( nickname );
            }
            changePresenceToAvailableIfInvisible();
        }
        catch ( XMPPException | SmackException | InterruptedException ex )
        {
            StanzaError error = null;
            if ( ex instanceof XMPPException.XMPPErrorException )
            {
                error = ( (XMPPException.XMPPErrorException) ex ).getStanzaError();
            }

            final String errorText = ConferenceUtils.getReason( error );
            errors.add( errorText );
        }
    }

    return errors;
}
 
Example 11
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
@Override
        public void joinChatGroupAsync(Address address, String reason) {

            String chatRoomJid = address.getBareAddress();
            String[] parts = chatRoomJid.split("@");
            String room = parts[0];

            try {

                if (mConnection == null || (!mConnection.isAuthenticated()))
                    return;

//                mBookmarkManager.addBookmarkedConference(address.getUser(),JidCreate.entityBareFrom(chatRoomJid),true,null,null);

                // Create a MultiUserChat using a Connection for a room
                MultiUserChatManager mucMgr = MultiUserChatManager.getInstanceFor(mConnection);
                mucMgr.setAutoJoinOnReconnect(true);
                EntityBareJid crJid = JidCreate.entityBareFrom(chatRoomJid);
                MultiUserChat muc = mucMgr.getMultiUserChat( crJid);

                DiscussionHistory history = new DiscussionHistory();
                history.setMaxStanzas(Integer.MAX_VALUE);
                muc.join(Resourcepart.from(mUser.getName()), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
                String subject = muc.getSubject();

                if (TextUtils.isEmpty(subject))
                    subject = room;

                ChatGroup chatGroup = mGroups.get(chatRoomJid);

                if (chatGroup == null) {
                    chatGroup = new ChatGroup(address, subject, this);
                    mGroups.put(chatRoomJid, chatGroup);
                }

                mMUCs.put(chatRoomJid, muc);

                addMucListeners(muc, chatGroup);
                loadMembers(muc, chatGroup);

                queryArchive(crJid);

            } catch (Exception e) {
                debug(TAG,"error joining MUC",e);
            }

        }
 
Example 12
Source File: YiIMUtils.java    From yiim_v2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 加入会议室
 * 
 * @param user
 *            昵称
 * @param password
 *            会议室密码
 * @param roomsName
 *            会议室名
 */
public static MultiUserChat joinMultiUserChat(Context context, String user,
		String roomJid, String password) throws Exception {
	XMPPConnection connection = XmppConnectionUtils.getInstance()
			.getRawConnection();
	if (connection == null || !connection.isConnected()
			|| !connection.isAuthenticated())
		throw new Exception("connection not ready");

	Cursor cursor = null;
	try {
		// 使用XMPPConnection创建一个MultiUserChat窗口
		MultiUserChat muc = new MultiUserChat(connection, roomJid);
		// 聊天室服务将会决定要接受的历史记录数量
		DiscussionHistory history = new DiscussionHistory();

		cursor = context.getContentResolver().query(
				MultiChatRoomColumns.CONTENT_URI,
				new String[] { MultiChatRoomColumns.LAST_MSG_TIME },
				MultiChatRoomColumns.ROOM_JID + "='" + roomJid + "' and "
						+ MultiChatRoomColumns.OWNER + "='"
						+ UserInfo.getUserInfo(context).getUser() + "'",
				null, null);
		if (cursor != null && cursor.getCount() == 1) {
			cursor.moveToFirst();
			history.setSince(new Date(cursor.getLong(0)));
		} else {
			history.setMaxStanzas(15);
		}
		// 用户加入聊天室
		muc.join(StringUtils.escapeUserHost(user), password, history,
				SmackConfiguration.getPacketReplyTimeout());
		return muc;
	} catch (Exception e) {
		throw e;
	} finally {
		if (cursor != null) {
			cursor.close();
			cursor = null;
		}
	}
}