Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
* development:
  update changelog/readme for 15.1
  update changelog
  fix #1178
  expose Starscream WebSocket enableSOCKSProxy option to socket.io-client-swift options
  • Loading branch information
nuclearace committed May 28, 2019
2 parents 148c302 + 0d44b10 commit 558ea65
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v15.1.0

- Add ability to enable websockets SOCKS proxy.
- Fix emit completion callback not firing on websockets [#1178](https://github.com/socketio/socket.io-client-swift/issues/1178)

# v15.0.0

- Swift 5
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Then import `import SocketIO`.
### Carthage
Add this line to your `Cartfile`:
```
github "socketio/socket.io-client-swift" ~> 15.0.0
github "socketio/socket.io-client-swift" ~> 15.1.0
```

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

target 'YourApp' do
pod 'Socket.IO-Client-Swift', '~> 15.0.0'
pod 'Socket.IO-Client-Swift', '~> 15.1.0'
end
```

Expand Down
7 changes: 7 additions & 0 deletions Source/SocketIO/Client/SocketIOClientOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public enum SocketIOClientOption : ClientOption {

/// If passed `true`, the only transport that will be used will be WebSockets.
case forceWebsockets(Bool)

/// If passed `true`, the WebSocket stream will be configured with the enableSOCKSProxy `true`.
case enableSOCKSProxy(Bool)

/// The queue that all interaction with the client should occur on. This is the queue that event handlers are
/// called on.
Expand Down Expand Up @@ -143,6 +146,8 @@ public enum SocketIOClientOption : ClientOption {
description = "security"
case .sessionDelegate:
description = "sessionDelegate"
case .enableSOCKSProxy:
description = "enableSOCKSProxy"
}

return description
Expand Down Expand Up @@ -192,6 +197,8 @@ public enum SocketIOClientOption : ClientOption {
value = signed
case let .sessionDelegate(delegate):
value = delegate
case let .enableSOCKSProxy(enable):
value = enable
}

return value
Expand Down
9 changes: 8 additions & 1 deletion Source/SocketIO/Engine/SocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
/// If `true`, then the engine is currently in WebSockets mode.
@available(*, deprecated, message: "No longer needed, if we're not polling, then we must be doing websockets")
public private(set) var websocket = false

/// When `true`, the WebSocket `stream` will be configured with the enableSOCKSProxy `true`.
public private(set) var enableSOCKSProxy = false

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

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

ws = WebSocket(request: req)
let stream = FoundationStream()
stream.enableSOCKSProxy = enableSOCKSProxy
ws = WebSocket(request: req, stream: stream)
ws?.callbackQueue = engineQueue
ws?.enableCompression = compress
ws?.disableSSLCertValidation = selfSigned
Expand Down Expand Up @@ -593,6 +598,8 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
self.security = security
case .compress:
self.compress = true
case .enableSOCKSProxy:
self.enableSOCKSProxy = true
default:
continue
}
Expand Down
10 changes: 7 additions & 3 deletions Source/SocketIO/Engine/SocketEngineWebsocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ extension SocketEngineWebsocket {
/// - parameter completion: Callback called on transport write completion.
public func sendWebSocketMessage(_ str: String,
withType type: SocketEnginePacketType,
withData datas: [Data],
withData data: [Data],
completion: (() -> ())?
) {
DefaultSocketLogger.Logger.log("Sending ws: \(str) as type: \(type.rawValue)", type: "SocketEngineWebSocket")

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

for data in datas {
if case let .left(bin) = createBinaryDataForSend(using: data) {
if data.count == 0 {
completion?()
}

for item in data {
if case let .left(bin) = createBinaryDataForSend(using: item) {
ws?.write(data: bin, completion: completion)
}
}
Expand Down
2 changes: 2 additions & 0 deletions Source/SocketIO/Util/SocketExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ extension Dictionary where Key == String, Value == Any {
return .sessionDelegate(delegate)
case let ("compress", compress as Bool):
return compress ? .compress : nil
case let ("enableSOCKSProxy", enable as Bool):
return .enableSOCKSProxy(enable)
default:
return nil
}
Expand Down

0 comments on commit 558ea65

Please sign in to comment.