Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. var smackConnection: AbstractXMPPConnection? = null fun attemptLogin(userName: String, password: String): Single<AbstractXMPPConnection> {
  2.  
  3.     return Single.create<AbstractXMPPConnection> { source ->
  4.  
  5. configBuilder = getBaseConfig(userName, password)<strong>
  6.         val hostAddress: InetAddress = InetAddress.getByName(hostName)
  7.         val configuration = configBuilder.setHostAddress(hostAddress).build()
  8.         val connection = XMPPTCPConnection(configuration)
  9.  
  10. connection.connect()
  11.         if (connection.isConnected) {
  12.             Log.v(LOG_TAG, "-> attemptLogin -> connected")
  13.         } else {
  14.             source.onError(Throwable("Unable to connect"))
  15.         }
  16.  
  17.         connection.login()
  18.         if (connection.isAuthenticated) {
  19.             Log.v(LOG_TAG, "-> attemptLogin -> ${configuration.username} authenticated")
  20.         } else {
  21.             source.onError(Throwable("Unable to login"))
  22.         }
  23.  
  24.         //send the available status that is "online" over the server
  25.         connection.sendStanza(Presence(Presence.Type.available))
  26.         this. smackConnection = connection
  27.  
  28.         val roster = Roster.getInstanceFor(connection)        
  29. //accept_all means anyone can initiate chat and message
  30.         roster.subscriptionMode = Roster.SubscriptionMode.accept_all
  31.  
  32.         source.onSuccess(connection)
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement