Repository navigation
[Split 2/N] Add the AblyPubSubDevice product and its factory #2265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,8 @@ let package = Package( | |
| dependencies: [ | ||
| // `package:` is the dependency's identity, which for a path | ||
| // dependency is the directory name, not the manifest's `name`. | ||
| .product(name: "AblyPubSubCore", package: "ably-cocoa") | ||
| .product(name: "AblyPubSubCore", package: "ably-cocoa"), | ||
| .product(name: "AblyPubSubDevice", package: "ably-cocoa") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MINOR] Example target isn't device-only
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also resolved by #2285, which removes the core product entirely: |
||
| ], | ||
| swiftSettings: [ | ||
| .unsafeFlags(["-warnings-as-errors"]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,9 @@ | ||
| import Ably | ||
| import AblyPubSubDevice | ||
|
|
||
| // `import AblyPubSubDevice` alone reaches the core's types too. | ||
| let options = ARTClientOptions() | ||
| options.autoConnect = false | ||
| options.key = "xxxx:xxxx" | ||
| options.clientId = "me" | ||
|
|
||
| let _ = PubSubDevice.createClient(options: options) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,18 @@ | ||
| import XCTest | ||
| import Ably | ||
| import AblyPubSubDevice | ||
|
|
||
| final class SPMTests: XCTestCase { | ||
| func ablyInitTest() { | ||
| let clientOptions = ARTClientOptions() | ||
| let _ = ARTRest(options: clientOptions) | ||
| let _ = ARTRealtime(options: clientOptions) | ||
| } | ||
|
|
||
| func pubSubDeviceInitTest() { | ||
| let clientOptions = ARTClientOptions() | ||
| let _ = PubSubDevice.createClient(options: clientOptions) | ||
| let _ = PubSubDevice.createClient(key: "xxxx:xxxx") | ||
| let _ = PubSubDevice.createClient(token: "xxxx") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,12 @@ let package = Package( | |
| name: "AblyPubSubCore", | ||
| targets: ["Ably"] | ||
| ), | ||
| // The entry point for apps: creates clients that declare they are | ||
| // running on an end user's device. | ||
| .library( | ||
| name: "AblyPubSubDevice", | ||
| targets: ["AblyPubSubDevice"] | ||
| ), | ||
| .library( | ||
| name: "AblyLiveObjects", | ||
| targets: ["AblyLiveObjects"] | ||
|
|
@@ -84,6 +90,16 @@ let package = Package( | |
| name: "_AblyPluginSupportPrivate", | ||
| path: "_AblyPluginSupportPrivate" | ||
| ), | ||
| // Creates clients that declare they are running on an end user's | ||
| // device, by stamping the agent entry Ably classifies on. | ||
| .target( | ||
| name: "AblyPubSubDevice", | ||
| dependencies: [ | ||
| .target(name: "Ably"), | ||
| ], | ||
| path: "PubSubDevice", | ||
| publicHeadersPath: "include" | ||
| ), | ||
| // The core SDK. Vended as the AblyPubSubCore product; its module is | ||
| // named `Ably`. | ||
| .target( | ||
|
|
@@ -120,6 +136,7 @@ let package = Package( | |
| name: "AblyTests", | ||
| dependencies: [ | ||
| .byName(name: "Ably"), | ||
| .target(name: "AblyPubSubDevice"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MINOR] No separate
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentional — your own reasoning is the reason. The helpers these tests need ( It paid off again in #2291: the plugins test reuses |
||
| .byName(name: "AblyTesting"), | ||
| .byName(name: "AblyTestingObjC"), | ||
| .product(name: "Nimble", package: "nimble"), | ||
|
|
@@ -167,6 +184,7 @@ let package = Package( | |
| name: "AblyTestsObjC", | ||
| dependencies: [ | ||
| .byName(name: "Ably"), | ||
| .target(name: "AblyPubSubDevice"), | ||
| .byName(name: "AblyTesting"), | ||
| .byName(name: "AblyTestingObjC"), | ||
| ], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #import <AblyPubSubDevice/ARTPubSubDevice.h> | ||
|
|
||
| /** | ||
| * The agent entry that declares a client is running on an end user's device. | ||
| * | ||
| * Ably matches this exact string to classify a connection for monthly active user counting, so | ||
| * changing it reclassifies every client this package creates. It is sent without a version: it | ||
| * states which kind of runtime the client is on, and the SDK's own entry alongside it carries the | ||
| * version. | ||
| */ | ||
| static NSString *const ARTPubSubDeviceAgentName = @"ably-pubsub-device"; | ||
|
|
||
| @implementation ARTPubSubDevice | ||
|
|
||
| /// Returns a copy of `options` carrying the device declaration. | ||
| /// | ||
| /// The caller's options object and its `agents` dictionary are both left untouched. The | ||
| /// declaration is applied last, so it wins if the caller set an entry under the same name. | ||
| + (ARTClientOptions *)optionsDeclaringDevice:(ARTClientOptions *)options { | ||
| ARTClientOptions *const newOptions = [options copy]; | ||
|
|
||
| NSMutableDictionary<NSString *, NSString *> *const agents = options.agents ? [options.agents mutableCopy] : [NSMutableDictionary dictionary]; | ||
| agents[ARTPubSubDeviceAgentName] = ARTClientInformationAgentNotVersioned; | ||
| newOptions.agents = agents; | ||
|
|
||
| return newOptions; | ||
| } | ||
|
|
||
| + (ARTRealtime *)createClientWithOptions:(ARTClientOptions *)options { | ||
| return [[ARTRealtime alloc] initWithOptions:[self optionsDeclaringDevice:options]]; | ||
| } | ||
|
|
||
| + (ARTRealtime *)createClientWithKey:(NSString *)key { | ||
| return [self createClientWithOptions:[[ARTClientOptions alloc] initWithKey:key]]; | ||
| } | ||
|
|
||
| + (ARTRealtime *)createClientWithToken:(NSString *)token { | ||
| return [self createClientWithOptions:[[ARTClientOptions alloc] initWithToken:token]]; | ||
| } | ||
|
|
||
| @end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #import <Ably/Ably.h> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MINOR] Header layout: no
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overtaken rather than acknowledged: #2285 merges the core into the device target and lands on the layout you were comparing against — |
||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| /** | ||
| * Creates Pub/Sub clients for apps running on an end user's device. | ||
| * | ||
| * A client created here tells Ably that it is running on an end user's device. That declaration | ||
| * determines how the connection is counted: on an account billed by monthly active users, device | ||
| * traffic counts toward the total, the connection must carry a `clientId`, and that `clientId` is | ||
| * subject to a concurrency limit. | ||
| * | ||
| * The returned object is an `ARTRealtime` and behaves exactly as one built with | ||
| * `-[ARTRealtime initWithOptions:]`, so all of the Ably Pub/Sub documentation applies to it | ||
| * unchanged. | ||
| */ | ||
| NS_SWIFT_NAME(PubSubDevice) | ||
| @interface ARTPubSubDevice : NSObject | ||
|
|
||
| - (instancetype)init NS_UNAVAILABLE; | ||
|
|
||
| /** | ||
| * Creates a client with the given options. | ||
| * | ||
| * The options are not modified; any `agents` entries they carry are preserved alongside the | ||
| * device declaration. | ||
| * | ||
| * @param options The client options. Set `clientId` on them, or use token authentication that | ||
| * supplies one. | ||
| * | ||
| * @return A realtime client that declares it is running on an end user's device. | ||
| */ | ||
| + (ARTRealtime *)createClientWithOptions:(ARTClientOptions *)options NS_SWIFT_NAME(createClient(options:)); | ||
|
|
||
| /** | ||
| * Creates a client that authenticates with an API key. | ||
| * | ||
| * Prefer token authentication in code that ships to a device; an API key embedded in an app is | ||
| * readable by anyone who has the app. | ||
| * | ||
| * @param key A full Ably API key. | ||
| * | ||
| * @return A realtime client that declares it is running on an end user's device. | ||
| */ | ||
| + (ARTRealtime *)createClientWithKey:(NSString *)key NS_SWIFT_NAME(createClient(key:)); | ||
|
|
||
| /** | ||
| * Creates a client that authenticates with an existing token. | ||
| * | ||
| * @param token An Ably authentication token. | ||
| * | ||
| * @return A realtime client that declares it is running on an end user's device. | ||
| */ | ||
| + (ARTRealtime *)createClientWithToken:(NSString *)token NS_SWIFT_NAME(createClient(token:)); | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MINOR] Release-notes bullet later in this file omits
AblyPubSubDeviceFinding: This section now correctly establishes
AblyPubSubDeviceas SPM-only, but the Versioning section's release-notes bullet (line 191, just outside this diff) still reads "A release whose only change is to LiveObjects is a no-op for them" — naming only LiveObjects when explaining what CocoaPods/Carthage consumers don't receive.Why it matters: With this PR, the pod/Carthage no-op reasoning applies equally to
AblyPubSubDevice: a release whose only change is to the device product delivers nothing to those channels either. As written, the bullet could lead a release author to write inaccurate release notes for such a release. (This echoes an outstanding CodeRabbit nit.)Suggested action: Extend the line-191 bullet to also name
AblyPubSubDevice, e.g. "A release whose only change is toAblyPubSubDeviceor LiveObjects is a no-op for them".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale now — that bullet is gone. #2282 drops CocoaPods and Carthage from 2.x, so
CONTRIBUTING.mdno longer reasons about what those channels do or do not receive; the Distribution section says they stay on the 1.x line. Nothing left to extend.