Skip to content

Switched context header X-Parse-Context to X-Parse-Cloud-Context #170

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

Merged
merged 23 commits into from
Jun 27, 2021
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,18 @@ jobs:
bundle install
- name: Create Jazzy Docs
run: ./Scripts/jazzy.sh
env:
BUILD_VERSION: '1.8.3'

cocoapods:
needs: xcode-build-watchos
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Update Framework Version
run: ./Scripts/update_build
env:
BUILD_VERSION: '1.8.3'
- name: CocoaPods
run: pod lib lint --allow-warnings

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Get release version
run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Update Framework Version
run: ./Scripts/update_build
env:
BUILD_VERSION: ${{ env.TAG }}
- name: CocoaPods
run: set -o pipefail && env NSUnbufferedIO=YES pod lib lint --allow-warnings --verbose
- name: Deploy CocoaPods
Expand All @@ -33,8 +39,12 @@ jobs:
run: |
bundle config path vendor/bundle
bundle install
- name: Get release version
run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Create Jazzy Docs
run: ./Scripts/jazzy.sh
env:
BUILD_VERSION: ${{ env.TAG }}
- name: Deploy Jazzy Docs
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Parse-Swift Changelog

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

### 1.8.4
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.3...1.8.4)

__Fixes__
- 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).
- 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).

### 1.8.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ do {
print(error)
}

//: If you look at your server log, you will notice the client and server disconnnected.
//: This is because there is no more LiveQuery subscriptions.

//: Ping the LiveQuery server. This should produce an error
//: because LiveQuery is disconnected.
ParseLiveQuery.client?.sendPing { error in
Expand All @@ -176,7 +179,7 @@ query2.fields("score")
//: Subscribe to your new query.
let subscription2 = query2.subscribeCallback!

//: As before, setup your subscription and event handlers.
//: As before, setup your subscription, event, and unsubscribe handlers.
subscription2.handleSubscribe { subscribedQuery, isNew in

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

subscription2.handleUnsubscribe { query in
print("Unsubscribed from \(query)")
}

//: To close the current LiveQuery connection.
ParseLiveQuery.client?.close()

Expand All @@ -219,41 +226,15 @@ ParseLiveQuery.client?.sendPing { error in
}
}

//: Subscribe to your new query.
//: Resubscribe to your previous query.
//: Since we never unsubscribed you can use your previous handlers.
let subscription3 = query2.subscribeCallback!

//: As before, setup your subscription and event handlers.
subscription3.handleSubscribe { subscribedQuery, isNew in

//: You can check this subscription is for this query.
if isNew {
print("Successfully subscribed to new query \(subscribedQuery)")
} else {
print("Successfully updated subscription to new query \(subscribedQuery)")
}
}

subscription3.handleEvent { _, event in
switch event {

case .entered(let object):
print("Entered: \(object)")
case .left(let object):
print("Left: \(object)")
case .created(let object):
print("Created: \(object)")
case .updated(let object):
print("Updated: \(object)")
case .deleted(let object):
print("Deleted: \(object)")
}
}

//: Now lets subscribe to an additional query.
//: Resubscribe to another previous query.
//: This one needs new handlers.
let subscription4 = query.subscribeCallback!

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

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

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

Expand All @@ -281,8 +262,8 @@ subscription4.handleEvent { _, event in
}
}

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

Expand All @@ -302,5 +283,15 @@ ParseLiveQuery.client?.sendPing { error in
}
}

//: To unsubscribe from your your last query.
do {
try query.unsubscribe()
} catch {
print(error)
}

//: If you look at your server log, you will notice the client and server disconnnected.
//: This is because there is no more LiveQuery subscriptions.

PlaygroundPage.current.finishExecution()
//: [Next](@next)
2 changes: 1 addition & 1 deletion ParseSwift.podspec → ParseSwift.podtemplate
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ParseSwift"
s.version = "1.8.3"
s.version = "[[VERSION]]"
s.summary = "Parse Pure Swift SDK"
s.homepage = "https://github.com/parse-community/Parse-Swift"
s.authors = {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/parse-community/Parse-Swift", from: "1.8.3"),
.package(url: "https://github.com/parse-community/Parse-Swift", from: "1.8.4"),
]
)
```
Expand Down
3 changes: 1 addition & 2 deletions Scripts/jazzy.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
ver=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" ParseSwift-iOS/Info.plist`
bundle exec jazzy \
--clean \
--author "Parse Community" \
--author_url http://parseplatform.org \
--github_url https://github.com/parse-community/Parse-Swift \
--root-url http://parseplatform.org/Parse-Swift/api/ \
--module-version 1.8.3 \
--module-version ${BUILD_VERSION} \
--theme fullwidth \
--skip-undocumented \
--output ./docs/api \
Expand Down
10 changes: 10 additions & 0 deletions Scripts/update_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Prepare podspec update
TEMPLATE_FILE_NAME="ParseSwift.podtemplate"
OUT_FILE_NAME="ParseSwift.podspec"

# Load the template podspec and replace version
TEMPLATE=$(cat "$TEMPLATE_FILE_NAME" | sed "s/\[\[VERSION\]\]/${BUILD_VERSION}/g")

echo "$TEMPLATE" > "$OUT_FILE_NAME"
2 changes: 1 addition & 1 deletion Sources/ParseSwift/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public struct API {
let context = AnyEncodable(context)
if let encoded = try? ParseCoding.jsonEncoder().encode(context),
let encodedString = String(data: encoded, encoding: .utf8) {
headers["X-Parse-Context"] = encodedString
headers["X-Parse-Cloud-Context"] = encodedString
}
}
}
Expand Down
49 changes: 25 additions & 24 deletions Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public final class ParseLiveQuery: NSObject {
}
components.scheme = (components.scheme == "https" || components.scheme == "wss") ? "wss" : "ws"
url = components.url
self.createTask()
self.task = URLSession.liveQuery.createTask(self.url)
self.resumeTask()

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

func createTask() {
func resumeTask() {
synchronizationQueue.sync {
if self.task == nil {
self.task = URLSession.liveQuery.createTask(self.url)
if self.task.state == .suspended {
self.task.resume()
}
self.task.resume()
URLSession.liveQuery.receive(self.task)
URLSession.liveQuery.delegates[self.task] = self
}
Expand Down Expand Up @@ -317,7 +317,7 @@ extension ParseLiveQuery: LiveQuerySocketDelegate {
self.isSocketEstablished = false
if !self.isDisconnectedByUser {
//Try to reconnect
self.createTask()
self.resumeTask()
}
}
}
Expand All @@ -329,7 +329,7 @@ extension ParseLiveQuery: LiveQuerySocketDelegate {
if self.isConnected {
self.close(useDedicatedQueue: true)
//Try to reconnect
self.createTask()
self.resumeTask()
}
}
return
Expand All @@ -344,7 +344,8 @@ extension ParseLiveQuery: LiveQuerySocketDelegate {
guard let parseError = try? ParseCoding.jsonDecoder().decode(ParseError.self, from: data) else {
//Turn LiveQuery error into ParseError
let parseError = ParseError(code: .unknownError,
message: "LiveQuery error code: \(error.code) message: \(error.error)")
// swiftlint:disable:next line_length
message: "ParseLiveQuery Error: code: \(error.code), message: \(error.error)")
self.notificationQueue.async {
self.receiveDelegate?.received(parseError)
}
Expand Down Expand Up @@ -529,10 +530,11 @@ extension ParseLiveQuery {
self.synchronizationQueue
.asyncAfter(deadline: .now() + DispatchTimeInterval
.seconds(reconnectInterval)) {
self.createTask()
self.resumeTask()
self.attempts += 1
let error = ParseError(code: .unknownError,
message: "Attempted to open socket \(self.attempts) time(s)")
// swiftlint:disable:next line_length
message: "ParseLiveQuery Error: attempted to open socket \(self.attempts) time(s)")
completion(error)
}
}
Expand All @@ -543,13 +545,12 @@ extension ParseLiveQuery {
public func close() {
synchronizationQueue.sync {
if self.isConnected {
self.task.cancel()
self.task.cancel(with: .goingAway, reason: nil)
self.isDisconnectedByUser = true
}
if task != nil {
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
}
self.task = nil
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
isSocketEstablished = false
self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use.
}
}

Expand All @@ -568,11 +569,12 @@ extension ParseLiveQuery {
*/
public func sendPing(pongReceiveHandler: @escaping (Error?) -> Void) {
synchronizationQueue.sync {
if isSocketEstablished {
if self.task.state == .running {
URLSession.liveQuery.sendPing(task, pongReceiveHandler: pongReceiveHandler)
} else {
let error = ParseError(code: .unknownError,
message: "Need to open the websocket before it can be pinged.")
// swiftlint:disable:next line_length
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.")
pongReceiveHandler(error)
}
}
Expand All @@ -582,19 +584,18 @@ extension ParseLiveQuery {
if useDedicatedQueue {
synchronizationQueue.async {
if self.isConnected {
self.task.cancel()
self.task.cancel(with: .goingAway, reason: nil)
}
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
self.task = nil
self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use.
}
} else {
if self.isConnected {
self.task.cancel()
}
if self.task != nil {
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
self.task.cancel(with: .goingAway, reason: nil)
}
self.task = nil
URLSession.liveQuery.delegates.removeValue(forKey: self.task)
isSocketEstablished = false
self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use.
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "1.8.1"
static let version = "1.8.4"
static let hashingKey = "parseSwift"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
Expand Down
Loading