Skip to content

Commit 313032a

Browse files
committed
Merge branch 'development'
* development: Fix socketio#882. Don't automatically remove sockets from nsps since they might be used again bump version Enable bitcode in debug Enable bitcode for select sdks simplify ranges update changelog Just use one boolean to determine polling/ws use addHeaders update changelog Implement socketio#684 Fix some documentation marks
2 parents 96ce620 + a611aee commit 313032a

20 files changed

+148
-65
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# v13.1.0
2+
3+
- Allow setting `SocketEngineSpec.extraHeaders` after init.
4+
- Deprecate `SocketEngineSpec.websocket` in favor of just using the `SocketEngineSpec.polling` property.
5+
- Enable bitcode for most platforms.
6+
- Fix [#882](https://github.com/socketio/socket.io-client-swift/issues/882). This adds a new method
7+
`SocketManger.removeSocket(_:)` that should be called if when you no longer wish to use a socket again.
8+
This will cause the engine to no longer keep a strong reference to the socket and no longer track it.
9+
110
# v13.0.1
211

312
- Fix not setting handleQueue on `SocketManager`

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let package = Package(
8686
.executable(name: "socket.io-test", targets: ["YourTargetName"])
8787
],
8888
dependencies: [
89-
.package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "13.0.0"))
89+
.package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "13.1.0"))
9090
],
9191
targets: [
9292
.target(name: "YourTargetName", dependencies: ["SocketIO"], path: "./Path/To/Your/Sources")
@@ -99,7 +99,7 @@ Then import `import SocketIO`.
9999
### Carthage
100100
Add this line to your `Cartfile`:
101101
```
102-
github "socketio/socket.io-client-swift" ~> 13.0.0
102+
github "socketio/socket.io-client-swift" ~> 13.1.0
103103
```
104104

105105
Run `carthage update --platform ios,macosx`.
@@ -113,7 +113,7 @@ Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`:
113113
use_frameworks!
114114

115115
target 'YourApp' do
116-
pod 'Socket.IO-Client-Swift', '~> 13.0.0'
116+
pod 'Socket.IO-Client-Swift', '~> 13.1.0'
117117
end
118118
```
119119

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.0.1"
4+
s.version = "13.1.0"
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.0.1',
21+
:tag => 'v13.1.0',
2222
:submodules => true
2323
}
2424
s.pod_target_xcconfig = {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@
532532
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
533533
CODE_SIGN_IDENTITY = "Developer ID Application";
534534
ENABLE_BITCODE = YES;
535+
"ENABLE_BITCODE[sdk=macosx*]" = NO;
535536
ENABLE_STRICT_OBJC_MSGSEND = YES;
536537
ENABLE_TESTABILITY = YES;
537538
"FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = (
@@ -604,6 +605,7 @@
604605
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
605606
CODE_SIGN_IDENTITY = "Developer ID Application";
606607
ENABLE_BITCODE = YES;
608+
"ENABLE_BITCODE[sdk=macosx*]" = NO;
607609
ENABLE_STRICT_OBJC_MSGSEND = YES;
608610
"FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = (
609611
"$(inherited)",
@@ -678,7 +680,8 @@
678680
DYLIB_COMPATIBILITY_VERSION = 1;
679681
DYLIB_CURRENT_VERSION = 1;
680682
DYLIB_INSTALL_NAME_BASE = "@rpath";
681-
ENABLE_BITCODE = NO;
683+
ENABLE_BITCODE = YES;
684+
"ENABLE_BITCODE[sdk=macosx*]" = NO;
682685
ENABLE_STRICT_OBJC_MSGSEND = YES;
683686
ENABLE_TESTABILITY = YES;
684687
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
@@ -747,7 +750,8 @@
747750
DYLIB_COMPATIBILITY_VERSION = 1;
748751
DYLIB_CURRENT_VERSION = 1;
749752
DYLIB_INSTALL_NAME_BASE = "@rpath";
750-
ENABLE_BITCODE = NO;
753+
ENABLE_BITCODE = YES;
754+
"ENABLE_BITCODE[sdk=macosx*]" = NO;
751755
ENABLE_NS_ASSERTIONS = NO;
752756
ENABLE_STRICT_OBJC_MSGSEND = YES;
753757
ENABLE_TESTABILITY = YES;

Source/SocketIO/Ack/SocketAckManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import Foundation
2727

2828
/// The status of an ack.
2929
public enum SocketAckStatus : String {
30+
// MARK: Cases
31+
3032
/// The ack timed out.
3133
case noAck = "NO ACK"
3234
}

Source/SocketIO/Client/SocketIOClient.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
127127

128128
status = .connecting
129129

130-
manager.connectSocket(self)
130+
joinNamespace()
131+
132+
if manager.status == .connected && nsp == "/" {
133+
// We might not get a connect event for the default nsp, fire immediately
134+
didConnect(toNamespace: nsp)
135+
136+
return
137+
}
131138

132139
guard timeoutAfter != 0 else { return }
133140

@@ -183,7 +190,6 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
183190
DefaultSocketLogger.Logger.log("Closing socket", type: logType)
184191

185192
leaveNamespace()
186-
didDisconnect(reason: "Disconnect")
187193
}
188194

189195
/// Send an event to the server, with optional data items.
@@ -366,21 +372,15 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
366372
/// Call when you wish to leave a namespace and disconnect this socket.
367373
@objc
368374
open func leaveNamespace() {
369-
guard nsp != "/" else { return }
370-
371-
status = .disconnected
372-
373375
manager?.disconnectSocket(self)
374376
}
375377

376378
/// Joins `nsp`.
377379
@objc
378380
open func joinNamespace() {
379-
guard nsp != "/" else { return }
380-
381381
DefaultSocketLogger.Logger.log("Joining namespace \(nsp)", type: logType)
382382

383-
manager?.engine?.send("0\(nsp)", withData: [])
383+
manager?.connectSocket(self)
384384
}
385385

386386
/// Removes handler(s) for a client event.

Source/SocketIO/Client/SocketIOClientConfiguration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public struct SocketIOClientConfiguration : ExpressibleByArrayLiteral, Collectio
129129

130130
/// Declares that a type can set configs from a `SocketIOClientConfiguration`.
131131
public protocol ConfigSettable {
132+
// MARK: Methods
133+
132134
/// Called when an `ConfigSettable` should set/update its configs from a given configuration.
133135
///
134136
/// - parameter config: The `SocketIOClientConfiguration` that should be used to set/update configs.

Source/SocketIO/Engine/SocketEngine.swift

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
4444
}
4545
}
4646

47+
/// A dictionary of extra http headers that will be set during connection.
48+
public var extraHeaders: [String: String]?
49+
4750
/// A queue of engine.io messages waiting for POSTing
4851
///
4952
/// **You should not touch this directly**
@@ -73,9 +76,6 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
7376
/// An array of HTTPCookies that are sent during the connection.
7477
public private(set) var cookies: [HTTPCookie]?
7578

76-
/// A dictionary of extra http headers that will be set during connection.
77-
public private(set) var extraHeaders: [String: String]?
78-
7979
/// When `true`, the engine is in the process of switching to WebSockets.
8080
///
8181
/// **Do not touch this directly**
@@ -112,6 +112,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
112112
public private(set) var urlWebSocket = URL(string: "http://localhost/")!
113113

114114
/// If `true`, then the engine is currently in WebSockets mode.
115+
@available(*, deprecated, message: "No longer needed, if we're not polling, then we must be doing websockets")
115116
public private(set) var websocket = false
116117

117118
/// The WebSocket for this engine.
@@ -233,7 +234,6 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
233234

234235
if forceWebsockets {
235236
polling = false
236-
websocket = true
237237
createWebSocketAndConnect()
238238
return
239239
}
@@ -283,18 +283,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
283283
ws?.delegate = nil // TODO this seems a bit defensive, is this really needed?
284284
var req = URLRequest(url: urlWebSocketWithSid)
285285

286-
if cookies != nil {
287-
let headers = HTTPCookie.requestHeaderFields(with: cookies!)
288-
for (headerName, value) in headers {
289-
req.setValue(value, forHTTPHeaderField: headerName)
290-
}
291-
}
292-
293-
if extraHeaders != nil {
294-
for (headerName, value) in extraHeaders! {
295-
req.setValue(value, forHTTPHeaderField: headerName)
296-
}
297-
}
286+
addHeaders(to: &req)
298287

299288
ws = WebSocket(request: req)
300289
ws?.callbackQueue = engineQueue
@@ -323,19 +312,15 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
323312
}
324313

325314
private func _disconnect(reason: String) {
326-
guard connected else { return closeOutEngine(reason: reason) }
315+
guard connected && !closed else { return closeOutEngine(reason: reason) }
327316

328317
DefaultSocketLogger.Logger.log("Engine is being closed.", type: SocketEngine.logType)
329318

330-
if closed {
331-
return closeOutEngine(reason: reason)
332-
}
333-
334-
if websocket {
319+
if polling {
320+
disconnectPolling(reason: reason)
321+
} else {
335322
sendWebSocketMessage("", withType: .close, withData: [])
336323
closeOutEngine(reason: reason)
337-
} else {
338-
disconnectPolling(reason: reason)
339324
}
340325
}
341326

@@ -358,8 +343,9 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
358343
"we'll probably disconnect soon. You should report this.", type: SocketEngine.logType)
359344
}
360345

346+
DefaultSocketLogger.Logger.log("Switching to WebSockets", type: SocketEngine.logType)
347+
361348
sendWebSocketMessage("", withType: .upgrade, withData: [])
362-
websocket = true
363349
polling = false
364350
fastUpgrade = false
365351
probing = false
@@ -454,6 +440,9 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
454440

455441
// We should upgrade
456442
if message == "3probe" {
443+
DefaultSocketLogger.Logger.log("Received probe response, should upgrade to WebSockets",
444+
type: SocketEngine.logType)
445+
457446
upgradeTransport()
458447
}
459448

@@ -520,7 +509,6 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
520509
sid = ""
521510
waitingForPoll = false
522511
waitingForPost = false
523-
websocket = false
524512
}
525513

526514
private func sendPing() {
@@ -603,17 +591,20 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
603591
public func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data]) {
604592
engineQueue.async {
605593
guard self.connected else { return }
594+
guard !self.probing else {
595+
self.probeWait.append((msg, type, data))
606596

607-
if self.websocket {
608-
DefaultSocketLogger.Logger.log("Writing ws: \(msg) has data: \(data.count != 0)",
609-
type: SocketEngine.logType)
610-
self.sendWebSocketMessage(msg, withType: type, withData: data)
611-
} else if !self.probing {
597+
return
598+
}
599+
600+
if self.polling {
612601
DefaultSocketLogger.Logger.log("Writing poll: \(msg) has data: \(data.count != 0)",
613602
type: SocketEngine.logType)
614603
self.sendPollMessage(msg, withType: type, withData: data)
615604
} else {
616-
self.probeWait.append((msg, type, data))
605+
DefaultSocketLogger.Logger.log("Writing ws: \(msg) has data: \(data.count != 0)",
606+
type: SocketEngine.logType)
607+
self.sendWebSocketMessage(msg, withType: type, withData: data)
617608
}
618609
}
619610
}
@@ -642,14 +633,14 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
642633
return
643634
}
644635

645-
guard websocket else {
636+
guard !polling else {
646637
flushProbeWait()
647638

648639
return
649640
}
650641

651642
connected = false
652-
websocket = false
643+
polling = true
653644

654645
if let reason = error?.localizedDescription {
655646
didError(reason: reason)

Source/SocketIO/Engine/SocketEnginePollable.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Foundation
2626

2727
/// Protocol that is used to implement socket.io polling support
2828
public protocol SocketEnginePollable : SocketEngineSpec {
29-
/// MARK: Properties
29+
// MARK: Properties
3030

3131
/// `true` If engine's session has been invalidated.
3232
var invalidated: Bool { get }
@@ -51,6 +51,8 @@ public protocol SocketEnginePollable : SocketEngineSpec {
5151
/// **Do not touch this directly**
5252
var waitingForPost: Bool { get set }
5353

54+
// MARK: Methods
55+
5456
/// Call to send a long-polling request.
5557
///
5658
/// You shouldn't need to call this directly, the engine should automatically maintain a long-poll request.
@@ -99,7 +101,7 @@ extension SocketEnginePollable {
99101
///
100102
/// You shouldn't need to call this directly, the engine should automatically maintain a long-poll request.
101103
public func doPoll() {
102-
guard !websocket && !waitingForPoll && connected && !closed else { return }
104+
guard polling && !waitingForPoll && connected && !closed else { return }
103105

104106
var req = URLRequest(url: urlPollingWithSid)
105107
addHeaders(to: &req)
@@ -149,7 +151,7 @@ extension SocketEnginePollable {
149151

150152
private func flushWaitingForPost() {
151153
guard postWait.count != 0 && connected else { return }
152-
guard !websocket else {
154+
guard polling else {
153155
flushWaitingForPostToWebSocket()
154156

155157
return

0 commit comments

Comments
 (0)