Java Code Examples for org.jivesoftware.smack.chat2.Chat#send()

The following examples show how to use org.jivesoftware.smack.chat2.Chat#send() . 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
private static void sendOfflineInvitationMessage(List<String> users, String roomid, String roomName)
		throws XmppStringprepException {
	// TODO 对离线用户应发送邀请消息,并让服务器存储离线消息,待用户上线后还应对此类消息进行处理
	MucInvitation mi = new MucInvitation(roomid, roomName);

	for (int i = 0; i < users.size(); i++) {
		String userJid = users.get(i);
		Chat chat = ChatManager.getInstanceFor(Launcher.connection).chatWith(JidCreate.entityBareFrom(userJid));
		org.jivesoftware.smack.packet.Message message = new org.jivesoftware.smack.packet.Message();
		message.setType(Type.chat);
		message.addExtension(mi);
		message.setBody("请加入会议");
		try {
			chat.send(message);
			DebugUtil.debug("sendOfflineInvitationMessage:" + message.toXML());
		} catch (NotConnectedException | InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
 
Example 2
Source File: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void sendInvitationMessage(List<Jid> users, String roomid, String roomName){
	MucInvitation mi = new MucInvitation(roomid, roomName);

	for (int i = 0; i < users.size(); i++) {
		Jid userJid = users.get(i);
		Chat chat = ChatManager.getInstanceFor(Launcher.connection).chatWith(userJid.asEntityBareJidIfPossible());
		org.jivesoftware.smack.packet.Message message = new org.jivesoftware.smack.packet.Message();
		message.setType(Type.chat);
		message.addExtension(mi);
		message.setBody("请加入会议");
		try {
			chat.send(message);
			DebugUtil.debug("sendOfflineInvitationMessage:" + message.toXML());
		} catch (NotConnectedException | InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
Example 3
Source File: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void sendKickMessage(List<Jid> users, String roomId, String name) {
	MucKick mucKick = new MucKick(roomId, name);

	for (int i = 0; i < users.size(); i++) {
		Jid userJid = users.get(i);
		Chat chat;
		chat = ChatManager.getInstanceFor(Launcher.connection).chatWith(userJid.asEntityBareJidIfPossible());
		org.jivesoftware.smack.packet.Message message = new org.jivesoftware.smack.packet.Message();
		message.setType(Type.chat);
		message.addExtension(mucKick);
		message.setBody("被管理员删除出群:"+name);
		try {
			chat.send(message);
			DebugUtil.debug("sendKickMessage:" + message.toXML());
		} catch (NotConnectedException | InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
 
Example 4
Source File: XmppFileService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void requestOfflineFile(org.jivesoftware.smack.packet.Message message) {
	// TODO 向离线文件机器人发送请求
	// 将接收到的离线文件消息,原封不动的发给离线文件机器人 ,
	//	离线机器人接收后,会立即将已存储的文件发过来,同时会发送一条消息回执,发送成功后,删除文件
	//	用户收到回执后,需要对聊天UI进行处理,注意:此时的fromJid是机器人,应处理为实际发送者,即senderFullJid
	Chat chat;
	try {
		chat = ChatManager.getInstanceFor(Launcher.connection).chatWith(JidCreate.entityBareFrom(Launcher.OFFLINEFILEROBOTJID));
        
		chat.send(message); //发送请求到机器人,然后机器人会把文件发给我
		OfflineFile of = (OfflineFile)message.getExtension(OfflineFile.NAMESPACE);
		offlineFileJidMap.put(of.getFileName(), of.getSenderFullJid());
		DebugUtil.debug( "send offlinefile request:"+ message.toXML());	
		
	} catch (XmppStringprepException |NotConnectedException | InterruptedException e) {
		
	}
}
 
Example 5
Source File: ChatStateIntegrationTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@SmackIntegrationTest
public void testChatStateListeners() throws Exception {
    ChatStateManager manOne = ChatStateManager.getInstance(conOne);
    ChatStateManager manTwo = ChatStateManager.getInstance(conTwo);

    // Add chatState listeners.
    manTwo.addChatStateListener(this::composingListener);
    manTwo.addChatStateListener(this::activeListener);

    Chat chatOne = ChatManager.getInstanceFor(conOne)
            .chatWith(conTwo.getUser().asEntityBareJid());

    // Test, if setCurrentState works and the chatState arrives
    manOne.setCurrentState(ChatState.composing, chatOne);
    composingSyncPoint.waitForResult(timeout);

    // Test, if the OutgoingMessageInterceptor successfully adds a chatStateExtension of "active" to
    // an outgoing chat message and if it arrives at the other side.
    Chat chat = ChatManager.getInstanceFor(conOne)
            .chatWith(conTwo.getUser().asEntityBareJid());
    chat.send("Hi!");
    activeSyncPoint.waitForResult(timeout);
}
 
Example 6
Source File: StanzaThread.java    From tutorials with MIT License 6 votes vote down vote up
@Override
public void run() {
    XMPPTCPConnectionConfiguration config = null;
    try {
        config = XMPPTCPConnectionConfiguration.builder()
                .setUsernameAndPassword("baeldung2","baeldung2")
                .setXmppDomain("jabb3r.org")
                .setHost("jabb3r.org")
                .build();

        AbstractXMPPConnection connection = new XMPPTCPConnection(config);
        connection.connect();
        connection.login();

        ChatManager chatManager = ChatManager.getInstanceFor(connection);

        Chat chat = chatManager.chatWith(JidCreate.from("[email protected]").asEntityBareJidOrThrow());

        chat.send("Hello!");

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 7
Source File: ChatStateManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the current state of the provided chat. This method will send an empty bodied Message
 * stanza with the state attached as a {@link org.jivesoftware.smack.packet.ExtensionElement}, if
 * and only if the new chat state is different than the last state.
 *
 * @param newState the new state of the chat
 * @param chat the chat.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void setCurrentState(ChatState newState, Chat chat) throws NotConnectedException, InterruptedException {
    if (chat == null || newState == null) {
        throw new IllegalArgumentException("Arguments cannot be null.");
    }
    if (!updateChatState(chat, newState)) {
        return;
    }
    Message message = StanzaBuilder.buildMessage().build();
    ChatStateExtension extension = new ChatStateExtension(newState);
    message.addExtension(extension);

    chat.send(message);
}
 
Example 8
Source File: XmppFileService.java    From xyTalk-pc with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void sendOfflineFileMsg(String fileFullPath, String reciveBareJid,String uuid,boolean toRobot) {
	String fileType;
	String fileName = fileFullPath.substring(fileFullPath.lastIndexOf(System.getProperty("file.separator"))+1);

	boolean isImage;
	if (fileFullPath.lastIndexOf(".")<0){
		isImage = false;
	}else{
		String type = MimeTypeUtil.getMime(fileFullPath.substring(fileFullPath.lastIndexOf(".")));
		isImage = type.startsWith("image/");
	}
	
	if (isImage){
		fileType = "image";
	}
	else{
		fileType = "file";
	}
	
	OfflineFile of = null;
	OfflineFileRobot ofr = null; 
	
	if (toRobot){
		ofr = new OfflineFileRobot(UserCache.CurrentBareJid,reciveBareJid,fileType,uuid,fileName);
	}else{
		of = new OfflineFile(UserCache.CurrentBareJid,reciveBareJid,fileType,uuid,fileName);
	}
		
	
	Chat chat;
	try {
		chat = ChatManager.getInstanceFor(Launcher.connection).chatWith(JidCreate.entityBareFrom(reciveBareJid));
        org.jivesoftware.smack.packet.Message message = new org.jivesoftware.smack.packet.Message();
        message.setType(Type.chat);
        
        if (toRobot){
	        message.addExtension(ofr);	        	
        }else{
	        message.addExtension(of);	        	
        }

        message.setBody(UserCache.CurrentUserRealName + " 发给您离线文件,即将接收:"+fileName);
		chat.send(message);
		DebugUtil.debug( "send offlinefile msg:"+ message.toXML());	
		
	} catch (XmppStringprepException |NotConnectedException | InterruptedException e) {
		
	}
}