Skip to content

Commit f6330ac

Browse files
authored
Switched context header X-Parse-Context to X-Parse-Cloud-Context (#170)
* Switched context header X-Parse-Context to X-Parse-Cloud-Context to match server * change min version in readme * nit * Update flaky LiveQuery test case * Improve LiveQuery playgrounds and test cases * Make ParseError CustomDebugStringConvertible * Use web socket cancel codes when closing * setup autoversioning WIP * working version update * use actions tag for framework build release number * make all dummy versions 1.8.3 * update ParseConstants.swift manually * Replace socket task instead of nil * nit actions release doc * nit * Fix ParseLiveQueryCombineTests * move update_build to scripts folder * update cocoapods script in ci.yml * fix jazzy docs to use tag for release number * Add more details to error * Improve error descriptions. * nits
1 parent 2e9b772 commit f6330ac

File tree

16 files changed

+130
-98
lines changed

16 files changed

+130
-98
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,18 @@ jobs:
128128
bundle install
129129
- name: Create Jazzy Docs
130130
run: ./Scripts/jazzy.sh
131+
env:
132+
BUILD_VERSION: '1.8.3'
131133

132134
cocoapods:
133135
needs: xcode-build-watchos
134136
runs-on: macos-latest
135137
steps:
136138
- uses: actions/checkout@v2
139+
- name: Update Framework Version
140+
run: ./Scripts/update_build
141+
env:
142+
BUILD_VERSION: '1.8.3'
137143
- name: CocoaPods
138144
run: pod lib lint --allow-warnings
139145

.github/workflows/release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ jobs:
1010
runs-on: macos-latest
1111
steps:
1212
- uses: actions/checkout@v2
13+
- name: Get release version
14+
run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
15+
- name: Update Framework Version
16+
run: ./Scripts/update_build
17+
env:
18+
BUILD_VERSION: ${{ env.TAG }}
1319
- name: CocoaPods
1420
run: set -o pipefail && env NSUnbufferedIO=YES pod lib lint --allow-warnings --verbose
1521
- name: Deploy CocoaPods
@@ -33,8 +39,12 @@ jobs:
3339
run: |
3440
bundle config path vendor/bundle
3541
bundle install
42+
- name: Get release version
43+
run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
3644
- name: Create Jazzy Docs
3745
run: ./Scripts/jazzy.sh
46+
env:
47+
BUILD_VERSION: ${{ env.TAG }}
3848
- name: Deploy Jazzy Docs
3949
uses: peaceiris/actions-gh-pages@v3
4050
with:

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Parse-Swift Changelog
22

33
### main
4-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.3...main)
4+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.4...main)
55
* _Contributing to this repo? Add info about your change here to be included in the next release_
66

7+
### 1.8.4
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.3...1.8.4)
9+
710
__Fixes__
11+
- Switched context header X-Parse-Context to X-Parse-Cloud-Context to match server ([#170](https://github.com/parse-community/Parse-Swift/pull/170)), thanks to [Corey Baker](https://github.com/cbaker6).
812
- Fixed a bug in LiveQuery that prevented reconnecting after a connection was closed. Also added a sendPing method to LiveQuery ([#172](https://github.com/parse-community/Parse-Swift/pull/172)), thanks to [Corey Baker](https://github.com/cbaker6).
913

1014
### 1.8.3

ParseSwift.playground/Pages/11 - LiveQuery.xcplaygroundpage/Contents.swift

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ do {
157157
print(error)
158158
}
159159

160+
//: If you look at your server log, you will notice the client and server disconnnected.
161+
//: This is because there is no more LiveQuery subscriptions.
162+
160163
//: Ping the LiveQuery server. This should produce an error
161164
//: because LiveQuery is disconnected.
162165
ParseLiveQuery.client?.sendPing { error in
@@ -176,7 +179,7 @@ query2.fields("score")
176179
//: Subscribe to your new query.
177180
let subscription2 = query2.subscribeCallback!
178181

179-
//: As before, setup your subscription and event handlers.
182+
//: As before, setup your subscription, event, and unsubscribe handlers.
180183
subscription2.handleSubscribe { subscribedQuery, isNew in
181184

182185
//: You can check this subscription is for this query.
@@ -203,6 +206,10 @@ subscription2.handleEvent { _, event in
203206
}
204207
}
205208

209+
subscription2.handleUnsubscribe { query in
210+
print("Unsubscribed from \(query)")
211+
}
212+
206213
//: To close the current LiveQuery connection.
207214
ParseLiveQuery.client?.close()
208215

@@ -219,41 +226,15 @@ ParseLiveQuery.client?.sendPing { error in
219226
}
220227
}
221228

222-
//: Subscribe to your new query.
229+
//: Resubscribe to your previous query.
230+
//: Since we never unsubscribed you can use your previous handlers.
223231
let subscription3 = query2.subscribeCallback!
224232

225-
//: As before, setup your subscription and event handlers.
226-
subscription3.handleSubscribe { subscribedQuery, isNew in
227-
228-
//: You can check this subscription is for this query.
229-
if isNew {
230-
print("Successfully subscribed to new query \(subscribedQuery)")
231-
} else {
232-
print("Successfully updated subscription to new query \(subscribedQuery)")
233-
}
234-
}
235-
236-
subscription3.handleEvent { _, event in
237-
switch event {
238-
239-
case .entered(let object):
240-
print("Entered: \(object)")
241-
case .left(let object):
242-
print("Left: \(object)")
243-
case .created(let object):
244-
print("Created: \(object)")
245-
case .updated(let object):
246-
print("Updated: \(object)")
247-
case .deleted(let object):
248-
print("Deleted: \(object)")
249-
}
250-
}
251-
252-
//: Now lets subscribe to an additional query.
233+
//: Resubscribe to another previous query.
234+
//: This one needs new handlers.
253235
let subscription4 = query.subscribeCallback!
254236

255-
//: This is how you receive notifications about the success
256-
//: of your subscription.
237+
//: Need a new handler because we previously unsubscribed.
257238
subscription4.handleSubscribe { subscribedQuery, isNew in
258239

259240
//: You can check this subscription is for this query
@@ -264,7 +245,7 @@ subscription4.handleSubscribe { subscribedQuery, isNew in
264245
}
265246
}
266247

267-
//: This is how you register to receive notifications of events related to your LiveQuery.
248+
//: Need a new event handler because we previously unsubscribed.
268249
subscription4.handleEvent { _, event in
269250
switch event {
270251

@@ -281,8 +262,8 @@ subscription4.handleEvent { _, event in
281262
}
282263
}
283264

284-
//: Now we will will unsubscribe from one of the subsriptions, but maintain the connection.
285-
subscription3.handleUnsubscribe { query in
265+
//: Need a new unsubscribe handler because we previously unsubscribed.
266+
subscription4.handleUnsubscribe { query in
286267
print("Unsubscribed from \(query)")
287268
}
288269

@@ -302,5 +283,15 @@ ParseLiveQuery.client?.sendPing { error in
302283
}
303284
}
304285

286+
//: To unsubscribe from your your last query.
287+
do {
288+
try query.unsubscribe()
289+
} catch {
290+
print(error)
291+
}
292+
293+
//: If you look at your server log, you will notice the client and server disconnnected.
294+
//: This is because there is no more LiveQuery subscriptions.
295+
305296
PlaygroundPage.current.finishExecution()
306297
//: [Next](@next)

ParseSwift.podspec renamed to ParseSwift.podtemplate

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ParseSwift"
3-
s.version = "1.8.3"
3+
s.version = "[[VERSION]]"
44
s.summary = "Parse Pure Swift SDK"
55
s.homepage = "https://github.com/parse-community/Parse-Swift"
66
s.authors = {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import PackageDescription
4444
let package = Package(
4545
name: "YOUR_PROJECT_NAME",
4646
dependencies: [
47-
.package(url: "https://github.com/parse-community/Parse-Swift", from: "1.8.3"),
47+
.package(url: "https://github.com/parse-community/Parse-Swift", from: "1.8.4"),
4848
]
4949
)
5050
```

Scripts/jazzy.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
ver=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" ParseSwift-iOS/Info.plist`
21
bundle exec jazzy \
32
--clean \
43
--author "Parse Community" \
54
--author_url http://parseplatform.org \
65
--github_url https://github.com/parse-community/Parse-Swift \
76
--root-url http://parseplatform.org/Parse-Swift/api/ \
8-
--module-version 1.8.3 \
7+
--module-version ${BUILD_VERSION} \
98
--theme fullwidth \
109
--skip-undocumented \
1110
--output ./docs/api \

Scripts/update_build

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Prepare podspec update
4+
TEMPLATE_FILE_NAME="ParseSwift.podtemplate"
5+
OUT_FILE_NAME="ParseSwift.podspec"
6+
7+
# Load the template podspec and replace version
8+
TEMPLATE=$(cat "$TEMPLATE_FILE_NAME" | sed "s/\[\[VERSION\]\]/${BUILD_VERSION}/g")
9+
10+
echo "$TEMPLATE" > "$OUT_FILE_NAME"

Sources/ParseSwift/API/API.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public struct API {
201201
let context = AnyEncodable(context)
202202
if let encoded = try? ParseCoding.jsonEncoder().encode(context),
203203
let encodedString = String(data: encoded, encoding: .utf8) {
204-
headers["X-Parse-Context"] = encodedString
204+
headers["X-Parse-Cloud-Context"] = encodedString
205205
}
206206
}
207207
}

Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ public final class ParseLiveQuery: NSObject {
199199
}
200200
components.scheme = (components.scheme == "https" || components.scheme == "wss") ? "wss" : "ws"
201201
url = components.url
202-
self.createTask()
202+
self.task = URLSession.liveQuery.createTask(self.url)
203+
self.resumeTask()
203204

204205
if isDefault {
205206
Self.setDefault(self)
@@ -226,12 +227,11 @@ extension ParseLiveQuery {
226227
return Int.random(in: 0 ..< Int(truncating: min))
227228
}
228229

229-
func createTask() {
230+
func resumeTask() {
230231
synchronizationQueue.sync {
231-
if self.task == nil {
232-
self.task = URLSession.liveQuery.createTask(self.url)
232+
if self.task.state == .suspended {
233+
self.task.resume()
233234
}
234-
self.task.resume()
235235
URLSession.liveQuery.receive(self.task)
236236
URLSession.liveQuery.delegates[self.task] = self
237237
}
@@ -317,7 +317,7 @@ extension ParseLiveQuery: LiveQuerySocketDelegate {
317317
self.isSocketEstablished = false
318318
if !self.isDisconnectedByUser {
319319
//Try to reconnect
320-
self.createTask()
320+
self.resumeTask()
321321
}
322322
}
323323
}
@@ -329,7 +329,7 @@ extension ParseLiveQuery: LiveQuerySocketDelegate {
329329
if self.isConnected {
330330
self.close(useDedicatedQueue: true)
331331
//Try to reconnect
332-
self.createTask()
332+
self.resumeTask()
333333
}
334334
}
335335
return
@@ -344,7 +344,8 @@ extension ParseLiveQuery: LiveQuerySocketDelegate {
344344
guard let parseError = try? ParseCoding.jsonDecoder().decode(ParseError.self, from: data) else {
345345
//Turn LiveQuery error into ParseError
346346
let parseError = ParseError(code: .unknownError,
347-
message: "LiveQuery error code: \(error.code) message: \(error.error)")
347+
// swiftlint:disable:next line_length
348+
message: "ParseLiveQuery Error: code: \(error.code), message: \(error.error)")
348349
self.notificationQueue.async {
349350
self.receiveDelegate?.received(parseError)
350351
}
@@ -529,10 +530,11 @@ extension ParseLiveQuery {
529530
self.synchronizationQueue
530531
.asyncAfter(deadline: .now() + DispatchTimeInterval
531532
.seconds(reconnectInterval)) {
532-
self.createTask()
533+
self.resumeTask()
533534
self.attempts += 1
534535
let error = ParseError(code: .unknownError,
535-
message: "Attempted to open socket \(self.attempts) time(s)")
536+
// swiftlint:disable:next line_length
537+
message: "ParseLiveQuery Error: attempted to open socket \(self.attempts) time(s)")
536538
completion(error)
537539
}
538540
}
@@ -543,13 +545,12 @@ extension ParseLiveQuery {
543545
public func close() {
544546
synchronizationQueue.sync {
545547
if self.isConnected {
546-
self.task.cancel()
548+
self.task.cancel(with: .goingAway, reason: nil)
547549
self.isDisconnectedByUser = true
548550
}
549-
if task != nil {
550-
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
551-
}
552-
self.task = nil
551+
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
552+
isSocketEstablished = false
553+
self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use.
553554
}
554555
}
555556

@@ -568,11 +569,12 @@ extension ParseLiveQuery {
568569
*/
569570
public func sendPing(pongReceiveHandler: @escaping (Error?) -> Void) {
570571
synchronizationQueue.sync {
571-
if isSocketEstablished {
572+
if self.task.state == .running {
572573
URLSession.liveQuery.sendPing(task, pongReceiveHandler: pongReceiveHandler)
573574
} else {
574575
let error = ParseError(code: .unknownError,
575-
message: "Need to open the websocket before it can be pinged.")
576+
// swiftlint:disable:next line_length
577+
message: "ParseLiveQuery Error: socket status needs to be \"\(URLSessionTask.State.running.rawValue)\" before pinging server. Current status is \"\(self.task.state.rawValue)\". Try calling \"open()\" to change socket status.")
576578
pongReceiveHandler(error)
577579
}
578580
}
@@ -582,19 +584,18 @@ extension ParseLiveQuery {
582584
if useDedicatedQueue {
583585
synchronizationQueue.async {
584586
if self.isConnected {
585-
self.task.cancel()
587+
self.task.cancel(with: .goingAway, reason: nil)
586588
}
587589
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
588-
self.task = nil
590+
self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use.
589591
}
590592
} else {
591593
if self.isConnected {
592-
self.task.cancel()
593-
}
594-
if self.task != nil {
595-
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
594+
self.task.cancel(with: .goingAway, reason: nil)
596595
}
597-
self.task = nil
596+
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
597+
isSocketEstablished = false
598+
self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use.
598599
}
599600
}
600601

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "1.8.1"
13+
static let version = "1.8.4"
1414
static let hashingKey = "parseSwift"
1515
static let fileManagementDirectory = "parse/"
1616
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"

0 commit comments

Comments
 (0)