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/.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..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 */; }; @@ -16,18 +19,16 @@ 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 */; }; /* 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; }; @@ -41,9 +42,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 +154,9 @@ 26DC0EAF1E95BED900991BDF /* Conformers */ = { isa = PBXGroup; children = ( - 26DC0EB01E95BED900991BDF /* StarscreamRTM.swift */, - 26DC0EB11E95BED900991BDF /* ZewoRTM.swift */, + 2604C59B202BFD83009CDBAF /* StarscreamRTM.swift */, + 26DC0EB11E95BED900991BDF /* VaporEngineRTM.swift */, + D2C085F12024BF9600FEC5AB /* WebSocketFactory.swift */, ); path = Conformers; sourceTree = ""; @@ -249,7 +251,7 @@ 2684F1741E95AA6900536DCC /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = "Peter Zignego"; TargetAttributes = { 2684F17C1E95AA6900536DCC = { @@ -357,8 +359,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 26DC0EB61E95BED900991BDF /* ZewoRTM.swift in Sources */, - 26DC0EB31E95BED900991BDF /* StarscreamRTM.swift in Sources */, + 26DC0EB61E95BED900991BDF /* VaporEngineRTM.swift in Sources */, + 2604C59C202BFD83009CDBAF /* StarscreamRTM.swift in Sources */, 26DC0EB91E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -367,8 +369,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 26DC0EB71E95BED900991BDF /* ZewoRTM.swift in Sources */, - 26DC0EB41E95BED900991BDF /* StarscreamRTM.swift in Sources */, + 26DC0EB71E95BED900991BDF /* VaporEngineRTM.swift in Sources */, + 2604C59D202BFD83009CDBAF /* StarscreamRTM.swift in Sources */, 26DC0EBA1E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -377,8 +379,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 26DC0EB81E95BED900991BDF /* ZewoRTM.swift in Sources */, - 26DC0EB51E95BED900991BDF /* StarscreamRTM.swift in Sources */, + 26DC0EB81E95BED900991BDF /* VaporEngineRTM.swift in Sources */, + 2604C59E202BFD83009CDBAF /* StarscreamRTM.swift in Sources */, 26DC0EBB1E95BED900991BDF /* SKRTMAPI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -396,7 +398,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 +408,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 +457,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 +467,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 +521,7 @@ PRODUCT_NAME = SKRTMAPI; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -534,7 +548,7 @@ PRODUCT_NAME = SKRTMAPI; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -561,7 +575,7 @@ PRODUCT_NAME = SKRTMAPI; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -588,7 +602,7 @@ PRODUCT_NAME = SKRTMAPI; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -614,7 +628,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 +655,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/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..c80ee32 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. // @@ -25,9 +25,9 @@ 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 +38,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,14 +65,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 } } diff --git a/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift b/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift new file mode 100644 index 0000000..9dff507 --- /dev/null +++ b/Sources/SKRTMAPI/Conformers/WebSocketFactory.swift @@ -0,0 +1,67 @@ +#if os(Linux) +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 + ) + } +} +#endif diff --git a/Sources/SKRTMAPI/SKRTMAPI.swift b/Sources/SKRTMAPI/SKRTMAPI.swift index e814059..781c1a0 100644 --- a/Sources/SKRTMAPI/SKRTMAPI.swift +++ b/Sources/SKRTMAPI/SKRTMAPI.swift @@ -65,7 +65,7 @@ public final class SKRTMAPI: RTMDelegate { self.rtm = rtm } else { #if os(Linux) - self.rtm = ZewoRTM() + self.rtm = VaporEngineRTM() #else self.rtm = StarscreamRTM() #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