Compare commits

...

17 Commits

Author SHA1 Message Date
Erik Little
42da871d93
update readme 2024-10-01 12:32:32 -04:00
Erik Little
03032d0c72
Update some more deps; bump version 2024-10-01 12:30:52 -04:00
Erik Little
d690d9c1bf
Merge pull request #1464 from socketio/development
v16.1.1
2024-10-01 12:28:07 -04:00
Erik Little
99cc2448f7
Merge pull request #1467 from olejnjak/xcode15
Xcode 15 support
2024-10-01 12:16:49 -04:00
Erik Little
99b673dfa5
Merge pull request #1491 from hsjcom/master
Fix the issue where it takes over 60 seconds to close the socket after a network disconnection
2024-10-01 12:15:25 -04:00
Erik Little
b4bff5db90
Merge pull request #1492 from xxZap/master
Support Privacy Manifest: bump Starscream package version to upToNextMajor 4.0.8
2024-10-01 12:14:08 -04:00
Shaojie Hong
354ed7e5e4
Update SocketEngine.swift
Fix the issue where it takes over 60 seconds to close the socket after a network disconnection, and the problem where the server-side socket takes over 30 seconds to close when the server ends a connection
2024-05-09 16:58:16 +08:00
Alessio Zap Boerio
5ecc5bbae9 Bump Starscream version to upToNextMajor 4.0.8 2024-04-15 13:39:56 +02:00
Erik Little
d069bbeefe
Merge pull request #1482 from elefantel/patch-1
Bump minimum deployment target to iOS 12 to match Starscream dependency
2024-03-18 09:11:26 -04:00
Mpendulo Ndlovu
eb806b62bf
Bump minimum deployment target to iOS 12 to match Starscream dependency
Currently there is an error when compiling for release:
```
Compiling for iOS 11.0, but module 'Starscream' has a minimum deployment target of iOS 12.0
```

This pull request addresses this error by bumping the minimum deployment target to match Starscream.
2024-03-18 11:18:13 +02:00
Jakub Olejnik
6dd51170bb Bump Carthage deployment targets 2023-11-21 16:24:22 +01:00
Erik Little
76b941933e
Merge pull request #1463 from davidkessler-ch/master
fix never running timingOut due to weak self capture
2023-11-13 15:40:51 -05:00
Erik Little
71a627c099
Merge pull request #1375 from emersonsoftware/fix_reconnect_issue
Handling reconnect scenarios properly when socket is hung
2023-11-13 15:40:16 -05:00
David K
a21af1016e
fix never running timingOut due to weak self capture 2023-11-10 23:49:06 +01:00
Erik Little
85585c42c0
Merge pull request #1437 from humanfriend22/type-patch-1
Typo in README example code
2023-08-28 14:52:04 -04:00
humanfriend22
8837d4a0d8 correct SocketActStatus in example code 2023-03-10 04:03:36 +00:00
Mark Schisler
ec4378ca49
Handling reconnect scenarios properly when socket is hung 2021-08-19 09:45:54 -05:00
15 changed files with 85 additions and 26 deletions

2
.gitignore vendored
View File

@ -50,3 +50,5 @@ Socket.IO-Test-Server/node_modules/*
.idea/ .idea/
docs/docsets/ docs/docsets/
docs/undocumented.json docs/undocumented.json
.swiftpm

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View File

@ -1 +1 @@
github "daltoniam/Starscream" ~> 4.0.6 github "daltoniam/Starscream" ~> 4.0.8

View File

@ -1 +1 @@
github "daltoniam/Starscream" "4.0.6" github "daltoniam/Starscream" "4.0.8"

View File

@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/daltoniam/Starscream", "repositoryURL": "https://github.com/daltoniam/Starscream",
"state": { "state": {
"branch": null, "branch": null,
"revision": "ac6c0fc9da221873e01bd1a0d4818498a71eef33", "revision": "c6bfd1af48efcc9a9ad203665db12375ba6b145a",
"version": "4.0.6" "version": "4.0.8"
} }
} }
] ]

View File

@ -8,7 +8,7 @@ let package = Package(
.library(name: "SocketIO", targets: ["SocketIO"]) .library(name: "SocketIO", targets: ["SocketIO"])
], ],
dependencies: [ dependencies: [
.package(url: "https://github.com/daltoniam/Starscream", .exactItem("4.0.6")), .package(url: "https://github.com/daltoniam/Starscream", .upToNextMajor(from: "4.0.8")),
], ],
targets: [ targets: [
.target(name: "SocketIO", dependencies: ["Starscream"]), .target(name: "SocketIO", dependencies: ["Starscream"]),

View File

@ -18,7 +18,7 @@ socket.on("currentAmount") {data, ack in
guard let cur = data[0] as? Double else { return } guard let cur = data[0] as? Double else { return }
socket.emitWithAck("canUpdate", cur).timingOut(after: 0) {data in socket.emitWithAck("canUpdate", cur).timingOut(after: 0) {data in
if data.first as? String ?? "passed" == SocketAckValue.noAck { if data.first as? String ?? "passed" == SocketAckStatus.noAck {
// Handle ack timeout // Handle ack timeout
} }
@ -61,7 +61,7 @@ let package = Package(
.executable(name: "socket.io-test", targets: ["YourTargetName"]) .executable(name: "socket.io-test", targets: ["YourTargetName"])
], ],
dependencies: [ dependencies: [
.package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "15.0.0")) .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "16.1.1"))
], ],
targets: [ targets: [
.target(name: "YourTargetName", dependencies: ["SocketIO"], path: "./Path/To/Your/Sources") .target(name: "YourTargetName", dependencies: ["SocketIO"], path: "./Path/To/Your/Sources")
@ -74,7 +74,7 @@ Then import `import SocketIO`.
### Carthage ### Carthage
Add this line to your `Cartfile`: Add this line to your `Cartfile`:
``` ```
github "socketio/socket.io-client-swift" ~> 15.2.0 github "socketio/socket.io-client-swift" ~> 16.1.1
``` ```
Run `carthage update --platform ios,macosx`. Run `carthage update --platform ios,macosx`.
@ -88,7 +88,7 @@ Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`:
use_frameworks! use_frameworks!
target 'YourApp' do target 'YourApp' do
pod 'Socket.IO-Client-Swift', '~> 15.2.0' pod 'Socket.IO-Client-Swift', '~> 16.1.1'
end end
``` ```

View File

@ -1,7 +1,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "Socket.IO-Client-Swift" s.name = "Socket.IO-Client-Swift"
s.module_name = "SocketIO" s.module_name = "SocketIO"
s.version = "16.1.0" s.version = "16.1.1"
s.summary = "Socket.IO-client for iOS and OS X" s.summary = "Socket.IO-client for iOS and OS X"
s.description = <<-DESC s.description = <<-DESC
Socket.IO-client for iOS and OS X. Socket.IO-client for iOS and OS X.
@ -11,14 +11,14 @@ Pod::Spec.new do |s|
s.homepage = "https://github.com/socketio/socket.io-client-swift" s.homepage = "https://github.com/socketio/socket.io-client-swift"
s.license = { :type => 'MIT' } s.license = { :type => 'MIT' }
s.author = { "Erik" => "nuclear.ace@gmail.com" } s.author = { "Erik" => "nuclear.ace@gmail.com" }
s.ios.deployment_target = '11.0' s.ios.deployment_target = '12.0'
s.osx.deployment_target = '10.13' s.osx.deployment_target = '10.13'
s.tvos.deployment_target = '12.0' s.tvos.deployment_target = '12.0'
s.watchos.deployment_target = '5.0' s.watchos.deployment_target = '5.0'
s.requires_arc = true s.requires_arc = true
s.source = { s.source = {
:git => "https://github.com/socketio/socket.io-client-swift.git", :git => "https://github.com/socketio/socket.io-client-swift.git",
:tag => 'v16.1.0', :tag => 'v16.1.1',
:submodules => true :submodules => true
} }
@ -27,5 +27,5 @@ Pod::Spec.new do |s|
'SWIFT_VERSION' => '5.4' 'SWIFT_VERSION' => '5.4'
} }
s.source_files = "Source/SocketIO/**/*.swift", "Source/SocketIO/*.swift" s.source_files = "Source/SocketIO/**/*.swift", "Source/SocketIO/*.swift"
s.dependency "Starscream", "~> 4.0.6" s.dependency "Starscream", "~> 4.0.8"
end end

View File

@ -652,6 +652,7 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = SocketIO/Info.plist; INFOPLIST_FILE = SocketIO/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -678,7 +679,7 @@
SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4,7"; TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
TVOS_DEPLOYMENT_TARGET = 10.0; TVOS_DEPLOYMENT_TARGET = 12.0;
VALID_ARCHS = "$(inherited)"; VALID_ARCHS = "$(inherited)";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
@ -728,6 +729,7 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = SocketIO/Info.plist; INFOPLIST_FILE = SocketIO/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -752,7 +754,7 @@
SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4,7"; TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
TVOS_DEPLOYMENT_TARGET = 10.0; TVOS_DEPLOYMENT_TARGET = 12.0;
VALID_ARCHS = "$(inherited)"; VALID_ARCHS = "$(inherited)";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
@ -832,7 +834,7 @@
"@loader_path/../Frameworks", "@loader_path/../Frameworks",
); );
LIBRARY_SEARCH_PATHS = "$(inherited)"; LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = 10.10; MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)";
@ -842,7 +844,7 @@
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 10.0; TVOS_DEPLOYMENT_TARGET = 12.0;
VALID_ARCHS = "$(inherited)"; VALID_ARCHS = "$(inherited)";
}; };
name = Debug; name = Debug;
@ -914,7 +916,7 @@
"@loader_path/../Frameworks", "@loader_path/../Frameworks",
); );
LIBRARY_SEARCH_PATHS = "$(inherited)"; LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = 10.10; MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
@ -922,7 +924,7 @@
SUPPORTED_PLATFORMS = "$(inherited)"; SUPPORTED_PLATFORMS = "$(inherited)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 10.0; TVOS_DEPLOYMENT_TARGET = 12.0;
VALID_ARCHS = "$(inherited)"; VALID_ARCHS = "$(inherited)";
}; };
name = Release; name = Release;

View File

@ -136,8 +136,8 @@ public final class OnAckCallback: NSObject {
guard seconds != 0 else { return } guard seconds != 0 else { return }
socket.manager?.handleQueue.asyncAfter(deadline: DispatchTime.now() + seconds) {[weak socket, weak self] in socket.manager?.handleQueue.asyncAfter(deadline: DispatchTime.now() + seconds) {[weak socket] in
guard let socket = socket, let `self` = self else { return } guard let socket = socket else { return }
socket.ackHandlers.timeoutAck(self.ackNumber) socket.ackHandlers.timeoutAck(self.ackNumber)
} }

View File

@ -150,7 +150,8 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
manager.handleQueue.asyncAfter(deadline: DispatchTime.now() + timeoutAfter) {[weak self] in manager.handleQueue.asyncAfter(deadline: DispatchTime.now() + timeoutAfter) {[weak self] in
guard let this = self, this.status == .connecting || this.status == .notConnected else { return } guard let this = self, this.status == .connecting || this.status == .notConnected else { return }
DefaultSocketLogger.Logger.log("Timeout: Socket not connected, so setting to disconnected", type: this.logType)
this.status = .disconnected this.status = .disconnected
this.leaveNamespace() this.leaveNamespace()

View File

@ -761,6 +761,12 @@ extension SocketEngine {
case .disconnected(_, _): case .disconnected(_, _):
wsConnected = false wsConnected = false
websocketDidDisconnect(error: nil) websocketDidDisconnect(error: nil)
case .viabilityChanged(false):
wsConnected = false
websocketDidDisconnect(error: nil)
case .peerClosed:
wsConnected = false
websocketDidDisconnect(error: nil)
case let .text(msg): case let .text(msg):
parseEngineMessage(msg) parseEngineMessage(msg)
case let .binary(data): case let .binary(data):

View File

@ -132,7 +132,7 @@ open class SocketManager: NSObject, SocketManagerSpec, SocketParsable, SocketDat
private(set) var reconnectAttempts = -1 private(set) var reconnectAttempts = -1
private var _config: SocketIOClientConfiguration private var _config: SocketIOClientConfiguration
private var currentReconnectAttempt = 0 internal var currentReconnectAttempt = 0
private var reconnecting = false private var reconnecting = false
// MARK: Initializers // MARK: Initializers
@ -186,9 +186,8 @@ open class SocketManager: NSObject, SocketManagerSpec, SocketParsable, SocketDat
/// ///
/// Override if you wish to attach a custom `SocketEngineSpec`. /// Override if you wish to attach a custom `SocketEngineSpec`.
open func connect() { open func connect() {
guard !status.active else { if status == .connected || (status == .connecting && currentReconnectAttempt == 0) {
DefaultSocketLogger.Logger.log("Tried connecting an already active socket", type: SocketManager.logType) DefaultSocketLogger.Logger.log("Tried connecting an already active socket", type: SocketManager.logType)
return return
} }

View File

@ -60,6 +60,44 @@ class SocketMangerTest : XCTestCase {
waitForExpectations(timeout: 0.3) waitForExpectations(timeout: 0.3)
} }
func testManagerDoesNotCallConnectWhenConnectingWithLessThanOneReconnect() {
setUpSockets()
let expect = expectation(description: "The manager should not call connect on the engine")
expect.isInverted = true
let engine = TestEngine(client: manager, url: manager.socketURL, options: nil)
engine.onConnect = {
expect.fulfill()
}
manager.setTestStatus(.connecting)
manager.setCurrentReconnect(currentReconnect: 0)
manager.engine = engine
manager.connect()
waitForExpectations(timeout: 0.3)
}
func testManagerCallConnectWhenConnectingAndMoreThanOneReconnect() {
setUpSockets()
let expect = expectation(description: "The manager should call connect on the engine")
let engine = TestEngine(client: manager, url: manager.socketURL, options: nil)
engine.onConnect = {
expect.fulfill()
}
manager.setTestStatus(.connecting)
manager.setCurrentReconnect(currentReconnect: 1)
manager.engine = engine
manager.connect()
waitForExpectations(timeout: 0.8)
}
func testManagerCallsDisconnect() { func testManagerCallsDisconnect() {
setUpSockets() setUpSockets()
@ -154,6 +192,10 @@ public enum ManagerExpectation: String {
} }
public class TestManager: SocketManager { public class TestManager: SocketManager {
public func setCurrentReconnect(currentReconnect: Int) {
self.currentReconnectAttempt = currentReconnect
}
public override func disconnect() { public override func disconnect() {
setTestStatus(.disconnected) setTestStatus(.disconnected)
} }

View File

@ -487,7 +487,7 @@ class TestEngine: SocketEngineSpec {
private(set) var ws: WebSocket? = nil private(set) var ws: WebSocket? = nil
private(set) var version = SocketIOVersion.three private(set) var version = SocketIOVersion.three
fileprivate var onConnect: (() -> ())? internal var onConnect: (() -> ())?
required init(client: SocketEngineClient, url: URL, options: [String: Any]?) { required init(client: SocketEngineClient, url: URL, options: [String: Any]?) {
self.client = client self.client = client