Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Sources/Ultravox/Ultravox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import WebKit

// MARK: - SDK Version

private let sdkVersion: String = "0.0.7"
private let sdkVersion: String = "0.0.8"

// MARK: - Enums

Expand Down Expand Up @@ -270,10 +270,14 @@ public final class UltravoxSession: NSObject {
public func sendData(data: [String: Any]) async {
guard data["type"] != nil else { return }
guard let jsonData = try? JSONSerialization.data(withJSONObject: data, options: []) else { return }
do {
try await room?.localParticipant.publish(data: jsonData, options: DataPublishOptions(reliable: true))
} catch {
print("Error publishing data: \(error)")
if jsonData.count > 1024 {
socket?.send(data: jsonData)
} else {
do {
try await room?.localParticipant.publish(data: jsonData, options: DataPublishOptions(reliable: true))
} catch {
print("Error publishing data: \(error)")
}
}
}

Expand Down Expand Up @@ -452,4 +456,12 @@ private final class WebSocketConnection: NSObject, Sendable {
return nil
}
}

func send(data: Data) {
webSocketTask.send(.data(data)) { error in
if let error {
print("Failed to send data message: \(error)")
}
}
}
}