Skip to content

Commit

Permalink
Add Socket.maximumMessageSize (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
atdrendel authored Oct 31, 2020
1 parent 606926f commit dec2179
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
"repositoryURL": "https://github.com/shareup/synchronized.git",
"state": {
"branch": null,
"revision": "5f3312cf35cde0ddd1196ca9c44190b1859426e0",
"version": "2.0.0"
"revision": "e8bbab660d61b4f78fd94c3640f1a03886c326ea",
"version": "2.1.0"
}
},
{
"package": "WebSocket",
"repositoryURL": "https://github.com/shareup/websocket-apple.git",
"state": {
"branch": null,
"revision": "98375bdc219e6d86d9ad7bbbc92171321aac4fe5",
"version": "2.0.3"
"revision": "b15957b59becc92f80bdab1abc5454fd8d608fd8",
"version": "2.1.0"
}
},
{
"package": "WebSocketProtocol",
"repositoryURL": "https://github.com/shareup/websocket-protocol.git",
"state": {
"branch": null,
"revision": "87f7173b21dc877e04211ef25bf1327d3c3b5982",
"version": "2.1.1"
"revision": "e3cc3105c75d070e0e6cd82568036b67a103ff5a",
"version": "2.2.0"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion Sources/Phoenix/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit dec2179

Please sign in to comment.