From dec2179f5dbf44d29269b0592617459a5dd32e08 Mon Sep 17 00:00:00 2001 From: Anthony Drendel Date: Sat, 31 Oct 2020 23:49:58 +0100 Subject: [PATCH] Add Socket.maximumMessageSize (#21) --- Package.resolved | 12 ++++++------ Package.swift | 4 ++-- Sources/Phoenix/Socket.swift | 9 ++++++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Package.resolved b/Package.resolved index f8dcdca2..a32ac01a 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/shareup/synchronized.git", "state": { "branch": null, - "revision": "5f3312cf35cde0ddd1196ca9c44190b1859426e0", - "version": "2.0.0" + "revision": "e8bbab660d61b4f78fd94c3640f1a03886c326ea", + "version": "2.1.0" } }, { @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/shareup/websocket-apple.git", "state": { "branch": null, - "revision": "98375bdc219e6d86d9ad7bbbc92171321aac4fe5", - "version": "2.0.3" + "revision": "b15957b59becc92f80bdab1abc5454fd8d608fd8", + "version": "2.1.0" } }, { @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/shareup/websocket-protocol.git", "state": { "branch": null, - "revision": "87f7173b21dc877e04211ef25bf1327d3c3b5982", - "version": "2.1.1" + "revision": "e3cc3105c75d070e0e6cd82568036b67a103ff5a", + "version": "2.2.0" } } ] diff --git a/Package.swift b/Package.swift index 2850aebd..b597d488 100644 --- a/Package.swift +++ b/Package.swift @@ -11,8 +11,8 @@ let package = Package( targets: ["Phoenix"]), ], dependencies: [ - .package(name: "Synchronized", url: "https://github.com/shareup/synchronized.git", from: "2.0.0"), - .package(name: "WebSocket", url: "https://github.com/shareup/websocket-apple.git", from: "2.0.0"), + .package(name: "Synchronized", url: "https://github.com/shareup/synchronized.git", from: "2.1.0"), + .package(name: "WebSocket", url: "https://github.com/shareup/websocket-apple.git", from: "2.1.0"), ], targets: [ .target( diff --git a/Sources/Phoenix/Socket.swift b/Sources/Phoenix/Socket.swift index 215c5d68..4c941a86 100644 --- a/Sources/Phoenix/Socket.swift +++ b/Sources/Phoenix/Socket.swift @@ -50,6 +50,12 @@ public final class Socket { public static let defaultHeartbeatInterval: DispatchTimeInterval = .seconds(30) public let heartbeatInterval: DispatchTimeInterval + public var maximumMessageSize: Int = 1024 * 1024 { + didSet { sync { + state.webSocket?.maximumMessageSize = maximumMessageSize + } } + } + // https://github.com/phoenixframework/phoenix/blob/ce8ec7eac3f1966926fd9d121d5a7d73ee35f897/assets/js/phoenix.js#L790 public var reconnectTimeInterval: ReconnectTimeInterval = { (attempt: Int) -> DispatchTimeInterval in let milliseconds = [10, 50, 100, 150, 200, 250, 500, 1000, 2000, 5000] @@ -182,6 +188,7 @@ extension Socket: ConnectablePublisher { switch state { case .closed: let ws = WebSocket(url: url) + ws.maximumMessageSize = maximumMessageSize self.state = .connecting(ws) ws.connect() @@ -502,7 +509,7 @@ extension Socket { flushAsync() } } - case .data: + case .binary: assertionFailure("We are not currently expecting any data frames from the server") case .text(let string): do {