Skip to content

Commit

Permalink
Merge pull request #1464 from socketio/development
Browse files Browse the repository at this point in the history
v16.1.1
  • Loading branch information
nuclearace authored Oct 1, 2024
2 parents 175da8b + 99cc244 commit d690d9c
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ Socket.IO-Test-Server/node_modules/*
.idea/
docs/docsets/
docs/undocumented.json

.swiftpm
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/daltoniam/Starscream",
"state": {
"branch": null,
"revision": "ac6c0fc9da221873e01bd1a0d4818498a71eef33",
"version": "4.0.6"
"revision": "c6bfd1af48efcc9a9ad203665db12375ba6b145a",
"version": "4.0.8"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let package = Package(
.library(name: "SocketIO", targets: ["SocketIO"])
],
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: [
.target(name: "SocketIO", dependencies: ["Starscream"]),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ socket.on("currentAmount") {data, ack in
guard let cur = data[0] as? Double else { return }

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
}

Expand Down
2 changes: 1 addition & 1 deletion Socket.IO-Client-Swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.homepage = "https://github.com/socketio/socket.io-client-swift"
s.license = { :type => 'MIT' }
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.tvos.deployment_target = '12.0'
s.watchos.deployment_target = '5.0'
Expand Down
14 changes: 8 additions & 6 deletions Socket.IO-Client-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = SocketIO/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -678,7 +679,7 @@
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VALID_ARCHS = "$(inherited)";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -728,6 +729,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = SocketIO/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -752,7 +754,7 @@
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VALID_ARCHS = "$(inherited)";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -832,7 +834,7 @@
"@loader_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -842,7 +844,7 @@
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VALID_ARCHS = "$(inherited)";
};
name = Debug;
Expand Down Expand Up @@ -914,15 +916,15 @@
"@loader_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SUPPORTED_PLATFORMS = "$(inherited)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
VALID_ARCHS = "$(inherited)";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions Source/SocketIO/Ack/SocketAckEmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public final class OnAckCallback: NSObject {

guard seconds != 0 else { return }

socket.manager?.handleQueue.asyncAfter(deadline: DispatchTime.now() + seconds) {[weak socket, weak self] in
guard let socket = socket, let `self` = self else { return }
socket.manager?.handleQueue.asyncAfter(deadline: DispatchTime.now() + seconds) {[weak socket] in
guard let socket = socket else { return }

socket.ackHandlers.timeoutAck(self.ackNumber)
}
Expand Down
3 changes: 2 additions & 1 deletion Source/SocketIO/Client/SocketIOClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {

manager.handleQueue.asyncAfter(deadline: DispatchTime.now() + timeoutAfter) {[weak self] in
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.leaveNamespace()

Expand Down
6 changes: 6 additions & 0 deletions Source/SocketIO/Engine/SocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,12 @@ extension SocketEngine {
case .disconnected(_, _):
wsConnected = false
websocketDidDisconnect(error: nil)
case .viabilityChanged(false):
wsConnected = false
websocketDidDisconnect(error: nil)
case .peerClosed:
wsConnected = false
websocketDidDisconnect(error: nil)
case let .text(msg):
parseEngineMessage(msg)
case let .binary(data):
Expand Down
5 changes: 2 additions & 3 deletions Source/SocketIO/Manager/SocketManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ open class SocketManager: NSObject, SocketManagerSpec, SocketParsable, SocketDat
private(set) var reconnectAttempts = -1

private var _config: SocketIOClientConfiguration
private var currentReconnectAttempt = 0
internal var currentReconnectAttempt = 0
private var reconnecting = false

// MARK: Initializers
Expand Down Expand Up @@ -186,9 +186,8 @@ open class SocketManager: NSObject, SocketManagerSpec, SocketParsable, SocketDat
///
/// Override if you wish to attach a custom `SocketEngineSpec`.
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)

return
}

Expand Down
42 changes: 42 additions & 0 deletions Tests/TestSocketIO/SocketMangerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,44 @@ class SocketMangerTest : XCTestCase {
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() {
setUpSockets()

Expand Down Expand Up @@ -154,6 +192,10 @@ public enum ManagerExpectation: String {
}

public class TestManager: SocketManager {
public func setCurrentReconnect(currentReconnect: Int) {
self.currentReconnectAttempt = currentReconnect
}

public override func disconnect() {
setTestStatus(.disconnected)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestSocketIO/SocketSideEffectTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class TestEngine: SocketEngineSpec {
private(set) var ws: WebSocket? = nil
private(set) var version = SocketIOVersion.three

fileprivate var onConnect: (() -> ())?
internal var onConnect: (() -> ())?

required init(client: SocketEngineClient, url: URL, options: [String: Any]?) {
self.client = client
Expand Down

0 comments on commit d690d9c

Please sign in to comment.