Skip to content

Commit 558ea65

Browse files
committed
Merge branch 'development'
* development: update changelog/readme for 15.1 update changelog fix #1178 expose Starscream WebSocket enableSOCKSProxy option to socket.io-client-swift options
2 parents 148c302 + 0d44b10 commit 558ea65

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v15.1.0
2+
3+
- Add ability to enable websockets SOCKS proxy.
4+
- Fix emit completion callback not firing on websockets [#1178](https://github.com/socketio/socket.io-client-swift/issues/1178)
5+
16
# v15.0.0
27

38
- Swift 5

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -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" ~> 15.0.0
102+
github "socketio/socket.io-client-swift" ~> 15.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', '~> 15.0.0'
116+
pod 'Socket.IO-Client-Swift', '~> 15.1.0'
117117
end
118118
```
119119

Source/SocketIO/Client/SocketIOClientOption.swift

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public enum SocketIOClientOption : ClientOption {
5252

5353
/// If passed `true`, the only transport that will be used will be WebSockets.
5454
case forceWebsockets(Bool)
55+
56+
/// If passed `true`, the WebSocket stream will be configured with the enableSOCKSProxy `true`.
57+
case enableSOCKSProxy(Bool)
5558

5659
/// The queue that all interaction with the client should occur on. This is the queue that event handlers are
5760
/// called on.
@@ -143,6 +146,8 @@ public enum SocketIOClientOption : ClientOption {
143146
description = "security"
144147
case .sessionDelegate:
145148
description = "sessionDelegate"
149+
case .enableSOCKSProxy:
150+
description = "enableSOCKSProxy"
146151
}
147152

148153
return description
@@ -192,6 +197,8 @@ public enum SocketIOClientOption : ClientOption {
192197
value = signed
193198
case let .sessionDelegate(delegate):
194199
value = delegate
200+
case let .enableSOCKSProxy(enable):
201+
value = enable
195202
}
196203

197204
return value

Source/SocketIO/Engine/SocketEngine.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
113113
/// If `true`, then the engine is currently in WebSockets mode.
114114
@available(*, deprecated, message: "No longer needed, if we're not polling, then we must be doing websockets")
115115
public private(set) var websocket = false
116+
117+
/// When `true`, the WebSocket `stream` will be configured with the enableSOCKSProxy `true`.
118+
public private(set) var enableSOCKSProxy = false
116119

117120
/// The WebSocket for this engine.
118121
public private(set) var ws: WebSocket?
@@ -283,7 +286,9 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
283286

284287
addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlPollingWithSid))
285288

286-
ws = WebSocket(request: req)
289+
let stream = FoundationStream()
290+
stream.enableSOCKSProxy = enableSOCKSProxy
291+
ws = WebSocket(request: req, stream: stream)
287292
ws?.callbackQueue = engineQueue
288293
ws?.enableCompression = compress
289294
ws?.disableSSLCertValidation = selfSigned
@@ -593,6 +598,8 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
593598
self.security = security
594599
case .compress:
595600
self.compress = true
601+
case .enableSOCKSProxy:
602+
self.enableSOCKSProxy = true
596603
default:
597604
continue
598605
}

Source/SocketIO/Engine/SocketEngineWebsocket.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@ extension SocketEngineWebsocket {
6262
/// - parameter completion: Callback called on transport write completion.
6363
public func sendWebSocketMessage(_ str: String,
6464
withType type: SocketEnginePacketType,
65-
withData datas: [Data],
65+
withData data: [Data],
6666
completion: (() -> ())?
6767
) {
6868
DefaultSocketLogger.Logger.log("Sending ws: \(str) as type: \(type.rawValue)", type: "SocketEngineWebSocket")
6969

7070
ws?.write(string: "\(type.rawValue)\(str)")
7171

72-
for data in datas {
73-
if case let .left(bin) = createBinaryDataForSend(using: data) {
72+
if data.count == 0 {
73+
completion?()
74+
}
75+
76+
for item in data {
77+
if case let .left(bin) = createBinaryDataForSend(using: item) {
7478
ws?.write(data: bin, completion: completion)
7579
}
7680
}

Source/SocketIO/Util/SocketExtensions.swift

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ extension Dictionary where Key == String, Value == Any {
8585
return .sessionDelegate(delegate)
8686
case let ("compress", compress as Bool):
8787
return compress ? .compress : nil
88+
case let ("enableSOCKSProxy", enable as Bool):
89+
return .enableSOCKSProxy(enable)
8890
default:
8991
return nil
9092
}

0 commit comments

Comments
 (0)