fluuxio/xmpp
Fluux XMPP is a Chat SDK in Swift for iOS, MacOS and Linux. It implements the XMPP protocol, which is an IETF standard.
Building Fluux XMPP library
We design the build system with the following principles:
- The goal is to be multiplatform (iOS, MacOS, Linux), while making use of newest iOS and MacOS features.
- We want to be flexible and easy to integrate with all major dependency management tools (SwiftPM, CocoaPods, Carthage). SwiftPM is
however our primary target.
As such, we build the platform differently based on the target / build system:
- With Carthage and Cocoapods and SwiftPM on MacOS, we use Apple Network.framework and thus target iOS 12+ and MacOS 10.14+.
It means that for standard iOS ou MacOS build, there is no other dependencies. - With SwiftPM on Linux, we use Swift-NIO, as Network.framework is only available for Apple platforms.
This decision allows us to keep all build system very simple, while having a good platform reach.
Using Swift Package
Install homebrew dependencies
You need a libxml2 and a TLS implementation (i.e. libressl). You can install them with HomeBrew:
brew install libxml2
brew install libresslAdding Fluux XMPP as a dependency in your project
You can build the lib using Swift Package Manager, thanks to the provided Package.swift file.
You also need to properly set your build target to MacOS 10.12 explicitely, as, at the moment, Swift PM uses MacOS 10.10 as an hardcoded value for the deployment target (more on this here).
To integrate Fluux XMPP in your Swift PM project, you can add it as a dependency of your project in your Package.swift file. For example:
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "XMPPDemo",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/FluuxIO/XMPP.git", from: "0.0.2"),
],
targets: [
.target(
name: "XMPPDemo",
dependencies: ["XMPP"]),
.testTarget(
name: "XMPPDemoTests",
dependencies: ["XMPPDemo"]),
]
)You can modify your command-line executable main.swift to start an XMPP client. For example:
import Foundation
import XMPP
guard let jid = JID("mremond@localhost/XMPPDemo") else { print("Invalid JID"); exit(1) }
var xmppConfig = Config(jid: jid, password: "mypass", useTLS: true)
xmppConfig.allowInsecure = true
xmppConfig.host = "MacBook-Pro-de-Mickael.local"
xmppConfig.streamObserver = DefaultStreamObserver()
let client = XMPP(config: xmppConfig)
let semaphore = DispatchSemaphore(value: 0)
client.connect {
print("Disconnected !")
semaphore.signal()
}
_ = semaphore.wait(timeout: DispatchTime.distantFuture)To build the project, you can just use the standard build command:
swift buildYou can then run your console client:
.build/debug/XMPPDemoThe tests can be run with the command:
swift testWorking on Linux with Docker
You can use Docker official image to work on the Swift projet on Linux. You can also use Docker on MacOs to build the Linux version.
You can retrieve the Swift Docker image with the following command:
docker pull swiftYou can then build open a Linux shell inside the container:
docker run -itv $(pwd):/code --name swiftcode -w /code swift /bin/bashYou will then need to install libxml2-dev and libssl-dev dev packages in the container with:
apt-get update
apt-get install libxml2-dev libssl-devFrom the Docker shell, you can build the code with:
swift buildTo run the test on Linux, you need to explicitely enable test discovery (See Swift Test Discovery):
swift test --enable-test-discoveryTLS support
At the moment the library only support standard TLS connection, not STARTTLS. Apple Networking library does not support (yet ?) switching encryption after the connection has been established, because they are worried by possible security issues around STARTTLS implementations.
That said, XMPP support TLS on port 5223. It is called "legacy" SSL because use of port 5223 has been deprecated by the XMPP Standards Foundation a while back. That said, modern XMPP servers like ejabberd support state of the art TLS on port 5223. To use TLS at the moment, it is perfectly fine to use TLS on port 5223.
Package Metadata
Repository: fluuxio/xmpp
Default branch: master
README: README.md