CheckInBandRegistration.scala

  1. /**
  2.  *
  3.  * Copyright 2018 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.igniterealtime.smack.scala.util

  18. import scala.language.postfixOps

  19. import org.jxmpp.jid.DomainBareJid
  20. import org.jxmpp.jid.impl.JidCreate

  21. import org.jivesoftware.smack.tcp.XMPPTCPConnection
  22. import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration

  23. import org.jivesoftware.smackx.iqregister.AccountManager

  24. object CheckInBandRegistration {

  25.   def supportsIbr(xmppServiceString: String) : Boolean = {
  26.     val xmppServiceAddress = JidCreate domainBareFrom(xmppServiceString)

  27.     val config = XMPPTCPConnectionConfiguration.builder()
  28.                   .setXmppDomain(xmppServiceAddress)
  29.                   .build();

  30.     supportsIbr(config)
  31.   }

  32.   def supportsIbr(connectionConfiguration: XMPPTCPConnectionConfiguration) : Boolean = {
  33.     val connection = new XMPPTCPConnection(connectionConfiguration)
  34.     connection.connect
  35.     try {
  36.       AccountManager.getInstance(connection).supportsAccountCreation
  37.     } finally {
  38.       connection disconnect
  39.     }
  40.   }

  41. }