Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var smackConnection: AbstractXMPPConnection? = null fun attemptLogin(userName: String, password: String): Single<AbstractXMPPConnection> {
- return Single.create<AbstractXMPPConnection> { source ->
- configBuilder = getBaseConfig(userName, password)<strong>
- val hostAddress: InetAddress = InetAddress.getByName(hostName)
- val configuration = configBuilder.setHostAddress(hostAddress).build()
- val connection = XMPPTCPConnection(configuration)
- connection.connect()
- if (connection.isConnected) {
- Log.v(LOG_TAG, "-> attemptLogin -> connected")
- } else {
- source.onError(Throwable("Unable to connect"))
- }
- connection.login()
- if (connection.isAuthenticated) {
- Log.v(LOG_TAG, "-> attemptLogin -> ${configuration.username} authenticated")
- } else {
- source.onError(Throwable("Unable to login"))
- }
- //send the available status that is "online" over the server
- connection.sendStanza(Presence(Presence.Type.available))
- this. smackConnection = connection
- val roster = Roster.getInstanceFor(connection)
- //accept_all means anyone can initiate chat and message
- roster.subscriptionMode = Roster.SubscriptionMode.accept_all
- source.onSuccess(connection)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement