当前位置: 首页>>代码示例>>Java>>正文


Java ChatManager.getInstanceFor方法代码示例

本文整理汇总了Java中org.jivesoftware.smack.chat.ChatManager.getInstanceFor方法的典型用法代码示例。如果您正苦于以下问题:Java ChatManager.getInstanceFor方法的具体用法?Java ChatManager.getInstanceFor怎么用?Java ChatManager.getInstanceFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jivesoftware.smack.chat.ChatManager的用法示例。


在下文中一共展示了ChatManager.getInstanceFor方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMessage

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
@Test
@BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 0, concurrency = 10)
// round: 1.05 [+- 0.07], round.block: 0.74 [+- 0.25], round.gc: 0.00 [+-
// 0.00], GC.calls: 1, GC.time: 0.01, time.total: 1.08, time.warmup: 0.00,
// time.bench: 1.08
public void sendMessage() throws Exception {
	XMPPConnection xmppConnection = xmppConnectionFactory.getXMPPConnection();
	System.out.println(xmppConnection);
	//
	ChatManager chatManager = ChatManager.getInstanceFor(xmppConnection);

	Chat chat = chatManager.createChat("[email protected]");
	chat.sendMessage("test_123");
	//
	PoolableXmppConnection conn = (PoolableXmppConnection) xmppConnection;
	conn.disconnect();
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:18,代码来源:XmppConnectionFactoryImplTest.java

示例2: connect

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
public void connect(String hostname, int port, String username, String password) throws Exception {

    purgeTask("reconnect");

    this.hostname = hostname;
    this.serviceName = hostname;
    this.port = port;
    this.username = username;
    this.password = password;

    Builder builder = XMPPTCPConnectionConfiguration.builder();
    builder.setUsernameAndPassword(username, password);
    builder.setServiceName(serviceName);
    builder.setServiceName(hostname);
    builder.setPort(port);
    builder.setSecurityMode(SecurityMode.disabled);
    builder.setDebuggerEnabled(true);

    XMPPTCPConnectionConfiguration config = builder.build();

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

    roster = Roster.getInstanceFor(connection);
    chatManager = ChatManager.getInstanceFor(connection);

    roster.addRosterListener(this);

    isConnected = true;

    // not worth it - always empty right after connect
    // getContactList();

    broadcastState();
  }
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:36,代码来源:Xmpp.java

示例3: sendRaw

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
/**
 * send the raw string as a message without wrapping it with xml attributes
 * @param message the message to be sent
 * @param buddyJID the buddy to send the message to
 */
public void sendRaw(String message, String buddyJID){
  ChatManager chatManager = ChatManager.getInstanceFor(connection);
  if (connection != null && connection.isConnected() && chatManager != null){
    try{
      Chat chat = chatManager.createChat(buddyJID);
      chat.sendMessage(message);
    }catch (Exception e){
      e.printStackTrace();
    }
  }
}
 
开发者ID:Nik-Sch,项目名称:ChatApp-Android,代码行数:17,代码来源:XmppManager.java

示例4: sendTextMessage

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
/**
 * sends a text message
 *
 * @param message  the message text to send
 * @param buddyJID the Buddy to receive the message
 * @return true if sending was successful
 */
public boolean sendTextMessage(String message, String buddyJID, long id){
  ChatManager chatManager = ChatManager.getInstanceFor(connection);
  if (connection != null && connection.isConnected() && chatManager != null){
    if (buddyJID.indexOf('@') == -1)
      buddyJID += "@" + service;
    Chat chat = chatManager.createChat(buddyJID);
    try{
      // wrap the message with all necessary xml attributes
      Document doc = DocumentBuilderFactory.newInstance()
              .newDocumentBuilder().newDocument();
      Element msg = doc.createElement("message");
      doc.appendChild(msg);
      msg.setAttribute("type", MessageHistory.TYPE_TEXT);
      msg.setAttribute("id", String.valueOf(id));
      Element file = doc.createElement("content");
      msg.appendChild(file);
      file.setTextContent(message);

      // transform everything to a string
      Transformer t = TransformerFactory.newInstance().newTransformer();
      StringWriter writer = new StringWriter();
      StreamResult r = new StreamResult(writer);
      t.transform(new DOMSource(doc), r);
      message = writer.toString();

      // send the message
      chat.sendMessage(message);
      Log.d("DEBUG", "Success: Sent message");
      return true;
    }catch (Exception e){
      Log.e("ERROR", "Couldn't send message.");
      Log.e("ERROR", e.toString());
      return false;
    }
  }
  Log.e("ERROR", "Sending failed: No connection.");
  return false;
}
 
开发者ID:Nik-Sch,项目名称:ChatApp-Android,代码行数:46,代码来源:XmppManager.java

示例5: sendAcknowledgement

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
/**
 * send an acknowledgement
 * @param buddyId the buddyId to receive the acknowledgement
 * @param othersId the id the buddy has sent the message with
 * @param type the type of acknowledgement to send
 * @return true if sending was successful
 */
public boolean sendAcknowledgement(String buddyId, long othersId, String type){
  ChatManager chatManager = ChatManager.getInstanceFor(connection);
  if (connection != null && connection.isConnected() && chatManager != null){
    if (buddyId.indexOf('@') == -1)
      buddyId += "@" + service;
    Chat chat = chatManager.createChat(buddyId);
    try{
      // create the message structure
      Document doc = DocumentBuilderFactory.newInstance()
              .newDocumentBuilder().newDocument();
      Element ack = doc.createElement("acknowledgement");
      doc.appendChild(ack);
      ack.setAttribute("id", String.valueOf(othersId));
      ack.setAttribute("type", type);

      // create the string representation of the message
      Transformer t = TransformerFactory.newInstance().newTransformer();
      StringWriter writer = new StringWriter();
      StreamResult r = new StreamResult(writer);
      t.transform(new DOMSource(doc), r);
      String message = writer.toString();

      // send the message
      chat.sendMessage(message);
      Log.d("DEBUG", "Success: Sent message");
      return true;
    }catch (Exception e){
      Log.e("ERROR", "Couldn't send message.");
      Log.e("ERROR", e.toString());
      return false;
    }
  }
  Log.e("ERROR", "Sending failed: No connection.");
  return false;
}
 
开发者ID:Nik-Sch,项目名称:ChatApp-Android,代码行数:43,代码来源:XmppManager.java

示例6: initialize

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
private void initialize(){
    try{
      //initialize xmpp:
      Log.d("SERVICE_DEBUG", "MessageService initializing");
      if (xmppManager == null)
        xmppManager = XmppManager.getInstance(getApplicationContext());
      if (!xmppManager.isConnected()){
        xmppManager.init();
        xmppManager.performLogin(getUserName(), getPassword());
//        OfflineMessageManager offlineMessageManager = new
//                OfflineMessageManager(xmppManager.getConnection());
//        if (offlineMessageManager.supportsFlexibleRetrieval())
//          processMessages(offlineMessageManager.getMessages().toArray(new
//                  Message[offlineMessageManager.getMessageCount()]));
        new Thread(reloadRoster).start();
      }

      ChatManager chatManager = ChatManager.getInstanceFor(xmppManager
              .getConnection());
      chatManager.addChatListener(new MyChatManagerListener());
      xmppManager.setStatus(true, String.valueOf(getSharedPreferences(Constants
              .PREFERENCES, 0).getLong(Constants.LAST_PRESENCE_SENT, 0)));
    }catch (Exception e){
      Log.e("SERVICE_ERROR", "An error while initializing the MessageService " +
              "occurred.");
      e.printStackTrace();
    }
  }
 
开发者ID:Nik-Sch,项目名称:ChatApp-Android,代码行数:29,代码来源:MessageService.java

示例7: connect

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
public void connect() throws IOException, XMPPException, SmackException {
    if (mConnection == null) {
        createConnection();
    }

    if (!mConnection.isConnected()) {
        Logger.info(TAG, "Connecting to " + mAccount.getHost() + ":" + mAccount.getPort());
        mConnection.connect();

        Roster roster = Roster.getInstanceFor(mConnection);
        roster.removeRosterListener(this);
        roster.addRosterListener(this);
        roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all);
        roster.setRosterLoadedAtLogin(true);
    }

    if (!mConnection.isAuthenticated()) {
        Logger.info(TAG, "Authenticating " + mAccount.getXmppJid());
        mConnection.login();

        PingManager.setDefaultPingInterval(XmppService.DEFAULT_PING_INTERVAL);
        PingManager pingManager = PingManager.getInstanceFor(mConnection);
        pingManager.registerPingFailedListener(this);

        ChatManager chatManager = ChatManager.getInstanceFor(mConnection);
        chatManager.removeChatListener(this);
        chatManager.addChatListener(this);

        DeliveryReceiptManager receipts = DeliveryReceiptManager.getInstanceFor(mConnection);
        receipts.setAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.always);
        receipts.autoAddDeliveryReceiptRequests();
    }

    mOwnAvatar = getAvatarFor("");
}
 
开发者ID:VoiSmart,项目名称:xmpp-service,代码行数:36,代码来源:XmppServiceConnection.java

示例8: ChatStateManager

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
private ChatStateManager(XMPPConnection connection) {
    super(connection);
    chatManager = ChatManager.getInstanceFor(connection);
    chatManager.addOutgoingMessageInterceptor(outgoingInterceptor, filter);
    chatManager.addChatListener(incomingInterceptor);

    ServiceDiscoveryManager.getInstanceFor(connection).addFeature(NAMESPACE);
    INSTANCES.put(connection, this);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:10,代码来源:ChatStateManager.java

示例9: getChatManager

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
public ChatManager getChatManager() {
    return ChatManager.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
}
 
开发者ID:esl,项目名称:mangosta-android,代码行数:4,代码来源:RoomsListManager.java

示例10: sendImageMessage

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
/**
 * sends an image message
 *
 * @param serverFile  the file on the server
 * @param description the description of the sent image
 * @param buddyJID    the Buddy to receive the message
 * @return true if sending was successful
 */
public boolean sendImageMessage(String serverFile, String description, String
        buddyJID, long id){
  if (buddyJID.indexOf('@') == -1)
    buddyJID += "@" + service;
  ChatManager chatManager = ChatManager.getInstanceFor(connection);
  if (connection != null && connection.isConnected() && chatManager != null){
    Chat chat = chatManager.createChat(buddyJID);
    try{
      //generate the message in order to set the type to image
      Document doc = DocumentBuilderFactory.newInstance()
              .newDocumentBuilder().newDocument();
      Element msg = doc.createElement("message");
      doc.appendChild(msg);
      msg.setAttribute("type", MessageHistory.TYPE_IMAGE);
      msg.setAttribute("id", String.valueOf(id));
      Element file = doc.createElement("file");
      msg.appendChild(file);
      file.setTextContent(serverFile);
      Element desc = doc.createElement("description");
      msg.appendChild(desc);
      desc.setTextContent(description);

      // create the string
      Transformer t = TransformerFactory.newInstance().newTransformer();
      StringWriter writer = new StringWriter();
      StreamResult r = new StreamResult(writer);
      t.transform(new DOMSource(doc), r);
      String message = writer.toString();

      // send the message
      chat.sendMessage(message);
      Log.d("DEBUG", "Success: Sent message");
      return true;
    }catch (Exception e){
      Log.e("ERROR", "Couldn't send message.");
      Log.e("ERROR", e.toString());
      return false;
    }
  }
  Log.e("ERROR", "Sending failed: No connection.");
  return false;
}
 
开发者ID:Nik-Sch,项目名称:ChatApp-Android,代码行数:51,代码来源:XmppManager.java

示例11: XmppSessionImpl

import org.jivesoftware.smack.chat.ChatManager; //导入方法依赖的package包/类
public XmppSessionImpl(XmppSessionFactoryImpl xmppSessionFactoryImpl, XMPPConnection xmppConnection) {
	this.xmppSessionFactoryImpl = xmppSessionFactoryImpl;
	this.xmppConnection = xmppConnection;
	//
	this.delegate = ChatManager.getInstanceFor(xmppConnection);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:7,代码来源:XmppSessionImpl.java


注:本文中的org.jivesoftware.smack.chat.ChatManager.getInstanceFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。