org.jivesoftware.smackx.muc.MultiUserChat Java Examples
The following examples show how to use
org.jivesoftware.smackx.muc.MultiUserChat.
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: ChatManager.java From Spark with Apache License 2.0 | 6 votes |
/** * Creates a new public Conference Room. * * @param roomName the name of the room. * @param serviceName the service name to use (ex.conference.jivesoftware.com) * @return the new ChatRoom created. If an error occured, null will be returned. */ public ChatRoom createConferenceRoom(Localpart roomName, DomainBareJid serviceName) { EntityBareJid roomAddress = JidCreate.entityBareFrom(roomName, serviceName); final MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor( SparkManager.getConnection()).getMultiUserChat( roomAddress); final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(chatRoom); try { LocalPreferences pref = SettingsManager.getLocalPreferences(); Resourcepart nickname = pref.getNickname(); chatRoom.create(nickname); // Send an empty room configuration form which indicates that we want // an instant room chatRoom.sendConfigurationForm(new Form( DataForm.Type.submit )); } catch (XMPPException | SmackException | InterruptedException e1) { Log.error("Unable to send conference room chat configuration form.", e1); return null; } getChatContainer().addChatRoom(room); return room; }
Example #2
Source File: MucManager.java From Yahala-Messenger with MIT License | 6 votes |
public List<String> getRoomParticipants(String threadId) { List<EntityFullJid> usersJids = null; List<String> usersIds = new ArrayList<>(); try { //RoomInfo roomInfo = manager.getRoomInfo(JidCreate.entityBareFrom(threadId)); MultiUserChat multiUserChat = manager.getMultiUserChat(JidCreate.entityBareFrom(threadId)); usersJids = multiUserChat.getOccupants(); for (EntityFullJid entityFullJid : usersJids) { usersIds.add(entityFullJid.toString()); } } catch (XmppStringprepException e) { e.printStackTrace(); } return usersIds; }
Example #3
Source File: RoomMembersPanel.java From xyTalk-pc with GNU Affero General Public License v3.0 | 6 votes |
private void inviteOrKick(final String[] usernames, String type) throws XmppStringprepException { if (usernames.length == 0) return; MultiUserChat muc = MultiUserChatManager.getInstanceFor(Launcher.connection).getMultiUserChat(JidCreate.entityBareFrom(roomId)); //邀请成员 if (type.equals("invite")){ addMan(usernames, muc); } //删除成员,踢人 if (type.equals("kick")){ kickMan(usernames, muc); } //刷新群成员UI updateUI(); }
Example #4
Source File: MucChatService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 6 votes |
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 #5
Source File: XmppConnection.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
public void setGroupSubject(final ChatGroup group, final String subject) { execute (new Runnable() { public void run() { String chatRoomJid = group.getAddress().getAddress(); if (mMUCs.containsKey(chatRoomJid)) { MultiUserChat muc = mMUCs.get(chatRoomJid); try { muc.changeSubject(subject); } catch (Exception e) { e.printStackTrace(); } } } }); }
Example #6
Source File: XmppConnection.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
@Override public void leaveChatGroupAsync(ChatGroup group) { String chatRoomJid = group.getAddress().getBareAddress(); if (mMUCs.containsKey(chatRoomJid)) { try { // mBookmarkManager.removeBookmarkedConference(JidCreate.entityBareFrom(chatRoomJid)); } catch (Exception e){} MultiUserChat muc = mMUCs.get(chatRoomJid); try { muc.leave(); } catch (Exception nce) { Log.e(ImApp.LOG_TAG,"not connected error trying to leave group",nce); } mMUCs.remove(chatRoomJid); } }
Example #7
Source File: XmppConnection.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
@Override public void joined(EntityFullJid entityFullJid) { XmppAddress xa = new XmppAddress(entityFullJid.toString()); ChatGroup chatGroup = mChatGroupManager.getChatGroup(xa); MultiUserChat muc = mChatGroupManager.getMultiUserChat(entityFullJid.asBareJid().toString()); Occupant occupant = muc.getOccupant(entityFullJid); Jid jidSource = (occupant != null) ? occupant.getJid() : null; if (jidSource != null) xa = new XmppAddress(jidSource.toString()); else xa = new XmppAddress(entityFullJid.toString()); Contact mucContact = new Contact(xa, xa.getUser(), Imps.Contacts.TYPE_NORMAL); chatGroup.notifyMemberJoined(entityFullJid.toString(),mucContact); if (occupant != null) { chatGroup.notifyMemberRoleUpdate(mucContact, occupant.getRole().name(), occupant.getAffiliation().toString()); } }
Example #8
Source File: WorkgroupManager.java From Spark with Apache License 2.0 | 6 votes |
@Override public boolean handleInvitation(final XMPPConnection conn, final MultiUserChat room, final EntityBareJid inviter, final String reason, final String password, final Message message) { invites.add(inviter); if (message.getExtension("workgroup", "http://jabber.org/protocol/workgroup") != null) { Localpart workgroupName = inviter.getLocalpart(); GroupChatRoom groupChatRoom = ConferenceUtils.enterRoomOnSameThread(workgroupName, room.getRoom(), password); int tabLocation = SparkManager.getChatManager().getChatContainer().indexOfComponent(groupChatRoom); groupChatRoom.setTabIcon(FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_16x16)); if (tabLocation != -1) { SparkTab tab = SparkManager.getChatManager().getChatContainer().getTabAt(tabLocation); tab.setIcon(FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_16x16)); } return true; } return false; }
Example #9
Source File: XmppService.java From yiim_v2 with GNU General Public License v2.0 | 6 votes |
private synchronized void reInitMultiUserChat() { synchronized (mLocker) { Iterator<String> iterator = mNeedReInitMultiChatRooms.iterator(); while (iterator.hasNext()) { String roomJid = iterator.next(); MultiUserChat chat = mMultiUserChats.get(roomJid); if (chat == null) { // 如果重新初始化成功,则移除 chat = initMultiUserChat(roomJid, true); if (chat != null && YiIMUtils.isMultiChatJoined(this, roomJid)) { iterator.remove(); } } } } }
Example #10
Source File: XmppService.java From yiim_v2 with GNU General Public License v2.0 | 6 votes |
public int createRoom(String user, String roomName, String roomDesc, String password) { try { MultiUserChat chat = YiIMUtils.createMultiUserChat( mService.get(), user, roomName, roomDesc, password); if (chat != null) { synchronized (mService.get().mLocker) { mService.get().mMultiUserChats .put(chat.getRoom(), chat); } return 0; } return -1; } catch (Exception e) { if ("room already exist".equals(e.getMessage())) { return -2; } YiLog.getInstance().e(e, "create room failed"); return -1; } }
Example #11
Source File: XmppService.java From yiim_v2 with GNU General Public License v2.0 | 6 votes |
public void inviteFriend(String roomJid, String user, boolean autoJoin) { MultiUserChat chat = null; synchronized (mService.get().mLocker) { chat = mService.get().mMultiUserChats.get(roomJid); } if (chat == null && autoJoin) { chat = mService.get().initMultiUserChat(roomJid, false); } if (chat != null) { try { chat.invite(user, ""); } catch (Exception e) { } } }
Example #12
Source File: XmppConnection.java From weixin with Apache License 2.0 | 6 votes |
/** * 初始化会议室列表 */ public List<HostedRoom> getHostRooms() { if (getConnection() == null) return null; Collection<HostedRoom> hostrooms = null; List<HostedRoom> roominfos = new ArrayList<HostedRoom>(); try { new ServiceDiscoveryManager(getConnection()); hostrooms = MultiUserChat.getHostedRooms(getConnection(), getConnection().getServiceName()); for (HostedRoom entry : hostrooms) { roominfos.add(entry); Log.i("room", "名字:" + entry.getName() + " - ID:" + entry.getJid()); } Log.i("room", "服务会议数量:" + roominfos.size()); } catch (XMPPException e) { e.printStackTrace(); } return roominfos; }
Example #13
Source File: XmppConnection.java From weixin with Apache License 2.0 | 6 votes |
/** * 加入会议室 * * @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 #14
Source File: XmppManager.java From weixin with Apache License 2.0 | 6 votes |
/** * 加入会议室 * * @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 #15
Source File: XmppManager.java From weixin with Apache License 2.0 | 6 votes |
/** * 获取服务器上所有会议室 * * @return * @throws XMPPException */ public List<FriendRooms> getConferenceRoom() throws XMPPException { List<FriendRooms> list = new ArrayList<FriendRooms>(); new ServiceDiscoveryManager(getConnection()); if (!MultiUserChat.getHostedRooms(getConnection(), getConnection().getServiceName()).isEmpty()) { for (HostedRoom k : MultiUserChat.getHostedRooms(getConnection(), getConnection().getServiceName())) { for (HostedRoom j : MultiUserChat.getHostedRooms(getConnection(), k.getJid())) { RoomInfo info2 = MultiUserChat.getRoomInfo(getConnection(), j.getJid()); if (j.getJid().indexOf("@") > 0) { FriendRooms friendrooms = new FriendRooms(); friendrooms.setName(j.getName());//聊天室的名称 friendrooms.setJid(j.getJid());//聊天室JID friendrooms.setOccupants(info2.getOccupantsCount());//聊天室中占有者数量 friendrooms.setDescription(info2.getDescription());//聊天室的描述 friendrooms.setSubject(info2.getSubject());//聊天室的主题 list.add(friendrooms); } } } } return list; }
Example #16
Source File: MultiUserChatStateManager.java From saros with GNU General Public License v2.0 | 6 votes |
/** * Returns the {@link MultiUserChatStateManager} associated to the {@link MultiUserChat}. Creates * one if it does not yet exist. * * @param connection * @param muc * @return */ public static MultiUserChatStateManager getInstance( final Connection connection, final MultiUserChat muc) { if (connection == null) { return null; } synchronized (managers) { MultiUserChatStateManager manager = managers.get(muc); if (manager == null) { manager = new MultiUserChatStateManager(connection, muc); managers.put(muc, manager); } return manager; } }
Example #17
Source File: Room.java From HippyJava with MIT License | 6 votes |
public static Room createRoom(String name, MultiUserChat chat, XMPPConnection con) { final Room r = new Room(name, chat); try { r.info = MultiUserChat.getRoomInfo(con, (name.indexOf("@") != -1 ? name : name + "@" + CONF_URL)); } catch (XMPPException e) { e.printStackTrace(); } r.subject = r.info.getSubject(); chat.addSubjectUpdatedListener(new SubjectUpdatedListener() { public void subjectUpdated(String newsubject, String from) { r.subject = newsubject; } }); for (String user : r.getConnectedUsers()) { r.users.add(user); } r.startThread(); return r; }
Example #18
Source File: YiIMUtils.java From yiim_v2 with GNU General Public License v2.0 | 6 votes |
public static boolean isRoomExist(String roomJid) throws Exception { XMPPConnection connection = XmppConnectionUtils.getInstance() .getRawConnection(); if (connection == null || !connection.isAuthenticated()) { throw new Exception("no connections"); } try { RoomInfo roomInfo = MultiUserChat.getRoomInfo(connection, roomJid); if (roomInfo != null) { return true; } return false; } catch (Exception e) { return false; } }
Example #19
Source File: InviteSwingWorker.java From Spark with Apache License 2.0 | 6 votes |
@Override public Object construct() { final Set<EntityBareJid> invitedJIDs = new HashSet<>(); final MultiUserChat groupChat = MultiUserChatManager.getInstanceFor( SparkManager.getConnection() ).getMultiUserChat( roomJID ); // Send invitations for ( final EntityBareJid jid : invitees) { try { groupChat.invite(jid, invitation); invitedJIDs.add( jid ); } catch ( SmackException.NotConnectedException | InterruptedException e ) { Log.warning( "Unable to invite " + jid + " to " + roomJID, e ); } } return invitedJIDs; }
Example #20
Source File: AnswerFormDialog.java From Spark with Apache License 2.0 | 6 votes |
/** * Sends the Answer Form * @param answer <u>must be an answer-form</u> * @param chat */ private void sendAnswerForm(Form answer, MultiUserChat chat) { ChatRoom room = SparkManager.getChatManager().getChatRoom(chat.getRoom().toString()); for (String key : _map.keySet()) { String value = getValueFromComponent(key); answer.setAnswer(key, value); } try { chat.sendRegistrationForm(answer); String reg = Res.getString("message.groupchat.registered.member", chat.getRoom()); room.getTranscriptWindow().insertNotificationMessage(reg,ChatManager.NOTIFICATION_COLOR); } catch (XMPPException | SmackException | InterruptedException e) { room.getTranscriptWindow().insertNotificationMessage(e.getMessage(),ChatManager.ERROR_COLOR); } }
Example #21
Source File: XmppService.java From yiim_v2 with GNU General Public License v2.0 | 6 votes |
public Iterator<String> getRoomMembers(String roomJid) { MultiUserChat chat = null; synchronized (mService.get().mLocker) { chat = mService.get().mMultiUserChats.get(roomJid); } if (chat == null) { chat = mService.get().initMultiUserChat(roomJid, false); } if (chat != null) { try { return chat.getOccupants(); } catch (Exception e) { // TODO: handle exception } } return null; }
Example #22
Source File: RoomCreationDialog.java From Spark with Apache License 2.0 | 5 votes |
private MultiUserChat createGroupChat(String roomName, DomainBareJid serviceName) { String roomString = roomName.replaceAll(" ", "_") + "@" + serviceName; EntityBareJid room = JidCreate.entityBareFromOrThrowUnchecked(roomString); // Create a group chat with valid information return MultiUserChatManager.getInstanceFor( SparkManager.getConnection() ).getMultiUserChat( room ); }
Example #23
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 查询会议室成员名字 * * @param muc */ public List<String> findMulitUser(MultiUserChat muc) { List<String> listUser = new ArrayList<String>(); Iterator<String> it = muc.getOccupants(); //遍历出聊天室人员名称 while (it.hasNext()) { // 聊天室成员名字 String name = StringUtils.parseResource(it.next()); listUser.add(name); } return listUser; }
Example #24
Source File: XmppConnection.java From weixin with Apache License 2.0 | 5 votes |
/** * 查询会议室成员名字 * * @param muc */ public List<String> findMulitUser(MultiUserChat muc) { if (getConnection() == null) return null; List<String> listUser = new ArrayList<String>(); Iterator<String> it = muc.getOccupants(); // 遍历出聊天室人员名称 while (it.hasNext()) { // 聊天室成员名字 String name = StringUtils.parseResource(it.next()); listUser.add(name); } return listUser; }
Example #25
Source File: XmppClient.java From riotapi with Apache License 2.0 | 5 votes |
public XmppClient(Shard server, String username, String pass) { super(buildConnectionConfiguration(server)); this.server = server; this.username = username; this.pass = pass; chatRooms = new HashMap<String, MultiUserChat>(); }
Example #26
Source File: XSCHelper.java From PracticeCode with Apache License 2.0 | 5 votes |
/** * 发送信息到云同步室 * * @param room 云同步室 * @param msg 将要发送的信息 */ public void sendProjChromMsg(MultiUserChat room, Object msg) { if (!room.isJoined()) return; try { Message message = new Message(room.getRoom(), Message.Type.groupchat); message.setBody(SysUtil.getInstance().getDateAndTimeFormated()); message.setProperty(MSGCLOUD, msg); room.sendMessage(message); } catch (XMPPException e) { e.printStackTrace(); } }
Example #27
Source File: MultiRoomDiscoverActivity.java From yiim_v2 with GNU General Public License v2.0 | 5 votes |
public void onSearchClick(View view) { if (isStringInvalid(mSearchEditText.getText())) { showMsgDialog(getString(R.string.err_empty_search_content), getString(R.string.str_ok)); return; } ArrayList<TabContactsModel> models = new ArrayList<TabContactsModel>(); try { String roomJid = YiHanziToPinyin.getPinYin(mSearchEditText .getText().toString()) + "@conference." + XmppConnectionUtils.getXmppHost(); RoomInfo roomInfo = MultiUserChat.getRoomInfo(getXmppBinder() .getXmppConnection(), roomJid); if (roomInfo != null) { TabContactsModel model = new TabContactsModel(); MultiChatDesc desc = MultiChatDesc.fromString(roomInfo .getDescription()); if (!YiUtils.isStringInvalid(roomInfo.getSubject())) { model.setMsg(roomInfo.getSubject()); } else if (!YiUtils.isStringInvalid(desc.getName())) { model.setMsg(desc.getName()); } else { model.setMsg(roomInfo.getRoom()); } model.setUser(roomInfo.getRoom()); model.setSubMsg(roomInfo.getDescription()); models.add(model); } } catch (Exception e) { // TODO: handle exception }finally { Message message = getHandler().obtainMessage(MSG_UPDATE_LIST, models); message.sendToTarget(); } }
Example #28
Source File: MucChatService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 5 votes |
public static void mucInvitation() { MultiUserChatManager.getInstanceFor(Launcher.connection).addInvitationListener(new InvitationListener() { @Override public void invitationReceived(XMPPConnection conn, MultiUserChat room, EntityJid inviter, String reason, String password, Message message, Invite invitation) { String barejid = message.getFrom().toString(); DebugUtil.debug("被邀请加入群聊:" + barejid + reason); try { room.join(Resourcepart.from(UserCache.CurrentUserName + "-" + UserCache.CurrentUserRealName)); if (barejid != null) { if (Launcher.currRoomId.equals(barejid)) { // 当前聊天者即为已有群 // updateChatPanel(message); } else { if (Launcher.roomService.exist(barejid)) { // 联系人列表中存在群组,更新未读信息,则修改 // updateRoom(message); } else { // 联系人中不存在群组,则新建一个群 createNewRoom(message); } // dbMessagePersistence(message); } } } catch (NotAMucServiceException | NoResponseException | XMPPErrorException | NotConnectedException | XmppStringprepException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }
Example #29
Source File: XmppClient.java From riotapi with Apache License 2.0 | 5 votes |
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 #30
Source File: MucManager.java From Yahala-Messenger with MIT License | 5 votes |
@Override public void invitationReceived(XMPPConnection conn, MultiUserChat room, String inviter, String reason, String password, Message message) { final EntityBareJid roomBareJid = room.getRoom(); if (!manager.getJoinedRooms().contains(room.getRoom())) { joinRoom(roomBareJid); //List<String> usersJids = getRoomParticipants(roomBareJid.asEntityBareJidString()); //DbHelper.addRoomToDb(roomBareJid, "", null); } }