Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
name: swift
scm: github.com/pubnub/swift
version: "5.0.1"
version: "5.1.0"
schema: 1
changelog:
- date: 2022-02-02
version: 5.1.0
changes:
- type: feature
text: "Add affected channels and groups under `affected` resources list."
- date: 2022-01-19
version: 5.0.1
changes:
Expand Down Expand Up @@ -439,7 +444,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: PubNub
location: https://github.com/pubnub/swift/archive/refs/tags/5.0.1.zip
location: https://github.com/pubnub/swift/archive/refs/tags/5.1.0.zip
supported-platforms:
supported-operating-systems:
macOS:
Expand Down
10 changes: 10 additions & 0 deletions Examples/Sources/MasterDetailTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ class MasterDetailTableViewController: UITableViewController {
print("A file was uplaoded \(file)")
case let .subscribeError(error):
print("The following error was generated during subscription \(error.localizedDescription)")
error.affected.forEach {
switch $0 {
case let .channels(affectedChannels):
print("Affected channels: \(affectedChannels)")
case let .channelGroups(affectedChannelGroups):
print("Affected channel groups: \(affectedChannelGroups)")
default:
break
}
}
print("If `disconnectedUnexpectedly` also occurred then subscription has stopped, and needs to be restarted")
}
}
Expand Down
4 changes: 2 additions & 2 deletions PubNub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MARKETING_VERSION = 5.0.1;
MARKETING_VERSION = 5.1.0;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down Expand Up @@ -2539,7 +2539,7 @@
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MARKETING_VERSION = 5.0.1;
MARKETING_VERSION = 5.1.0;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down
2 changes: 1 addition & 1 deletion PubNubSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PubNubSwift'
s.version = '5.0.1'
s.version = '5.1.0'
s.homepage = 'https://github.com/pubnub/swift'
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
s.authors = { 'PubNub, Inc.' => 'support@pubnub.com' }
Expand Down
12 changes: 11 additions & 1 deletion Sources/PubNub/Errors/PubNubError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public struct PubNubError: Error {
case response(HTTPURLResponse)
case json(AnyJSON)
case subscribe(SubscribeCursor)
case channels([String])
case channelGroups([String])
}

/// The PubNubError specific Domain that groups together the different Reasons
Expand Down Expand Up @@ -255,7 +257,9 @@ public struct PubNubError: Error {
router: HTTPRouter?,
request: URLRequest?,
response: HTTPURLResponse?,
additional details: [ErrorDetail]? = nil
additional details: [ErrorDetail]? = nil,
affectedChannels channels: [String]? = nil,
affectedChannelGroups channelGroups: [String]? = nil
) {
var reasonOrResponse = reason

Expand All @@ -268,6 +272,12 @@ public struct PubNubError: Error {
reasonOrResponse = reasonOrResponse ?? Reason(rawValue: response.statusCode)
affectedValues.append(.response(response))
}
if let channels = channels {
affectedValues.append(.channels(channels))
}
if let channelGroups = channelGroups {
affectedValues.append(.channelGroups(channelGroups))
}

self.init(reasonOrResponse ?? .unrecognizedStatusCode,
router: router,
Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/Helpers/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct Constant {
}()

static let pubnubSwiftSDKVersion: String = {
"5.0.1"
"5.1.0"
}()

static let appBundleId: String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,18 @@ struct GenericServicePayloadResponse: Codable, Hashable {
let status: Int
let error: Bool
let channels: [String: [String]]
let affectedChannels: [String]?
let affectedChannelGroups: [String]?

init(
message: EndpointResponseMessage? = nil,
details: [ErrorDetail] = [],
service: String? = nil,
status: Int? = nil,
error: Bool = false,
channels: [String: [String]] = [:]
channels: [String: [String]] = [:],
affectedChannels: [String]? = nil,
affectedChannelGroups: [String]? = nil
) {
if !error, HTTPURLResponse.successfulStatusCodes.contains(status ?? 0) {
self.message = .acknowledge
Expand All @@ -245,6 +249,8 @@ struct GenericServicePayloadResponse: Codable, Hashable {
self.status = status ?? -1
self.error = error
self.channels = channels
self.affectedChannels = affectedChannels
self.affectedChannelGroups = affectedChannelGroups
}

enum CodingKeys: String, CodingKey {
Expand All @@ -254,6 +260,7 @@ struct GenericServicePayloadResponse: Codable, Hashable {
case status
case error
case channels
case payload
}

init(from decoder: Decoder) throws {
Expand Down Expand Up @@ -289,13 +296,18 @@ struct GenericServicePayloadResponse: Codable, Hashable {

let status = try container.decodeIfPresent(Int.self, forKey: .status)
let channels = try container.decodeIfPresent([String: [String]].self, forKey: .channels) ?? [:]
let payload = try container.decodeIfPresent([String: [String]].self, forKey: .payload) ?? [:]
let affectedChannels: [String]? = payload["channels"]
let affectedChannelGroups: [String]? = payload["channel-groups"]

self.init(message: message ?? error,
details: details,
service: service,
status: status,
error: isError,
channels: channels)
channels: channels,
affectedChannels: affectedChannels,
affectedChannelGroups: affectedChannelGroups)
}

func encode(to encoder: Encoder) throws {
Expand Down
4 changes: 3 additions & 1 deletion Sources/PubNub/Networking/Response/ResponseOperator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ extension ResponseDecoder {

return PubNubError(reason: generalErrorPayload?.pubnubReason,
router: router, request: request, response: response,
additional: generalErrorPayload?.details)
additional: generalErrorPayload?.details,
affectedChannels: generalErrorPayload?.affectedChannels,
affectedChannelGroups: generalErrorPayload?.affectedChannelGroups)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/Subscription/SubscriptionSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SubscriptionSession {

public let uuid = UUID()
let longPollingSession: SessionReplaceable
internal(set) var configuration: SubscriptionConfiguration
var configuration: SubscriptionConfiguration
let sessionStream: SessionListener

/// PSV2 feature to subscribe with a custom filter expression.
Expand Down