Skip to content

Latest commit

 

History

History
102 lines (74 loc) · 2.7 KB

File metadata and controls

102 lines (74 loc) · 2.7 KB

Quick Start

Back to README

Install the package first: see Installation.

Contents

1. Configure PoolChat

Set up logging and storage before using any PoolChat services:

import PoolChat

// Inject your logger (optional, falls back to os.Logger)
PoolChatConfiguration.logger = MyAppLogger()

// Inject your encrypted storage provider (required for history persistence)
PoolChatConfiguration.storageProvider = MySecureStorage()

// Security settings (defaults are recommended)
PoolChatConfiguration.rejectUnencryptedMessages = true
PoolChatConfiguration.enableHistorySync = true

Every knob is documented in Configuration.

2. Key Exchange

When a peer connects, exchange public keys to establish encryption:

let encryptionService = ChatEncryptionService.shared

// Get your public key to send to the peer
let myPublicKey = encryptionService.publicKey

// When you receive a peer's public key, perform key exchange
let success = encryptionService.performKeyExchange(
    peerPublicKeyData: peerPublicKeyData,
    peerID: remotePeerID
)

if success {
    print("E2E encryption established with \(remotePeerID)")
}

First contact records the peer identity under TOFU. See Security: Trust-On-First-Use.

3. Encrypt and Send a Message

// Create a message
let message = RichChatMessage.textMessage(
    from: localPeerID,
    senderName: "Alice",
    text: "Hello from PoolChat!",
    isFromLocalUser: true
)

// Serialize the payload
let payload = RichChatPayload(from: message)
let payloadData = try JSONEncoder().encode(payload)

// Encrypt for a specific peer
if let encrypted = encryptionService.encrypt(payloadData, for: targetPeerID) {
    let envelope = EncryptedChatPayload(
        encryptedData: encrypted,
        senderPeerID: localPeerID,
        isPrivateChat: false,
        targetPeerID: nil,
        messageType: .chatMessage
    )
    // Send via ConnectionPool
}

4. Use the Built-in SwiftUI View

For a complete chat UI out of the box:

import PoolChat
import ConnectionPool

struct ChatScreen: View {
    @StateObject private var viewModel = PoolChatViewModel()

    var body: some View {
        PoolChatView(viewModel: viewModel)
    }
}

The view includes message bubbles, emoji picker, voice recording controls, image sending, poll creation, reactions, reply threading, @mention autocomplete, and voice/video calling flows, all with cross-platform support.