Skip to content
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

feat: use url session websocket as default adapter #150

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion AppSyncRealTimeClient.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.homepage = 'https://aws.amazon.com/amplify/'
s.license = 'Apache License, Version 2.0'
s.author = { 'Amazon Web Services' => 'amazonwebservices' }
s.platform = :ios, '9.0'
s.platform = :ios, '13.0'
s.source = { :git => 'https://github.com/aws-amplify/aws-appsync-realtime-client-ios.git', :tag => s.version}
s.swift_version = '5.1'

Expand Down
86 changes: 14 additions & 72 deletions AppSyncRealTimeClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
217F39DE2406E98400F1A0B3 /* AppSyncSubscriptionConnection+ErrorHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 217F39BF2406E98300F1A0B3 /* AppSyncSubscriptionConnection+ErrorHandler.swift */; };
217F39DF2406E98400F1A0B3 /* SubscriptionItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 217F39C02406E98300F1A0B3 /* SubscriptionItem.swift */; };
217F39E02406E98400F1A0B3 /* AppSyncWebsocketProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 217F39C22406E98400F1A0B3 /* AppSyncWebsocketProvider.swift */; };
217F39E12406E98400F1A0B3 /* StarscreamAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 217F39C42406E98400F1A0B3 /* StarscreamAdapter.swift */; };
217F39E22406E98400F1A0B3 /* StarscreamAdapter+Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 217F39C52406E98400F1A0B3 /* StarscreamAdapter+Delegate.swift */; };
217F39E32406E98400F1A0B3 /* AppSyncLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 217F39C72406E98400F1A0B3 /* AppSyncLogger.swift */; };
217F39E42406E98400F1A0B3 /* RealtimeGatewayURLInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 217F39C82406E98400F1A0B3 /* RealtimeGatewayURLInterceptor.swift */; };
217F39E52406E98400F1A0B3 /* AppSyncJSONValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 217F39C92406E98400F1A0B3 /* AppSyncJSONValue.swift */; };
Expand Down Expand Up @@ -89,6 +87,7 @@
5CFF7239283C19CF001D5471 /* TaskQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CFF7238283C19CF001D5471 /* TaskQueue.swift */; };
5CFF723D283C1AF5001D5471 /* ConnectionProviderAsyncTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CFF723B283C1AF5001D5471 /* ConnectionProviderAsyncTests.swift */; };
5CFF723E283C1AF5001D5471 /* RealtimeConnectionProviderAsyncTestBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CFF723C283C1AF5001D5471 /* RealtimeConnectionProviderAsyncTestBase.swift */; };
6092B6C02B58611C00FD5DC2 /* URLSessionWebsocketAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6092B6BF2B58611C00FD5DC2 /* URLSessionWebsocketAdapter.swift */; };
978409B82739C7BE002362A7 /* AppSyncURLHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 978409B72739C7BE002362A7 /* AppSyncURLHelper.swift */; };
978409BA2739C7E1002362A7 /* AppSyncURLHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 978409B92739C7E1002362A7 /* AppSyncURLHelperTests.swift */; };
B4AEC68C29E8A14F00D693CD /* InterceptableConnection+Default.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4AEC68B29E8A14F00D693CD /* InterceptableConnection+Default.swift */; };
Expand Down Expand Up @@ -177,8 +176,6 @@
217F39BF2406E98300F1A0B3 /* AppSyncSubscriptionConnection+ErrorHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AppSyncSubscriptionConnection+ErrorHandler.swift"; sourceTree = "<group>"; };
217F39C02406E98300F1A0B3 /* SubscriptionItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionItem.swift; sourceTree = "<group>"; };
217F39C22406E98400F1A0B3 /* AppSyncWebsocketProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSyncWebsocketProvider.swift; sourceTree = "<group>"; };
217F39C42406E98400F1A0B3 /* StarscreamAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarscreamAdapter.swift; sourceTree = "<group>"; };
217F39C52406E98400F1A0B3 /* StarscreamAdapter+Delegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StarscreamAdapter+Delegate.swift"; sourceTree = "<group>"; };
217F39C72406E98400F1A0B3 /* AppSyncLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSyncLogger.swift; sourceTree = "<group>"; };
217F39C82406E98400F1A0B3 /* RealtimeGatewayURLInterceptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealtimeGatewayURLInterceptor.swift; sourceTree = "<group>"; };
217F39C92406E98400F1A0B3 /* AppSyncJSONValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSyncJSONValue.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -234,6 +231,7 @@
5CFF7238283C19CF001D5471 /* TaskQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskQueue.swift; sourceTree = "<group>"; };
5CFF723B283C1AF5001D5471 /* ConnectionProviderAsyncTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionProviderAsyncTests.swift; sourceTree = "<group>"; };
5CFF723C283C1AF5001D5471 /* RealtimeConnectionProviderAsyncTestBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealtimeConnectionProviderAsyncTestBase.swift; sourceTree = "<group>"; };
6092B6BF2B58611C00FD5DC2 /* URLSessionWebsocketAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionWebsocketAdapter.swift; sourceTree = "<group>"; };
7CF486070B34EFD15B4DB8FC /* Pods_AppSyncRTCSample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AppSyncRTCSample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7D4F451B830A5837CE5274A3 /* Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests.release.xcconfig"; path = "Target Support Files/Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests/Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests.release.xcconfig"; sourceTree = "<group>"; };
81AFCBED5A97E398A4BD9D06 /* Pods_AppSyncRealTimeClient.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AppSyncRealTimeClient.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -432,21 +430,12 @@
217F39C12406E98400F1A0B3 /* Websocket */ = {
isa = PBXGroup;
children = (
6092B6BE2B58610000FD5DC2 /* URLSession */,
217F39C22406E98400F1A0B3 /* AppSyncWebsocketProvider.swift */,
217F39C32406E98400F1A0B3 /* Starscream */,
);
path = Websocket;
sourceTree = "<group>";
};
217F39C32406E98400F1A0B3 /* Starscream */ = {
isa = PBXGroup;
children = (
217F39C42406E98400F1A0B3 /* StarscreamAdapter.swift */,
217F39C52406E98400F1A0B3 /* StarscreamAdapter+Delegate.swift */,
);
path = Starscream;
sourceTree = "<group>";
};
217F39C62406E98400F1A0B3 /* Support */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -624,6 +613,14 @@
path = ConnectionProviderAsync;
sourceTree = "<group>";
};
6092B6BE2B58610000FD5DC2 /* URLSession */ = {
isa = PBXGroup;
children = (
6092B6BF2B58611C00FD5DC2 /* URLSessionWebsocketAdapter.swift */,
);
path = URLSession;
sourceTree = "<group>";
};
CC47BA7DC6033B1626BAD959 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -728,7 +725,6 @@
FA91B21424D308B00017404D /* SwiftLint */,
217F39952405D9D500F1A0B3 /* Frameworks */,
217F39962405D9D500F1A0B3 /* Resources */,
9CB3A44F02BD117B9687BF03 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -750,7 +746,6 @@
FA91B21624D308D90017404D /* SwiftLint */,
21D38B3B2409AFBD00EC2A8D /* Frameworks */,
21D38B3C2409AFBD00EC2A8D /* Resources */,
D3A1E54210CC83949895F543 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -791,7 +786,6 @@
FA91B21824D308FD0017404D /* SwiftLint */,
FA91B1F824D3063E0017404D /* Frameworks */,
FA91B1F924D3063E0017404D /* Resources */,
7CEC6E6F72B76741B987A5FE /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -947,40 +941,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
7CEC6E6F72B76741B987A5FE /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AppSyncRTCSample/Pods-AppSyncRTCSample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AppSyncRTCSample/Pods-AppSyncRTCSample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AppSyncRTCSample/Pods-AppSyncRTCSample-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9CB3A44F02BD117B9687BF03 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests/Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests/Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests/Pods-AppSyncRealTimeClient-AppSyncRealTimeClientTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
A19977CDA1FE7EB3815A5E31 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1025,23 +985,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
D3A1E54210CC83949895F543 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-HostApp-AppSyncRealTimeClientIntegrationTests/Pods-HostApp-AppSyncRealTimeClientIntegrationTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-HostApp-AppSyncRealTimeClientIntegrationTests/Pods-HostApp-AppSyncRealTimeClientIntegrationTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-HostApp-AppSyncRealTimeClientIntegrationTests/Pods-HostApp-AppSyncRealTimeClientIntegrationTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
F78B4AC87B22D691D620684A /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1231,6 +1174,7 @@
217F39CD2406E98400F1A0B3 /* InterceptableConnection.swift in Sources */,
21D38B8E240A3C2300EC2A8D /* ConnectionProviderFactory.swift in Sources */,
217F39E02406E98400F1A0B3 /* AppSyncWebsocketProvider.swift in Sources */,
6092B6C02B58611C00FD5DC2 /* URLSessionWebsocketAdapter.swift in Sources */,
219BFF4927A3B238000FC148 /* ConnectivityMonitor.swift in Sources */,
FAB7E91224D2644E00DF1EA1 /* RealtimeConnectionProvider+StaleConnection.swift in Sources */,
217F39D32406E98400F1A0B3 /* RealtimeConnectionProvider.swift in Sources */,
Expand All @@ -1241,7 +1185,6 @@
217F39E52406E98400F1A0B3 /* AppSyncJSONValue.swift in Sources */,
217F39E42406E98400F1A0B3 /* RealtimeGatewayURLInterceptor.swift in Sources */,
2143D4B027BC49BE0066B2F7 /* AWSAppSyncRealTimeClient.swift in Sources */,
217F39E22406E98400F1A0B3 /* StarscreamAdapter+Delegate.swift in Sources */,
217F39D52406E98400F1A0B3 /* RealtimeConnectionProviderResponse.swift in Sources */,
217F39D62406E98400F1A0B3 /* RealtimeConnectionProvider+MessageInterceptable.swift in Sources */,
5CFF7233283C1971001D5471 /* RealtimeConnectionProviderAsync.swift in Sources */,
Expand All @@ -1266,7 +1209,6 @@
21D38B6D240A262800EC2A8D /* AppSyncJSONHelper.swift in Sources */,
219BFF4B27A3B24F000FC148 /* ConnectivityPath.swift in Sources */,
217F39CE2406E98400F1A0B3 /* ConnectionProviderError.swift in Sources */,
217F39E12406E98400F1A0B3 /* StarscreamAdapter.swift in Sources */,
217F39D72406E98400F1A0B3 /* RealtimeConnectionProvider+ConnectionInterceptable.swift in Sources */,
217F39DE2406E98400F1A0B3 /* AppSyncSubscriptionConnection+ErrorHandler.swift in Sources */,
5CFF7237283C1971001D5471 /* RealtimeConnectionProviderAsync+MessageInterceptableAsync.swift in Sources */,
Expand Down Expand Up @@ -1515,7 +1457,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = AppSyncRealTimeClient/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1542,7 +1484,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = AppSyncRealTimeClient/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import Starscream

extension AppSyncSubscriptionConnection {
func handleError(error: Error) {
Expand Down Expand Up @@ -72,8 +71,6 @@ extension AppSyncSubscriptionConnection {
switch error {
case let typedError as ConnectionProviderError:
logExtendedErrorInfo(for: typedError)
case let typedError as WSError:
logExtendedErrorInfo(for: typedError)
case let typedError as NSError:
logExtendedErrorInfo(for: typedError)
default:
Expand Down Expand Up @@ -115,10 +112,6 @@ extension AppSyncSubscriptionConnection {
}
}

private static func logExtendedErrorInfo(for error: WSError) {
AppSyncLogger.error(error)
}

private static func logExtendedErrorInfo(for error: NSError) {
AppSyncLogger.error(
"""
Expand All @@ -130,13 +123,3 @@ extension AppSyncSubscriptionConnection {
}

}

extension WSError: CustomStringConvertible {
public var description: String {
"""
WSError:\(message); \
code:\(code); \
type:\(type)
"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import Foundation

extension RealtimeConnectionProvider: AppSyncWebsocketDelegate {
public func websocketDidReceiveError(provider: AppSyncWebsocketProvider, error: Error?) {
AppSyncLogger.debug("[RealtimeConnectionProvider] WebsocketDidReceiveError, error: \(String(describing: error))")
}


public func websocketDidConnect(provider: AppSyncWebsocketProvider) {
// Call the ack to finish the connection handshake
Expand All @@ -23,11 +27,12 @@ extension RealtimeConnectionProvider: AppSyncWebsocketDelegate {
return
}
self.status = .notConnected
guard error != nil else {

if error != nil {
self.updateCallback(event: .error(ConnectionProviderError.connection))
} else {
self.updateCallback(event: .connection(self.status))
return
}
self.updateCallback(event: .error(ConnectionProviderError.connection))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extension RealtimeConnectionProviderAsync {
AppSyncLogger.error("[RealtimeConnectionProvider] Realtime connection is stale, disconnecting.")
self.status = .notConnected
self.isStaleConnection = false
self.websocket.disconnect()
self.webSocket.disconnect()
self.updateCallback(event: .error(ConnectionProviderError.connection))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// SPDX-License-Identifier: Apache-2.0
//

#if swift(>=5.5.2)

import Foundation

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension RealtimeConnectionProviderAsync: AppSyncWebsocketDelegate {
public func websocketDidReceiveError(provider: AppSyncWebsocketProvider, error: Error?) {
AppSyncLogger.debug("[RealtimeConnectionProvider] WebsocketDidReceiveError, error: \(String(describing: error))")
}

public func websocketDidConnect(provider: AppSyncWebsocketProvider) {
// Call the ack to finish the connection handshake
Expand Down Expand Up @@ -127,4 +127,3 @@ extension RealtimeConnectionProviderAsync: AppSyncWebsocketDelegate {
}

}
#endif
Loading