ART Swift ADK

Swift Platform License

Swift SDK for ART – A Realtime Tech Communication, a realtime messaging platform providing WebSocket-based channels, presence tracking, end-to-end encrypted messaging, and CRDT-backed shared objects.


Features

  • WebSocket connection management (connect, pause, resume, auto-reconnect)
  • Channel subscriptions (default, targeted, group, encrypted, CRDT)
  • Push messages with structured payloads
  • Event-based message listening (emitter.on)
  • Real-time presence tracking
  • End-to-end encryption support
  • Interceptors for message processing
  • Shared objects using CRDT

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/aiotrixdev/art-swift-adk.git", from: "1.0.0")
]

Or in Xcode:

File → Add Packages → Paste repository URL

Configuration

1. Create credentials

Store your ART credentials securely:

let creds = CredentialStore(
    environment:  "YOUR_ENV",
    projectKey:   "YOUR_PROJECT_KEY",
    orgTitle:     "YOUR_ORG",
    clientID:     "CLIENT_ID",
    clientSecret: "CLIENT_SECRET"
)

2. Get a user passcode

ART uses a short-lived passcode for authentication:

func fetchPasscode(creds: CredentialStore) async throws -> String {
    let url = URL(string: "https://dev.arealtimetech.com/ws/v1/connect/passcode")!
    
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    
    request.addValue(creds.clientID, forHTTPHeaderField: "Client-Id")
    request.addValue(creds.clientSecret, forHTTPHeaderField: "Client-Secret")
    request.addValue(creds.orgTitle, forHTTPHeaderField: "X-Org")
    request.addValue(creds.environment, forHTTPHeaderField: "Environment")
    request.addValue(creds.projectKey, forHTTPHeaderField: "ProjectKey")
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    
    let body: [String: Any] = [
        "username": "john_doe",
        "first_name": "John",
        "last_name": "Doe"
    ]
    
    request.httpBody = try JSONSerialization.data(withJSONObject: body)
    
    let (data, _) = try await URLSession.shared.data(for: request)
    let json = try JSONSerialization.jsonObject(with: data) as? [String: Any]
    let dataObj = json?["data"] as? [String: Any]
    
    return dataObj?["passcode"] as? String ?? ""
}

Quick Start

import ArtAdk

let passcode = try await fetchPasscode(creds: creds)

let adk = Adk(config: AdkConfig(
    uri: "ws.arealtimetech.com",
    authToken: passcode,
    getCredentials: { creds }
))

adk.on("connection") { data in
    if let conn = data as? ConnectionDetail {
        print("Connected → \(conn.connectionId)")
    }
}

adk.on("close") { reason in
    print("Closed:", reason)
}

try await adk.connect()

let sub = try await adk.subscribe(channel: "room-42")

sub.emitter.on("message") { data in
    print("Received:", data)
}

try await sub.push(
    event: "message",
    data: ["text": "Hello ART!"]
)

Connecting

try await adk.connect()

Safe usage:

do {
    try await adk.connect()
} finally {
    await adk.disconnect()
}

Check state:

adk.getState() // connected | retrying | paused | stopped

Subscribing to a Channel

let sub = try await adk.subscribe(channel: "room-42")

if let live = sub as? LiveObjSubscription {
    // CRDT channel
}

Unsubscribe:

await sub.unsubscribe()

Pushing Messages

try await sub.push(
    event: "message",
    data: ["text": "Hello"]
)

Targeted messaging:

try await sub.push(
    event: "message",
    data: ["text": "Hi Bob"],
    options: PushConfig(to: ["bob"])
)

Receiving Messages

sub.emitter.on("message") { data in
    print("Got:", data)
}

Presence

let cancel = try await sub.fetchPresence { users in
    print("Online:", users)
}

// later
await cancel()

Encrypted Channels

try await adk.generateKeyPair()

let secure = try await adk.subscribe(channel: "SECURE_CHANNEL")

try await secure.push(
    event: "message",
    data: ["text": "Private"],
    options: PushConfig(to: ["bob"])
)

secure.emitter.on("message") { data in
    print("Decrypted:", data)
}

Shared Object Channels (CRDT)

let sub = try await adk.subscribe(channel: "CRDT_CHANNEL")

if let live = sub as? LiveObjSubscription {
    
    // Write
    live.state()["document"]["title"].set("My Doc")
    await live.flush()
    
    // Read
    let snapshot = await live.query(path: "document").execute()
    print(snapshot)
    
    // Listen
    let dispose = await live.query(path: "document").listen { data in
        print("Updated:", data)
    }
    
    dispose()
}

Array Operations

let items = live.state()["items"]

items.push("alpha")
items.unshift("zero")
items.pop()
items.removeAt(2)
items.splice(start: 1, deleteCount: 1, insert: ["x"])

await live.flush()

Interceptors

try await adk.intercept(interceptor: "filter") { payload, resolve, reject in
    
    if let text = payload["text"] as? String,
       text.contains("anyword") {
        reject("Blocked")
        return
    }
    
    resolve(payload)
}

Connection Lifecycle

adk.on("connection") { data in
    print("Connected")
}

adk.on("close") { _ in
    print("Closed")
}

adk.pause()
await adk.resume()
await adk.disconnect()

Documentation

Full documentation is available at: https://docs.arealtimetech.com/docs/adk/

Topic Link
Overview ADK Overview
Installation Swift Installation
Publish & Subscribe Pub/Sub Docs
Connection Management Connection Docs
User Presence Presence Docs
Encrypted Channels Encryption Docs
Shared Object Channels Shared Object Docs
Interceptors Interceptor Docs

License

Released under the MIT License.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sun May 17 2026 11:54:59 GMT-0900 (Hawaii-Aleutian Daylight Time)