From ca83556266850c616487d445165591a00e2dc1d9 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Fri, 2 Feb 2018 16:43:18 -0500 Subject: [PATCH 1/4] Swift 4 --- .swiftlint.yml | 3 +- Cartfile | 6 ++-- Package.swift | 20 +++++++---- README.md | 6 ++-- SKRTMAPI.podspec | 34 +++++++++---------- SKRTMAPI.xcodeproj/project.pbxproj | 26 ++++++++++---- .../xcschemes/SKRTMAPI iOS.xcscheme | 4 ++- .../xcschemes/SKRTMAPI macOS.xcscheme | 4 ++- .../xcschemes/SKRTMAPI tvOS.xcscheme | 4 ++- .../SKRTMAPI/Conformers/StarscreamRTM.swift | 14 +++++--- Supporting Files/Info.plist | 2 +- 11 files changed, 77 insertions(+), 46 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 4d09ef6..ca85008 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -4,4 +4,5 @@ disabled_rules: line_length: 140 excluded: # paths to ignore during linting. Takes precedence over `included`. - Carthage - - Pods \ No newline at end of file + - Pods + - .build \ No newline at end of file diff --git a/Cartfile b/Cartfile index c1e41d6..8b5bad6 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,3 @@ -github "SlackKit/SKCore" >= 4.0.0 -github "SlackKit/SKWebAPI" >= 4.0.0 -github "daltoniam/Starscream" ~> 2.0 \ No newline at end of file +github "SlackKit/SKCore" >= 4.1.0 +github "SlackKit/SKWebAPI" >= 4.1.0 +github "daltoniam/Starscream" ~> 3.0 \ No newline at end of file diff --git a/Package.swift b/Package.swift index 8b8a365..a4aad20 100644 --- a/Package.swift +++ b/Package.swift @@ -1,20 +1,26 @@ +// swift-tools-version:4.0 import PackageDescription let package = Package( name: "SKRTMAPI", - targets: [ - Target(name: "SKRTMAPI") + products: [ + .library(name: "SKRTMAPI", targets: ["SKRTMAPI"]) ], dependencies: [ - .Package(url: "https://github.com/SlackKit/SKCore", majorVersion: 4), - .Package(url: "https://github.com/SlackKit/SKWebAPI", majorVersion: 4) - ] + .package(url: "https://github.com/SlackKit/SKCore", .upToNextMajor(from: "4.0.0")), + .package(url: "https://github.com/SlackKit/SKWebAPI", .upToNextMajor(from: "4.0.0")) + ], + targets: [] ) var dependency: Package.Dependency +var target: Target #if os(macOS) || os(iOS) || os(tvOS) -dependency = .Package(url: "https://github.com/daltoniam/Starscream", majorVersion: 2) +target = .target(name: "SKRTMAPI", dependencies: ["SKCore", "SKWebAPI", "Starscream"]) +dependency = .package(url: "https://github.com/daltoniam/Starscream", .upToNextMajor(from: "3.0.0")) #else -dependency = .Package(url: "https://github.com/Zewo/WebSocketClient.git", majorVersion: 0, minor: 14) +target = .target(name: "SKRTMAPI", dependencies: ["SKCore", "SKWebAPI", "WebSockets", "HTTP", "URI"]) +dependency = .package(url: "https://github.com/vapor/engine", .upToNextMajor(from: "2.2.2")) #endif package.dependencies.append(dependency) +package.targets.append(target) diff --git a/README.md b/README.md index 312beff..5016b35 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # SKRTMAPI: SlackKit RTM Module -![Swift Version](https://img.shields.io/badge/Swift-3.1.1-orange.svg) +![Swift Version](https://img.shields.io/badge/Swift-4.0.3-orange.svg) ![Plaforms](https://img.shields.io/badge/Platforms-macOS,iOS,tvOS,Linux-lightgrey.svg) ![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg) [![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) @@ -21,7 +21,7 @@ pod 'SKRTMAPI' and run ``` -# Use CocoaPods version >= 1.1.0 +# Use CocoaPods version >= 1.4.0 pod install ``` @@ -49,7 +49,7 @@ import PackageDescription let package = Package( dependencies: [ - .Package(url: "https://github.com/SlackKit/SKRTMAPI.git", majorVersion: 4) + .package(url: "https://github.com/SlackKit/SKRTMAPI.git", .upToNextMinor(from: "4.1.0")) ] ) ``` diff --git a/SKRTMAPI.podspec b/SKRTMAPI.podspec index 9a7c6e6..84f2ff0 100644 --- a/SKRTMAPI.podspec +++ b/SKRTMAPI.podspec @@ -1,19 +1,19 @@ Pod::Spec.new do |s| - s.name = "SKRTMAPI" - s.version = "4.0.3" - s.summary = "A Swift library for connecting to the Slack RTM API" - s.homepage = "https://github.com/SlackKit/SKRTMAPI" - s.license = 'MIT' - s.author = { "Peter Zignego" => "peter@launchsoft.co" } - s.source = { :git => "https://github.com/SlackKit/SKRTMAPI.git", :tag => s.version.to_s } - s.social_media_url = 'https://twitter.com/pvzig' - s.ios.deployment_target = '9.0' - s.osx.deployment_target = '10.11' - s.tvos.deployment_target = '9.0' - s.requires_arc = true - s.source_files = 'Sources/**/*.swift' - s.frameworks = 'Foundation' - s.dependency 'SKCore' - s.dependency 'SKWebAPI' - s.dependency 'Starscream' + s.name = "SKRTMAPI" + s.version = "4.1.0" + s.summary = "A Swift library for connecting to the Slack RTM API" + s.homepage = "https://github.com/SlackKit/SKRTMAPI" + s.license = 'MIT' + s.author = { "Peter Zignego" => "peter@launchsoft.co" } + s.source = { :git => "https://github.com/SlackKit/SKRTMAPI.git", :tag => s.version.to_s } + s.social_media_url = 'https://twitter.com/pvzig' + s.ios.deployment_target = '9.0' + s.osx.deployment_target = '10.11' + s.tvos.deployment_target = '9.0' + s.requires_arc = true + s.source_files = 'Sources/**/*.swift' + s.frameworks = 'Foundation' + s.dependency 'SKCore' + s.dependency 'SKWebAPI' + s.dependency 'Starscream' end diff --git a/SKRTMAPI.xcodeproj/project.pbxproj b/SKRTMAPI.xcodeproj/project.pbxproj index 5c12204..d4ee3fa 100644 --- a/SKRTMAPI.xcodeproj/project.pbxproj +++ b/SKRTMAPI.xcodeproj/project.pbxproj @@ -249,7 +249,7 @@ 2684F1741E95AA6900536DCC /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = "Peter Zignego"; TargetAttributes = { 2684F17C1E95AA6900536DCC = { @@ -396,7 +396,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -404,7 +406,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -449,7 +455,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -457,7 +465,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -507,7 +519,7 @@ PRODUCT_NAME = SKRTMAPI; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -534,7 +546,7 @@ PRODUCT_NAME = SKRTMAPI; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -561,7 +573,7 @@ PRODUCT_NAME = SKRTMAPI; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -588,7 +600,7 @@ PRODUCT_NAME = SKRTMAPI; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -614,7 +626,7 @@ PRODUCT_NAME = SKRTMAPI; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -641,7 +653,7 @@ PRODUCT_NAME = SKRTMAPI; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; diff --git a/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI iOS.xcscheme b/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI iOS.xcscheme index 33f6e82..1540071 100644 --- a/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI iOS.xcscheme +++ b/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI iOS.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI macOS.xcscheme b/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI macOS.xcscheme index f635107..deca31e 100644 --- a/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI macOS.xcscheme +++ b/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI macOS.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI tvOS.xcscheme b/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI tvOS.xcscheme index 2386711..79cbfc6 100644 --- a/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI tvOS.xcscheme +++ b/SKRTMAPI.xcodeproj/xcshareddata/xcschemes/SKRTMAPI tvOS.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Sources/SKRTMAPI/Conformers/StarscreamRTM.swift b/Sources/SKRTMAPI/Conformers/StarscreamRTM.swift index 68862fe..43fda03 100644 --- a/Sources/SKRTMAPI/Conformers/StarscreamRTM.swift +++ b/Sources/SKRTMAPI/Conformers/StarscreamRTM.swift @@ -27,6 +27,7 @@ import SKCore import Starscream public class StarscreamRTM: RTMWebSocket, WebSocketDelegate { + public weak var delegate: RTMDelegate? private var webSocket: WebSocket? @@ -55,19 +56,24 @@ public class StarscreamRTM: RTMWebSocket, WebSocketDelegate { } // MARK: - WebSocketDelegate - public func websocketDidConnect(socket: WebSocket) { + public func websocketDidConnect(socket: WebSocketClient) { delegate?.didConnect() } - public func websocketDidDisconnect(socket: WebSocket, error: NSError?) { + public func websocketDidDisconnect(socket: WebSocketClient, error: Error?) { webSocket = nil delegate?.disconnected() } - public func websocketDidReceiveMessage(socket: WebSocket, text: String) { + public func websocketDidReceiveMessage(socket: WebSocketClient, text: String) { delegate?.receivedMessage(text) } - public func websocketDidReceiveData(socket: WebSocket, data: Data) {} + public func websocketDidConnect(socket: WebSocket) { + delegate?.didConnect() + } + + public func websocketDidReceiveData(socket: WebSocketClient, data: Data) {} } + #endif diff --git a/Supporting Files/Info.plist b/Supporting Files/Info.plist index 2253315..020969e 100644 --- a/Supporting Files/Info.plist +++ b/Supporting Files/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.0.0 + 4.1.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright From 4dc4ad0d458252031b594d2a3d3fcedb87632814 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Wed, 7 Feb 2018 22:36:45 -0500 Subject: [PATCH 2/4] vapor/engine --- .swift-version | 1 + SKRTMAPI.xcodeproj/project.pbxproj | 26 +++----- .../{ZewoRTM.swift => VaporEngineRTM.swift} | 20 +++--- .../Conformers/WebSocketFactory.swift | 65 +++++++++++++++++++ Sources/SKRTMAPI/SKRTMAPI.swift | 8 +-- 5 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 .swift-version rename Sources/SKRTMAPI/Conformers/{ZewoRTM.swift => VaporEngineRTM.swift} (85%) create mode 100644 Sources/SKRTMAPI/Conformers/WebSocketFactory.swift diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..5186d07 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +4.0 diff --git a/SKRTMAPI.xcodeproj/project.pbxproj b/SKRTMAPI.xcodeproj/project.pbxproj index d4ee3fa..d049a87 100644 --- a/SKRTMAPI.xcodeproj/project.pbxproj +++ b/SKRTMAPI.xcodeproj/project.pbxproj @@ -16,12 +16,9 @@ 26D1C4D91EE4655100C95954 /* SKCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C4D61EE4655100C95954 /* SKCore.framework */; }; 26D1C4DA1EE4655100C95954 /* SKWebAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C4D71EE4655100C95954 /* SKWebAPI.framework */; }; 26D1C4DB1EE4655100C95954 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C4D81EE4655100C95954 /* Starscream.framework */; }; - 26DC0EB31E95BED900991BDF /* StarscreamRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB01E95BED900991BDF /* StarscreamRTM.swift */; }; - 26DC0EB41E95BED900991BDF /* StarscreamRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB01E95BED900991BDF /* StarscreamRTM.swift */; }; - 26DC0EB51E95BED900991BDF /* StarscreamRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB01E95BED900991BDF /* StarscreamRTM.swift */; }; - 26DC0EB61E95BED900991BDF /* ZewoRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB11E95BED900991BDF /* ZewoRTM.swift */; }; - 26DC0EB71E95BED900991BDF /* ZewoRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB11E95BED900991BDF /* ZewoRTM.swift */; }; - 26DC0EB81E95BED900991BDF /* ZewoRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB11E95BED900991BDF /* ZewoRTM.swift */; }; + 26DC0EB61E95BED900991BDF /* VaporEngineRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB11E95BED900991BDF /* VaporEngineRTM.swift */; }; + 26DC0EB71E95BED900991BDF /* VaporEngineRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB11E95BED900991BDF /* VaporEngineRTM.swift */; }; + 26DC0EB81E95BED900991BDF /* VaporEngineRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB11E95BED900991BDF /* VaporEngineRTM.swift */; }; 26DC0EB91E95BED900991BDF /* SKRTMAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB21E95BED900991BDF /* SKRTMAPI.swift */; }; 26DC0EBA1E95BED900991BDF /* SKRTMAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB21E95BED900991BDF /* SKRTMAPI.swift */; }; 26DC0EBB1E95BED900991BDF /* SKRTMAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DC0EB21E95BED900991BDF /* SKRTMAPI.swift */; }; @@ -41,9 +38,9 @@ 26D1C4D61EE4655100C95954 /* SKCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SKCore.framework; path = Carthage/Build/tvOS/SKCore.framework; sourceTree = ""; }; 26D1C4D71EE4655100C95954 /* SKWebAPI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SKWebAPI.framework; path = Carthage/Build/tvOS/SKWebAPI.framework; sourceTree = ""; }; 26D1C4D81EE4655100C95954 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/tvOS/Starscream.framework; sourceTree = ""; }; - 26DC0EB01E95BED900991BDF /* StarscreamRTM.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarscreamRTM.swift; sourceTree = ""; }; - 26DC0EB11E95BED900991BDF /* ZewoRTM.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZewoRTM.swift; sourceTree = ""; }; + 26DC0EB11E95BED900991BDF /* VaporEngineRTM.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VaporEngineRTM.swift; sourceTree = ""; }; 26DC0EB21E95BED900991BDF /* SKRTMAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SKRTMAPI.swift; sourceTree = ""; }; + D2C085F12024BF9600FEC5AB /* WebSocketFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocketFactory.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -153,8 +150,8 @@ 26DC0EAF1E95BED900991BDF /* Conformers */ = { isa = PBXGroup; children = ( - 26DC0EB01E95BED900991BDF /* StarscreamRTM.swift */, - 26DC0EB11E95BED900991BDF /* ZewoRTM.swift */, + 26DC0EB11E95BED900991BDF /* VaporEngineRTM.swift */, + D2C085F12024BF9600FEC5AB /* WebSocketFactory.swift */, ); path = Conformers; sourceTree = ""; @@ -357,8 +354,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 26DC0EB61E95BED900991BDF /* ZewoRTM.swift in Sources */, - 26DC0EB31E95BED900991BDF /* StarscreamRTM.swift in Sources */, + 26DC0EB61E95BED900991BDF /* VaporEngineRTM.swift in Sources */, 26DC0EB91E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -367,8 +363,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 26DC0EB71E95BED900991BDF /* ZewoRTM.swift in Sources */, - 26DC0EB41E95BED900991BDF /* StarscreamRTM.swift in Sources */, + 26DC0EB71E95BED900991BDF /* VaporEngineRTM.swift in Sources */, 26DC0EBA1E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -377,8 +372,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 26DC0EB81E95BED900991BDF /* ZewoRTM.swift in Sources */, - 26DC0EB51E95BED900991BDF /* StarscreamRTM.swift in Sources */, + 26DC0EB81E95BED900991BDF /* VaporEngineRTM.swift in Sources */, 26DC0EBB1E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Sources/SKRTMAPI/Conformers/ZewoRTM.swift b/Sources/SKRTMAPI/Conformers/VaporEngineRTM.swift similarity index 85% rename from Sources/SKRTMAPI/Conformers/ZewoRTM.swift rename to Sources/SKRTMAPI/Conformers/VaporEngineRTM.swift index 5c90c2d..5bd5214 100644 --- a/Sources/SKRTMAPI/Conformers/ZewoRTM.swift +++ b/Sources/SKRTMAPI/Conformers/VaporEngineRTM.swift @@ -1,5 +1,5 @@ // -// ZewoRTM.swift +// VaporEngineRTM.swift // // Copyright © 2017 Peter Zignego. All rights reserved. // @@ -21,13 +21,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#if os(Linux) import Dispatch import Foundation import SKCore -import WebSocketClient +import URI -public class ZewoRTM: RTMWebSocket { +public class VaporEngineRTM: RTMWebSocket { public weak var delegate: RTMDelegate? var webSocket: WebSocket? let queue = DispatchQueue(label: "com.launchsoft.slackkit") @@ -38,10 +37,10 @@ public class ZewoRTM: RTMWebSocket { public func connect(url: URL) { queue.async { do { - try WebSocketClient(url: url, didConnect: { (webSocket) in + try WebSocketFactory.shared.connect(to: url.absoluteString) { (webSocket) in self.delegate?.didConnect() self.setupSocket(webSocket) - }).connect() + } } catch let error { print("WebSocket client could not connect: \(error)") } @@ -65,15 +64,14 @@ public class ZewoRTM: RTMWebSocket { // MARK: - WebSocket private func setupSocket(_ webSocket: WebSocket) { - webSocket.onText { (message) in + webSocket.onText = { _, message in self.delegate?.receivedMessage(message) } - webSocket.onClose { _, _ in + webSocket.onClose = { _, _, _, _ in self.delegate?.disconnected() } - webSocket.onPing { _ in try webSocket.pong() } - webSocket.onPong { _ in try webSocket.ping() } + webSocket.onPing = { _, _ in try webSocket.pong() } + webSocket.onPong = { _, _ in try webSocket.ping() } self.webSocket = webSocket } } -#endif diff --git a/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift b/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift new file mode 100644 index 0000000..71d6247 --- /dev/null +++ b/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift @@ -0,0 +1,65 @@ +import WebSockets +import HTTP +import Sockets +import TLS +import URI + +public typealias WebSocket = WebSockets.WebSocket + +public final class WebSocketFactory { + public static let shared = WebSocketFactory() + + public init() {} + + public func connect( + to uri: URI, + protocols: [String]? = nil, + headers: [HeaderKey: String]? = nil, + onConnect: @escaping (WebSocket) throws -> Void + ) throws { + + if uri.scheme.isSecure { + let tcp = try TCPInternetSocket( + scheme: "https", + hostname: uri.hostname, + port: uri.port ?? 443 + ) + let stream = try TLS.InternetSocket(tcp, TLS.Context(.client)) + try WebSocket.connect( + to: uri, + using: stream, + protocols: protocols, + headers: headers, + onConnect: onConnect + ) + } else { + let stream = try TCPInternetSocket( + scheme: "http", + hostname: uri.hostname, + port: uri.port ?? 80 + ) + try WebSocket.connect( + to: uri, + using: stream, + protocols: protocols, + headers: headers, + onConnect: onConnect + ) + } + } + + public func connect( + to uri: String, + protocols: [String]? = nil, + headers: [HeaderKey: String]? = nil, + onConnect: @escaping (WebSocket) throws -> Void + ) throws { + let uri = try URI(uri) + try connect( + to: uri, + protocols: protocols, + headers: headers, + onConnect: onConnect + ) + } +} diff --git a/Sources/SKRTMAPI/SKRTMAPI.swift b/Sources/SKRTMAPI/SKRTMAPI.swift index e814059..7e799df 100644 --- a/Sources/SKRTMAPI/SKRTMAPI.swift +++ b/Sources/SKRTMAPI/SKRTMAPI.swift @@ -21,9 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#if os(Linux) import Dispatch -#endif import Foundation import SKWebAPI @_exported import SKCore @@ -64,11 +62,7 @@ public final class SKRTMAPI: RTMDelegate { if let rtm = rtm { self.rtm = rtm } else { - #if os(Linux) - self.rtm = ZewoRTM() - #else - self.rtm = StarscreamRTM() - #endif + self.rtm = VaporEngineRTM() } self.rtm.delegate = self } From 23376d5c5d6582a6a0721249f5c1c68a3842b670 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Wed, 7 Feb 2018 22:46:10 -0500 Subject: [PATCH 3/4] OS flags --- SKRTMAPI.xcodeproj/project.pbxproj | 8 ++++++++ Sources/SKRTMAPI/Conformers/VaporEngineRTM.swift | 2 ++ Sources/SKRTMAPI/Conformers/WebSocketFactory.swift | 2 ++ Sources/SKRTMAPI/SKRTMAPI.swift | 6 +++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/SKRTMAPI.xcodeproj/project.pbxproj b/SKRTMAPI.xcodeproj/project.pbxproj index d049a87..a6e6e89 100644 --- a/SKRTMAPI.xcodeproj/project.pbxproj +++ b/SKRTMAPI.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 2604C59C202BFD83009CDBAF /* StarscreamRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2604C59B202BFD83009CDBAF /* StarscreamRTM.swift */; }; + 2604C59D202BFD83009CDBAF /* StarscreamRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2604C59B202BFD83009CDBAF /* StarscreamRTM.swift */; }; + 2604C59E202BFD83009CDBAF /* StarscreamRTM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2604C59B202BFD83009CDBAF /* StarscreamRTM.swift */; }; 26D1C4CD1EE4653600C95954 /* SKCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C4CA1EE4653600C95954 /* SKCore.framework */; }; 26D1C4CE1EE4653600C95954 /* SKWebAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C4CB1EE4653600C95954 /* SKWebAPI.framework */; }; 26D1C4CF1EE4653600C95954 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C4CC1EE4653600C95954 /* Starscream.framework */; }; @@ -25,6 +28,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 2604C59B202BFD83009CDBAF /* StarscreamRTM.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarscreamRTM.swift; sourceTree = ""; }; 2684F17D1E95AA6900536DCC /* SKRTMAPI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SKRTMAPI.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2684F1E41E95ABD400536DCC /* SKRTMAPI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SKRTMAPI.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2684F2081E95ABD600536DCC /* SKRTMAPI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SKRTMAPI.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -150,6 +154,7 @@ 26DC0EAF1E95BED900991BDF /* Conformers */ = { isa = PBXGroup; children = ( + 2604C59B202BFD83009CDBAF /* StarscreamRTM.swift */, 26DC0EB11E95BED900991BDF /* VaporEngineRTM.swift */, D2C085F12024BF9600FEC5AB /* WebSocketFactory.swift */, ); @@ -355,6 +360,7 @@ buildActionMask = 2147483647; files = ( 26DC0EB61E95BED900991BDF /* VaporEngineRTM.swift in Sources */, + 2604C59C202BFD83009CDBAF /* StarscreamRTM.swift in Sources */, 26DC0EB91E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -364,6 +370,7 @@ buildActionMask = 2147483647; files = ( 26DC0EB71E95BED900991BDF /* VaporEngineRTM.swift in Sources */, + 2604C59D202BFD83009CDBAF /* StarscreamRTM.swift in Sources */, 26DC0EBA1E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -373,6 +380,7 @@ buildActionMask = 2147483647; files = ( 26DC0EB81E95BED900991BDF /* VaporEngineRTM.swift in Sources */, + 2604C59E202BFD83009CDBAF /* StarscreamRTM.swift in Sources */, 26DC0EBB1E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Sources/SKRTMAPI/Conformers/VaporEngineRTM.swift b/Sources/SKRTMAPI/Conformers/VaporEngineRTM.swift index 5bd5214..c80ee32 100644 --- a/Sources/SKRTMAPI/Conformers/VaporEngineRTM.swift +++ b/Sources/SKRTMAPI/Conformers/VaporEngineRTM.swift @@ -21,6 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#if os(Linux) import Dispatch import Foundation import SKCore @@ -75,3 +76,4 @@ public class VaporEngineRTM: RTMWebSocket { self.webSocket = webSocket } } +#endif diff --git a/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift b/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift index 71d6247..9dff507 100644 --- a/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift +++ b/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift @@ -1,3 +1,4 @@ +#if os(Linux) import WebSockets import HTTP import Sockets @@ -63,3 +64,4 @@ public final class WebSocketFactory { ) } } +#endif diff --git a/Sources/SKRTMAPI/SKRTMAPI.swift b/Sources/SKRTMAPI/SKRTMAPI.swift index 7e799df..2a9b885 100644 --- a/Sources/SKRTMAPI/SKRTMAPI.swift +++ b/Sources/SKRTMAPI/SKRTMAPI.swift @@ -62,7 +62,11 @@ public final class SKRTMAPI: RTMDelegate { if let rtm = rtm { self.rtm = rtm } else { - self.rtm = VaporEngineRTM() + #if os(Linux) + self.rtm = VaporEngineRTM() + #else + self.rtm = StarscreamRTM() + #endif } self.rtm.delegate = self } From d1a011a2cc77ad7a366df5324a88fa4764bc189a Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Wed, 7 Feb 2018 22:56:43 -0500 Subject: [PATCH 4/4] Revert change --- Sources/SKRTMAPI/SKRTMAPI.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/SKRTMAPI/SKRTMAPI.swift b/Sources/SKRTMAPI/SKRTMAPI.swift index 2a9b885..781c1a0 100644 --- a/Sources/SKRTMAPI/SKRTMAPI.swift +++ b/Sources/SKRTMAPI/SKRTMAPI.swift @@ -21,7 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#if os(Linux) import Dispatch +#endif import Foundation import SKWebAPI @_exported import SKCore