Skip to content

Commit f407bea

Browse files
committed
Fix #1147
1 parent fa81fc2 commit f407bea

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

Socket.IO-Client-Swift.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1C6572803D7E252A77A86E5F /* SocketManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C65763817782DFAC67BE05C /* SocketManager.swift */; };
1111
1C6573B22DC9423CDFC32F05 /* SocketRawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C657533E849FC3E4342C602 /* SocketRawView.swift */; };
12+
1C657CDE5D510E8E2E573E39 /* utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C6577B639C34EE1C8829D9A /* utils.swift */; };
1213
1C657FBB3F670261780FD72E /* SocketManagerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C6574AF9687A213814753E4 /* SocketManagerSpec.swift */; };
1314
1C686BE21F869AFD007D8627 /* SocketIOClientConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C686BD21F869AF1007D8627 /* SocketIOClientConfigurationTest.swift */; };
1415
1C686BE31F869AFD007D8627 /* SocketEngineTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C686BD31F869AF1007D8627 /* SocketEngineTest.swift */; };
@@ -64,6 +65,7 @@
6465
1C6574AF9687A213814753E4 /* SocketManagerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketManagerSpec.swift; sourceTree = "<group>"; };
6566
1C657533E849FC3E4342C602 /* SocketRawView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketRawView.swift; sourceTree = "<group>"; };
6667
1C65763817782DFAC67BE05C /* SocketManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketManager.swift; sourceTree = "<group>"; };
68+
1C6577B639C34EE1C8829D9A /* utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = utils.swift; sourceTree = "<group>"; };
6769
1C686BD21F869AF1007D8627 /* SocketIOClientConfigurationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketIOClientConfigurationTest.swift; sourceTree = "<group>"; };
6870
1C686BD31F869AF1007D8627 /* SocketEngineTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketEngineTest.swift; sourceTree = "<group>"; };
6971
1C686BD41F869AF1007D8627 /* SocketSideEffectTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketSideEffectTest.swift; sourceTree = "<group>"; };
@@ -159,6 +161,7 @@
159161
1C686BD71F869AF1007D8627 /* SocketParserTest.swift */,
160162
1C686BD81F869AF1007D8627 /* SocketNamespacePacketTest.swift */,
161163
DD52BBAC5FAA7730D32CD5BF /* SocketMangerTest.swift */,
164+
1C6577B639C34EE1C8829D9A /* utils.swift */,
162165
);
163166
name = TestSocketIO;
164167
path = Tests/TestSocketIO;
@@ -501,6 +504,7 @@
501504
1C686BE81F869AFD007D8627 /* SocketNamespacePacketTest.swift in Sources */,
502505
DD52BCCD25EFA76E0F9B313C /* SocketMangerTest.swift in Sources */,
503506
DD52B53F2609D91A683DFCDD /* ManagerObjectiveCTest.m in Sources */,
507+
1C657CDE5D510E8E2E573E39 /* utils.swift in Sources */,
504508
);
505509
runOnlyForDeploymentPostprocessing = 0;
506510
};

Source/SocketIO/Client/SocketIOClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
8383
@objc
8484
public private(set) var status = SocketIOStatus.notConnected {
8585
didSet {
86-
handleClientEvent(.statusChange, data: [status])
86+
handleClientEvent(.statusChange, data: [status, status.rawValue])
8787
}
8888
}
8989

Source/SocketIO/Client/SocketIOClientSpec.swift

+3
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ public enum SocketClientEvent : String {
327327

328328
/// Emitted every time there is a change in the client's status.
329329
///
330+
/// The payload for data is [SocketIOClientStatus, Int]. Where the second item is the raw value. Use the second one
331+
/// if you are working in Objective-C.
332+
///
330333
/// Usage:
331334
///
332335
/// ```swift

Tests/TestSocketIO/utils.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Created by Erik Little on 2019-01-11.
3+
//
4+
5+
import Foundation
6+
@testable import SocketIO
7+
8+
public class OBjcUtils: NSObject {
9+
@objc
10+
public static func setTestStatus(socket: SocketIOClient, status: SocketIOStatus) {
11+
socket.setTestStatus(status)
12+
}
13+
}

Tests/TestSocketIOObjc/SocketObjectiveCTest.m

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// Merely tests whether the Objective-C api breaks
88
//
99

10+
#import "SocketIO_Tests-Swift.h"
1011
#import "SocketObjectiveCTest.h"
1112

1213
@import Dispatch;
@@ -73,11 +74,11 @@ - (void)testEmitWriteCompletionSyntax {
7374

7475
- (void)testEmitWriteCompletion {
7576
XCTestExpectation* expect = [self expectationWithDescription:@"Write completion should be called"];
76-
77+
7778
[self.socket emit:@"testEmit" with:@[@YES] completion:^{
7879
[expect fulfill];
7980
}];
80-
81+
8182
[self waitForExpectationsWithTimeout:0.3 handler:nil];
8283
}
8384

@@ -98,6 +99,19 @@ - (void)testSSLSecurity {
9899
sec = nil;
99100
}
100101

102+
- (void)testStatusChangeHandler {
103+
XCTestExpectation* expect = [self expectationWithDescription:@"statusChange should be correctly called"];
104+
105+
[self.socket on:@"statusChange" callback:^(NSArray* data, SocketAckEmitter* ack) {
106+
XCTAssertTrue([data[1] integerValue] == SocketIOStatusConnecting);
107+
[expect fulfill];
108+
}];
109+
110+
[OBjcUtils setTestStatusWithSocket:self.socket status:SocketIOStatusConnecting];
111+
112+
[self waitForExpectationsWithTimeout:0.3 handler:nil];
113+
}
114+
101115
- (void)setUp {
102116
[super setUp];
103117
NSURL* url = [[NSURL alloc] initWithString:@"http://localhost"];

0 commit comments

Comments
 (0)