public static synchronized final void enableJingle() { if( enabled ) return; enabled = true; ProviderManager providerManager = ProviderManager.getInstance(); providerManager.addIQProvider( JingleIQ.ELEMENT_NAME, JingleIQ.NAMESPACE, new JingleIQProvider()); Connection.addConnectionCreationListener(new ConnectionCreationListener() { public synchronized void connectionCreated(Connection connection) { if( ! ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(JingleIQ.NAMESPACE) ) ServiceDiscoveryManager.getInstanceFor(connection).addFeature(JingleIQ.NAMESPACE); } }); }
public ConnectionCreationListener createConnectionListener() { connectionCreationListener = new ConnectionCreationListener() { @Override public void connectionCreated(XMPPConnection xmppConnection) { FileLog.e("Test", "Connection created: Successful!"); } }; return connectionCreationListener; }
/** * Initializes the connection by creating a stanza(/packet) reader and writer and opening a * XMPP stream to the server. * * @throws XMPPException if establishing a connection to the server fails. * @throws SmackException if the server failes to respond back or if there is anther error. * @throws IOException */ private void initConnection() throws IOException { boolean isFirstInitialization = packetReader == null || packetWriter == null; compressionHandler = null; // Set the reader and writer instance variables initReaderAndWriter(); if (isFirstInitialization) { // 创建包的读写器 packetWriter = new PacketWriter(); packetReader = new PacketReader(); // If debugging is enabled, we should start the thread that will listen for // all packets and then log them. if (config.isDebuggerEnabled()) { addAsyncStanzaListener(debugger.getReaderListener(), null); if (debugger.getWriterListener() != null) { addPacketSendingListener(debugger.getWriterListener(), null); } } } // Start the packet writer. This will open an XMPP stream to the server packetWriter.init(); // Start the packet reader. The startup() method will block until we // get an opening stream packet back from server packetReader.init(); if (isFirstInitialization) { // Notify listeners that a new connection has been established for (ConnectionCreationListener listener : getConnectionCreationListeners()) { listener.connectionCreated(this); } } }
/** * Setup the jingle system to let the remote clients know we support Jingle. * (This used to be a static part of construction. The problem is a remote client might * attempt a Jingle connection to us after we've created an XMPPConnection, but before we've * setup an instance of a JingleManager. We will appear to not support Jingle. With the new * method you just call it once and all new connections will report Jingle support.) */ public static void setJingleServiceEnabled() { ProviderManager.addIQProvider("jingle", "urn:xmpp:tmp:jingle", new JingleProvider()); // Enable the Jingle support on every established connection // The ServiceDiscoveryManager class should have been already // initialized XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { public void connectionCreated(XMPPConnection connection) { JingleManager.setServiceEnabled(connection, true); } }); }
@Override public void onCreate() { Log.d(TAG, "onCreate"); if (instance != null) Log.d(TAG, "instance is already defined !"); instance = this; notificationsEnabled = MessengerPreferences.areNotificationsEnabled(); ringtone = MessengerPreferences.getNotificationRingtone(); ringtoneUri = MessengerPreferences.getNotificationRingtoneUri(); vibrateEnabled = MessengerPreferences.isNotificationVibrationEnabled(); chats = new ArrayList<Chat>(); roster = new ArrayList<PRosterEntry>(); savedMessages = new ArrayList<org.jivesoftware.smack.packet.Message>(); pendingActions = new LinkedHashMap<String, Object>(); configure(ProviderManager.getInstance()); Connection.addConnectionCreationListener(new ConnectionCreationListener() { public void connectionCreated(Connection connection) { reconnectionManager = new ReconnectionManager(connection, ConnectionState.getInstance(MessengerService.this).isOnline()); connection.addConnectionListener(reconnectionManager); } }); registerReceiver(new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { Log.i(TAG, "Connection status change to " + ConnectionState.getInstance(MessengerService.this).isOnline()); onConnectivityChange(); } }, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")); connect(); }
/** * Setup the jingle system to let the remote clients know we support Jingle. * (This used to be a static part of construction. The problem is a remote client might * attempt a Jingle connection to us after we've created a Connection, but before we've * setup an instance of a JingleManager. We will appear to not support Jingle. With the new * method you just call it once and all new connections will report Jingle support.) */ public static void setJingleServiceEnabled() { ProviderManager providerManager = ProviderManager.getInstance(); providerManager.addIQProvider("jingle", "urn:xmpp:tmp:jingle", new JingleProvider()); // Enable the Jingle support on every established connection // The ServiceDiscoveryManager class should have been already // initialized Connection.addConnectionCreationListener(new ConnectionCreationListener() { public void connectionCreated(Connection connection) { JingleManager.setServiceEnabled(connection, true); } }); }
@Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); mHandlerProxy = new YiHandlerProxy(this, this); mXmppConnection = null; mXmppBinder = new XmppBinder(this); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager = new com.ikantech.yiim.common.NotificationManager( this, mXmppBinder, notificationManager); mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); mAVCallManager = new AVCallManager(this); mSoundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0); mSoundIds = new HashMap<String, Integer>(); mSoundIds.put(MSG_SOUND, mSoundPool.load(this, R.raw.office, 1)); mVibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE); mLocker = new Object(); mMultiUserChats = new HashMap<String, MultiUserChat>(); mChats = new HashMap<String, Chat>(); mNeedReInitMultiChatRooms = new ArrayList<String>(); mMsgReceivedBroadcast = new MsgReceivedBroadcast(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Const.NOTIFY_MSG_RECEIVED_OR_SENT); registerReceiver(mMsgReceivedBroadcast, intentFilter); mNetworkBroadcastReceiver = new NativeNetworkBroadcastReceiver(); IntentFilter netIntentFilter = new IntentFilter(); netIntentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mNetworkBroadcastReceiver, netIntentFilter); Connection .addConnectionCreationListener(new ConnectionCreationListener() { @Override public void connectionCreated(Connection connection) { // TODO Auto-generated method stub initService(connection); } }); getHandler().removeMessages(MSG_NETWORK_CONNECTED); getHandler().sendEmptyMessageDelayed(MSG_NETWORK_CONNECTED, 1300); }