Skip to content

Commit

Permalink
StompClient: Unzip compressed websocket messages (#109)
Browse files Browse the repository at this point in the history
* Unzip compressed websocket messages

* Add warning for failed decompression
  • Loading branch information
anian03 authored Dec 28, 2024
1 parent 75edd1f commit 23fa0aa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
26 changes: 13 additions & 13 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"version" : "1.8.2"
}
},
{
"identity" : "gzipswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/1024jp/GzipSwift.git",
"state" : {
"revision" : "56bf51fdd2fe4b2cf254b2cf34aede3d7caccc6c",
"version" : "6.1.0"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -50,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ashleymills/Reachability.swift",
"state" : {
"revision" : "98e968e7b6c1318fb61df23e347bc319761e8acb",
"version" : "5.0.0"
"revision" : "21d1dc412cfecbe6e34f1f4c4eb88d3f912654a6",
"version" : "5.2.4"
}
},
{
Expand All @@ -63,15 +72,6 @@
"version" : "0.35.0"
}
},
{
"identity" : "starscream",
"kind" : "remoteSourceControl",
"location" : "https://github.com/daltoniam/Starscream.git",
"state" : {
"revision" : "df8d82047f6654d8e4b655d1b1525c64e1059d21",
"version" : "4.0.4"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Romixery/SwiftStomp.git",
"state" : {
"revision" : "99dcfa7f428485b92de2359c9df9c778fd2d5599",
"version" : "1.1.1"
"revision" : "f25926d2ab67ec0391de9a706cf71dfb08d36bbc",
"version" : "1.2.1"
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let package = Package(
.package(url: "https://github.com/Romixery/SwiftStomp.git", .upToNextMinor(from: "1.2.1")),
.package(url: "https://github.com/realm/SwiftLint.git", .upToNextMinor(from: "0.55.0")),
.package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver.git", .upToNextMajor(from: "1.9.0")),
.package(url: "https://github.com/1024jp/GzipSwift.git", .upToNextMajor(from: "6.1.0")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -77,7 +78,8 @@ let package = Package(
dependencies: [
"Common",
"SwiftStomp",
"UserStore"
"UserStore",
.product(name: "Gzip", package: "GzipSwift")
],
plugins: [
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")
Expand Down
12 changes: 11 additions & 1 deletion Sources/APIClient/StompClient/ArtemisStompClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import Gzip
import SwiftStomp
import UserStore
import Common
Expand Down Expand Up @@ -125,7 +126,16 @@ extension ArtemisStompClient: SwiftStompDelegate {
public func onMessageReceived(swiftStomp: SwiftStomp, message: Any?, messageId: String, destination: String, headers: [String: String]) {
log.debug("Stomp: MessageReceived")
let continuation = continuations[destination]
continuation?.yield(message)

if headers["compressed"] == "true" {
if let unzipped = try? (message as? Data)?.gunzipped() {
continuation?.yield(unzipped)
} else {
log.warning("Stomp: Failed to gunzip compressed message")
}
} else {
continuation?.yield(message)
}
}

public func onReceipt(swiftStomp: SwiftStomp, receiptId: String) {
Expand Down

0 comments on commit 23fa0aa

Please sign in to comment.