diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index cf7e6e25..f5b648dd 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 1C6572803D7E252A77A86E5F /* SocketManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C65763817782DFAC67BE05C /* SocketManager.swift */; }; 1C6573B22DC9423CDFC32F05 /* SocketRawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C657533E849FC3E4342C602 /* SocketRawView.swift */; }; + 1C657CDE5D510E8E2E573E39 /* utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C6577B639C34EE1C8829D9A /* utils.swift */; }; 1C657FBB3F670261780FD72E /* SocketManagerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C6574AF9687A213814753E4 /* SocketManagerSpec.swift */; }; 1C686BE21F869AFD007D8627 /* SocketIOClientConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C686BD21F869AF1007D8627 /* SocketIOClientConfigurationTest.swift */; }; 1C686BE31F869AFD007D8627 /* SocketEngineTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C686BD31F869AF1007D8627 /* SocketEngineTest.swift */; }; @@ -64,6 +65,7 @@ 1C6574AF9687A213814753E4 /* SocketManagerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketManagerSpec.swift; sourceTree = ""; }; 1C657533E849FC3E4342C602 /* SocketRawView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketRawView.swift; sourceTree = ""; }; 1C65763817782DFAC67BE05C /* SocketManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketManager.swift; sourceTree = ""; }; + 1C6577B639C34EE1C8829D9A /* utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = utils.swift; sourceTree = ""; }; 1C686BD21F869AF1007D8627 /* SocketIOClientConfigurationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketIOClientConfigurationTest.swift; sourceTree = ""; }; 1C686BD31F869AF1007D8627 /* SocketEngineTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketEngineTest.swift; sourceTree = ""; }; 1C686BD41F869AF1007D8627 /* SocketSideEffectTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketSideEffectTest.swift; sourceTree = ""; }; @@ -159,6 +161,7 @@ 1C686BD71F869AF1007D8627 /* SocketParserTest.swift */, 1C686BD81F869AF1007D8627 /* SocketNamespacePacketTest.swift */, DD52BBAC5FAA7730D32CD5BF /* SocketMangerTest.swift */, + 1C6577B639C34EE1C8829D9A /* utils.swift */, ); name = TestSocketIO; path = Tests/TestSocketIO; @@ -501,6 +504,7 @@ 1C686BE81F869AFD007D8627 /* SocketNamespacePacketTest.swift in Sources */, DD52BCCD25EFA76E0F9B313C /* SocketMangerTest.swift in Sources */, DD52B53F2609D91A683DFCDD /* ManagerObjectiveCTest.m in Sources */, + 1C657CDE5D510E8E2E573E39 /* utils.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index b05b0ecb..0e558a87 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -83,7 +83,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { @objc public private(set) var status = SocketIOStatus.notConnected { didSet { - handleClientEvent(.statusChange, data: [status]) + handleClientEvent(.statusChange, data: [status, status.rawValue]) } } diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index 17cee736..de9f31ab 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -327,6 +327,9 @@ public enum SocketClientEvent : String { /// Emitted every time there is a change in the client's status. /// + /// The payload for data is [SocketIOClientStatus, Int]. Where the second item is the raw value. Use the second one + /// if you are working in Objective-C. + /// /// Usage: /// /// ```swift diff --git a/Tests/TestSocketIO/utils.swift b/Tests/TestSocketIO/utils.swift new file mode 100644 index 00000000..66d99acd --- /dev/null +++ b/Tests/TestSocketIO/utils.swift @@ -0,0 +1,13 @@ +// +// Created by Erik Little on 2019-01-11. +// + +import Foundation +@testable import SocketIO + +public class OBjcUtils: NSObject { + @objc + public static func setTestStatus(socket: SocketIOClient, status: SocketIOStatus) { + socket.setTestStatus(status) + } +} diff --git a/Tests/TestSocketIOObjc/SocketObjectiveCTest.m b/Tests/TestSocketIOObjc/SocketObjectiveCTest.m index 28c21b94..61412c12 100644 --- a/Tests/TestSocketIOObjc/SocketObjectiveCTest.m +++ b/Tests/TestSocketIOObjc/SocketObjectiveCTest.m @@ -7,6 +7,7 @@ // Merely tests whether the Objective-C api breaks // +#import "SocketIO_Tests-Swift.h" #import "SocketObjectiveCTest.h" @import Dispatch; @@ -73,11 +74,11 @@ - (void)testEmitWriteCompletionSyntax { - (void)testEmitWriteCompletion { XCTestExpectation* expect = [self expectationWithDescription:@"Write completion should be called"]; - + [self.socket emit:@"testEmit" with:@[@YES] completion:^{ [expect fulfill]; }]; - + [self waitForExpectationsWithTimeout:0.3 handler:nil]; } @@ -98,6 +99,19 @@ - (void)testSSLSecurity { sec = nil; } +- (void)testStatusChangeHandler { + XCTestExpectation* expect = [self expectationWithDescription:@"statusChange should be correctly called"]; + + [self.socket on:@"statusChange" callback:^(NSArray* data, SocketAckEmitter* ack) { + XCTAssertTrue([data[1] integerValue] == SocketIOStatusConnecting); + [expect fulfill]; + }]; + + [OBjcUtils setTestStatusWithSocket:self.socket status:SocketIOStatusConnecting]; + + [self waitForExpectationsWithTimeout:0.3 handler:nil]; +} + - (void)setUp { [super setUp]; NSURL* url = [[NSURL alloc] initWithString:@"http://localhost"];