Skip to content

Commit 41af615

Browse files
committed
Merge branch 'development'
* development: Add note about manager not being thread safe Make it clear that `handleQueue` should be serial remove some redundant connected checking get rid of internal emitAck method open engine Add raw view to ack emitter change access level to public for raw view rename SocketBinaryView Add rawEmitView. Implements #992 Add way to skip binary inspection. bump version Set reconnectAttempts in manager. Fixes #989
2 parents 731aaf4 + 4ea1bb9 commit 41af615

15 files changed

+269
-50
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: objective-c
22
xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder
33
xcode_scheme: SocketIO-Mac
4-
osx_image: xcode9
4+
osx_image: xcode9.2
55
branches:
66
only:
77
- master

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# v13.2.0
2+
3+
- Add ability to bypass Data inspection in emits. [#992]((https://github.com/socketio/socket.io-client-swift/issues/992))
4+
- Allow `SocketEngine` to be subclassed
5+
6+
# v13.1.3
7+
8+
- Fix setting reconnectAttempts [#989]((https://github.com/socketio/socket.io-client-swift/issues/989))
9+
10+
111
# v13.1.2
212

313
- Fix [#950](https://github.com/socketio/socket.io-client-swift/issues/950)
@@ -29,7 +39,7 @@ Checkout out the migration guide in Usage Docs for a more detailed guide on how
2939
What's new:
3040
---
3141

32-
- Adds a new `SocketManager` class that multiplexes multiple namespaces through a single engine.
42+
- Adds a new `SocketManager` class that multiplexes multiple namespaces through a single engine.
3343
- Adds `.sentPing` and `.gotPong` client events for tracking ping/pongs.
3444
- watchOS support.
3545

Package.resolved

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
{
22
"object": {
33
"pins": [
4-
{
5-
"package": "SSCZLib",
6-
"repositoryURL": "https://github.com/daltoniam/zlib-spm.git",
7-
"state": {
8-
"branch": null,
9-
"revision": "83ac8d719a2f3aa775dbdf116a57f56fb2c49abb",
10-
"version": "1.1.0"
11-
}
12-
},
134
{
145
"package": "SSCommonCrypto",
156
"repositoryURL": "https://github.com/daltoniam/common-crypto-spm",
@@ -27,6 +18,15 @@
2718
"revision": "6cb1c474e09b0a3aa60bcdc7553b570336d6a61a",
2819
"version": "3.0.3"
2920
}
21+
},
22+
{
23+
"package": "SSCZLib",
24+
"repositoryURL": "https://github.com/daltoniam/zlib-spm.git",
25+
"state": {
26+
"branch": null,
27+
"revision": "83ac8d719a2f3aa775dbdf116a57f56fb2c49abb",
28+
"version": "1.1.0"
29+
}
3030
}
3131
]
3232
},

Socket.IO-Client-Swift.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Socket.IO-Client-Swift"
33
s.module_name = "SocketIO"
4-
s.version = "13.1.2"
4+
s.version = "13.1.3"
55
s.summary = "Socket.IO-client for iOS and OS X"
66
s.description = <<-DESC
77
Socket.IO-client for iOS and OS X.
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
1818
s.requires_arc = true
1919
s.source = {
2020
:git => "https://github.com/socketio/socket.io-client-swift.git",
21-
:tag => 'v13.1.2',
21+
:tag => 'v13.1.3',
2222
:submodules => true
2323
}
2424
s.pod_target_xcconfig = {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
1C6572803D7E252A77A86E5F /* SocketManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C65763817782DFAC67BE05C /* SocketManager.swift */; };
11+
1C6573B22DC9423CDFC32F05 /* SocketRawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C657533E849FC3E4342C602 /* SocketRawView.swift */; };
1112
1C657FBB3F670261780FD72E /* SocketManagerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C6574AF9687A213814753E4 /* SocketManagerSpec.swift */; };
1213
1C686BE21F869AFD007D8627 /* SocketIOClientConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C686BD21F869AF1007D8627 /* SocketIOClientConfigurationTest.swift */; };
1314
1C686BE31F869AFD007D8627 /* SocketEngineTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C686BD31F869AF1007D8627 /* SocketEngineTest.swift */; };
@@ -61,6 +62,7 @@
6162

6263
/* Begin PBXFileReference section */
6364
1C6574AF9687A213814753E4 /* SocketManagerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketManagerSpec.swift; sourceTree = "<group>"; };
65+
1C657533E849FC3E4342C602 /* SocketRawView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketRawView.swift; sourceTree = "<group>"; };
6466
1C65763817782DFAC67BE05C /* SocketManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketManager.swift; sourceTree = "<group>"; };
6567
1C686BD21F869AF1007D8627 /* SocketIOClientConfigurationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketIOClientConfigurationTest.swift; sourceTree = "<group>"; };
6668
1C686BD31F869AF1007D8627 /* SocketEngineTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketEngineTest.swift; sourceTree = "<group>"; };
@@ -300,6 +302,7 @@
300302
DD52B078DB0A3C3D1BB507CD /* SocketIOClientOption.swift */,
301303
DD52B1D9BC4AE46D38D827DE /* SocketIOStatus.swift */,
302304
DD52B57FFEE8560CFFD793B3 /* SocketIOClientConfiguration.swift */,
305+
1C657533E849FC3E4342C602 /* SocketRawView.swift */,
303306
);
304307
name = Client;
305308
path = Source/SocketIO/Client;
@@ -480,6 +483,7 @@
480483
DD52B9412F660F828B683422 /* SocketParsable.swift in Sources */,
481484
1C6572803D7E252A77A86E5F /* SocketManager.swift in Sources */,
482485
1C657FBB3F670261780FD72E /* SocketManagerSpec.swift in Sources */,
486+
1C6573B22DC9423CDFC32F05 /* SocketRawView.swift in Sources */,
483487
);
484488
runOnlyForDeploymentPostprocessing = 0;
485489
};

Source/SocketIO/Ack/SocketAckEmitter.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,20 @@ import Foundation
2929
///
3030
/// **NOTE**: You should not store this beyond the life of the event handler.
3131
public final class SocketAckEmitter : NSObject {
32-
let socket: SocketIOClient
33-
let ackNum: Int
32+
private unowned let socket: SocketIOClient
33+
private let ackNum: Int
34+
35+
/// A view into this emitter where emits do not check for binary data.
36+
///
37+
/// Usage:
38+
///
39+
/// ```swift
40+
/// ack.rawEmitView.with(myObject)
41+
/// ```
42+
///
43+
/// **NOTE**: It is not safe to hold on to this view beyond the life of the socket.
44+
@objc
45+
public private(set) lazy var rawEmitView = SocketRawAckView(socket: socket, ackNum: ackNum)
3446

3547
// MARK: Properties
3648

@@ -91,13 +103,16 @@ public final class SocketAckEmitter : NSObject {
91103
/// ```
92104
public final class OnAckCallback : NSObject {
93105
private let ackNumber: Int
106+
private let binary: Bool
94107
private let items: [Any]
108+
95109
private weak var socket: SocketIOClient?
96110

97-
init(ackNumber: Int, items: [Any], socket: SocketIOClient) {
111+
init(ackNumber: Int, items: [Any], socket: SocketIOClient, binary: Bool = true) {
98112
self.ackNumber = ackNumber
99113
self.items = items
100114
self.socket = socket
115+
self.binary = binary
101116
}
102117

103118
deinit {
@@ -116,7 +131,7 @@ public final class OnAckCallback : NSObject {
116131
guard let socket = self.socket, ackNumber != -1 else { return }
117132

118133
socket.ackHandlers.addAck(ackNumber, callback: callback)
119-
socket.emit(items, ack: ackNumber)
134+
socket.emit(items, ack: ackNumber, binary: binary)
120135

121136
guard seconds != 0 else { return }
122137

Source/SocketIO/Client/SocketIOClient.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
6767
@objc
6868
public private(set) weak var manager: SocketManagerSpec?
6969

70+
/// A view into this socket where emits do not check for binary data.
71+
///
72+
/// Usage:
73+
///
74+
/// ```swift
75+
/// socket.rawEmitView.emit("myEvent", myObject)
76+
/// ```
77+
///
78+
/// **NOTE**: It is not safe to hold on to this view beyond the life of the socket.
79+
@objc
80+
public private(set) lazy var rawEmitView = SocketRawView(socket: self)
81+
7082
/// The status of this client.
7183
@objc
7284
public private(set) var status = SocketIOStatus.notConnected {
@@ -148,7 +160,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
148160
}
149161
}
150162

151-
private func createOnAck(_ items: [Any]) -> OnAckCallback {
163+
func createOnAck(_ items: [Any], binary: Bool = true) -> OnAckCallback {
152164
currentAck += 1
153165

154166
return OnAckCallback(ackNumber: currentAck, items: items, socket: self)
@@ -216,11 +228,6 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
216228
/// - parameter items: The items to send with this event. Send an empty array to send no data.
217229
@objc
218230
open func emit(_ event: String, with items: [Any]) {
219-
guard status == .connected else {
220-
handleClientEvent(.error, data: ["Tried emitting \(event) when not connected"])
221-
return
222-
}
223-
224231
emit([event] + items)
225232
}
226233

@@ -277,16 +284,16 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
277284
return createOnAck([event] + items)
278285
}
279286

280-
func emit(_ data: [Any], ack: Int? = nil) {
287+
func emit(_ data: [Any], ack: Int? = nil, binary: Bool = true, isAck: Bool = false) {
281288
guard status == .connected else {
282289
handleClientEvent(.error, data: ["Tried emitting when not connected"])
283290
return
284291
}
285292

286-
let packet = SocketPacket.packetFromEmit(data, id: ack ?? -1, nsp: nsp, ack: false)
293+
let packet = SocketPacket.packetFromEmit(data, id: ack ?? -1, nsp: nsp, ack: isAck, checkForBinary: binary)
287294
let str = packet.packetString
288295

289-
DefaultSocketLogger.Logger.log("Emitting: \(str)", type: logType)
296+
DefaultSocketLogger.Logger.log("Emitting: \(str), Ack: \(isAck)", type: logType)
290297

291298
manager?.engine?.send(str, withData: packet.binary)
292299
}
@@ -298,14 +305,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
298305
/// - parameter ack: The ack number.
299306
/// - parameter with: The data for this ack.
300307
open func emitAck(_ ack: Int, with items: [Any]) {
301-
guard status == .connected else { return }
302-
303-
let packet = SocketPacket.packetFromEmit(items, id: ack, nsp: nsp, ack: true)
304-
let str = packet.packetString
305-
306-
DefaultSocketLogger.Logger.log("Emitting Ack: \(str)", type: logType)
307-
308-
manager?.engine?.send(str, withData: packet.binary)
308+
emit(items, ack: ack, binary: true, isAck: true)
309309
}
310310

311311
/// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called.

Source/SocketIO/Client/SocketIOClientOption.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public enum SocketIOClientOption : ClientOption {
5555

5656
/// The queue that all interaction with the client should occur on. This is the queue that event handlers are
5757
/// called on.
58+
///
59+
/// **This should be a serial queue! Concurrent queues are not supported and might cause crashes and races**.
5860
case handleQueue(DispatchQueue)
5961

6062
/// If passed `true`, the client will log debug information. This should be turned off in production code.

Source/SocketIO/Client/SocketIOClientSpec.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ public protocol SocketIOClientSpec : class {
4343
/// **Must** start with a `/`.
4444
var nsp: String { get }
4545

46+
/// A view into this socket where emits do not check for binary data.
47+
///
48+
/// Usage:
49+
///
50+
/// ```swift
51+
/// socket.rawEmitView.emit("myEvent", myObject)
52+
/// ```
53+
///
54+
/// **NOTE**: It is not safe to hold on to this view beyond the life of the socket.
55+
var rawEmitView: SocketRawView { get }
56+
4657
/// The status of this client.
4758
var status: SocketIOStatus { get }
4859

0 commit comments

Comments
 (0)