Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cfc7b7b8dc | |||
| 311b6dd9c7 | |||
| 339ca39461 | |||
| 4e8973e3fc | |||
| 990a4c858e | |||
| 3b4c81547a | |||
| 9e8fcba42e | |||
| d84552f944 | |||
| c3ac0a9df7 | |||
| 97538bc11d | |||
| 4e8dca654d | |||
| 547cb80ef6 | |||
| 12946fc610 | |||
| 850f620441 | |||
| ced0725e4b | |||
| 9d1bac8ede | |||
| eb29f2a1f9 | |||
| 9cf7b4dfcb | |||
| 6b2742542c | |||
| a986e38e56 | |||
| 692f3cb14a | |||
| e8c0e894aa | |||
| b7e98e147f | |||
| 281a49edd8 |
+1
-1
@@ -1,4 +1,4 @@
|
||||
osx_image: xcode11
|
||||
osx_image: xcode11.3
|
||||
language: objective-c
|
||||
before_install:
|
||||
- gem install cocoapods --pre
|
||||
|
||||
@@ -2,6 +2,29 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
`Starscream` adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
### [4.0.3](https://github.com/daltoniam/Starscream/tree/4.0.3)
|
||||
|
||||
Bug fixes for 4.0.2.
|
||||
|
||||
[#760](https://github.com/daltoniam/Starscream/issues/760)
|
||||
|
||||
### [4.0.2](https://github.com/daltoniam/Starscream/tree/4.0.2)
|
||||
|
||||
Bug fixes for 4.0.1. Fixed native engine is connected/disconnected. Native engine isn't the default since the API lacks features.
|
||||
|
||||
[#697](https://github.com/daltoniam/Starscream/pull/697)
|
||||
|
||||
### [4.0.1](https://github.com/daltoniam/Starscream/tree/4.0.1)
|
||||
|
||||
Bug fixes for 4.0.0. Enabled Native engine now that the API is out of beta and works properly.
|
||||
|
||||
[#749](https://github.com/daltoniam/Starscream/pull/749)
|
||||
[#755](https://github.com/daltoniam/Starscream/pull/755)
|
||||
|
||||
### [4.0.0](https://github.com/daltoniam/Starscream/tree/4.0.0)
|
||||
|
||||
Major API refactor.
|
||||
|
||||
### [3.1.1](https://github.com/daltoniam/Starscream/tree/3.1.1)
|
||||
|
||||
Small version number fix for 3.1.0: [#703](https://github.com/daltoniam/Starscream/issues/703)
|
||||
|
||||
+64
-59
@@ -1,47 +1,52 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
CFPropertyList (3.0.0)
|
||||
CFPropertyList (3.0.2)
|
||||
activesupport (4.2.11.1)
|
||||
i18n (~> 0.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
addressable (2.6.0)
|
||||
public_suffix (>= 2.0.2, < 4.0)
|
||||
addressable (2.7.0)
|
||||
public_suffix (>= 2.0.2, < 5.0)
|
||||
algoliasearch (1.27.1)
|
||||
httpclient (~> 2.8, >= 2.8.3)
|
||||
json (>= 1.5.1)
|
||||
atomos (0.1.3)
|
||||
babosa (1.0.2)
|
||||
claide (1.0.2)
|
||||
cocoapods (1.6.1)
|
||||
babosa (1.0.3)
|
||||
claide (1.0.3)
|
||||
cocoapods (1.8.4)
|
||||
activesupport (>= 4.0.2, < 5)
|
||||
claide (>= 1.0.2, < 2.0)
|
||||
cocoapods-core (= 1.6.1)
|
||||
cocoapods-deintegrate (>= 1.0.2, < 2.0)
|
||||
cocoapods-core (= 1.8.4)
|
||||
cocoapods-deintegrate (>= 1.0.3, < 2.0)
|
||||
cocoapods-downloader (>= 1.2.2, < 2.0)
|
||||
cocoapods-plugins (>= 1.0.0, < 2.0)
|
||||
cocoapods-search (>= 1.0.0, < 2.0)
|
||||
cocoapods-stats (>= 1.0.0, < 2.0)
|
||||
cocoapods-trunk (>= 1.3.1, < 2.0)
|
||||
cocoapods-trunk (>= 1.4.0, < 2.0)
|
||||
cocoapods-try (>= 1.1.0, < 2.0)
|
||||
colored2 (~> 3.1)
|
||||
escape (~> 0.0.4)
|
||||
fourflusher (>= 2.2.0, < 3.0)
|
||||
fourflusher (>= 2.3.0, < 3.0)
|
||||
gh_inspector (~> 1.0)
|
||||
molinillo (~> 0.6.6)
|
||||
nap (~> 1.0)
|
||||
ruby-macho (~> 1.4)
|
||||
xcodeproj (>= 1.8.1, < 2.0)
|
||||
cocoapods-core (1.6.1)
|
||||
xcodeproj (>= 1.11.1, < 2.0)
|
||||
cocoapods-core (1.8.4)
|
||||
activesupport (>= 4.0.2, < 6)
|
||||
algoliasearch (~> 1.0)
|
||||
concurrent-ruby (~> 1.1)
|
||||
fuzzy_match (~> 2.0.4)
|
||||
nap (~> 1.0)
|
||||
cocoapods-deintegrate (1.0.4)
|
||||
cocoapods-downloader (1.2.2)
|
||||
cocoapods-downloader (1.3.0)
|
||||
cocoapods-plugins (1.0.0)
|
||||
nap
|
||||
cocoapods-search (1.0.0)
|
||||
cocoapods-stats (1.1.0)
|
||||
cocoapods-trunk (1.3.1)
|
||||
cocoapods-trunk (1.4.1)
|
||||
nap (>= 0.8, < 2.0)
|
||||
netrc (~> 0.11)
|
||||
cocoapods-try (1.1.0)
|
||||
@@ -53,21 +58,21 @@ GEM
|
||||
declarative (0.0.10)
|
||||
declarative-option (0.1.0)
|
||||
digest-crc (0.4.1)
|
||||
domain_name (0.5.20180417)
|
||||
domain_name (0.5.20190701)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
dotenv (2.7.2)
|
||||
dotenv (2.7.5)
|
||||
emoji_regex (1.0.1)
|
||||
escape (0.0.4)
|
||||
excon (0.64.0)
|
||||
faraday (0.15.4)
|
||||
excon (0.71.1)
|
||||
faraday (0.17.3)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
faraday-cookie_jar (0.0.6)
|
||||
faraday (>= 0.7.4)
|
||||
http-cookie (~> 1.0.0)
|
||||
faraday_middleware (0.13.1)
|
||||
faraday (>= 0.7.4, < 1.0)
|
||||
fastimage (2.1.5)
|
||||
fastlane (2.122.0)
|
||||
fastimage (2.1.7)
|
||||
fastlane (2.139.0)
|
||||
CFPropertyList (>= 2.3, < 4.0.0)
|
||||
addressable (>= 2.3, < 3.0.0)
|
||||
babosa (>= 1.0.2, < 2.0.0)
|
||||
@@ -76,23 +81,23 @@ GEM
|
||||
commander-fastlane (>= 4.4.6, < 5.0.0)
|
||||
dotenv (>= 2.1.1, < 3.0.0)
|
||||
emoji_regex (>= 0.1, < 2.0)
|
||||
excon (>= 0.45.0, < 1.0.0)
|
||||
faraday (~> 0.9)
|
||||
excon (>= 0.71.0, < 1.0.0)
|
||||
faraday (~> 0.17)
|
||||
faraday-cookie_jar (~> 0.0.6)
|
||||
faraday_middleware (~> 0.9)
|
||||
faraday_middleware (~> 0.13.1)
|
||||
fastimage (>= 2.1.0, < 3.0.0)
|
||||
gh_inspector (>= 1.1.2, < 2.0.0)
|
||||
google-api-client (>= 0.21.2, < 0.24.0)
|
||||
google-api-client (>= 0.29.2, < 0.37.0)
|
||||
google-cloud-storage (>= 1.15.0, < 2.0.0)
|
||||
highline (>= 1.7.2, < 2.0.0)
|
||||
json (< 3.0.0)
|
||||
mini_magick (~> 4.5.1)
|
||||
multi_json
|
||||
jwt (~> 2.1.0)
|
||||
mini_magick (>= 4.9.4, < 5.0.0)
|
||||
multi_xml (~> 0.5)
|
||||
multipart-post (~> 2.0.0)
|
||||
plist (>= 3.1.0, < 4.0.0)
|
||||
public_suffix (~> 2.0.0)
|
||||
rubyzip (>= 1.2.2, < 2.0.0)
|
||||
rubyzip (>= 1.3.0, < 2.0.0)
|
||||
security (= 0.1.3)
|
||||
simctl (~> 1.6.3)
|
||||
slack-notifier (>= 2.0.0, < 3.0.0)
|
||||
@@ -101,52 +106,52 @@ GEM
|
||||
tty-screen (>= 0.6.3, < 1.0.0)
|
||||
tty-spinner (>= 0.8.0, < 1.0.0)
|
||||
word_wrap (~> 1.0.0)
|
||||
xcodeproj (>= 1.8.1, < 2.0.0)
|
||||
xcodeproj (>= 1.13.0, < 2.0.0)
|
||||
xcpretty (~> 0.3.0)
|
||||
xcpretty-travis-formatter (>= 0.0.3)
|
||||
fourflusher (2.2.0)
|
||||
fourflusher (2.3.1)
|
||||
fuzzy_match (2.0.4)
|
||||
gh_inspector (1.1.3)
|
||||
google-api-client (0.23.9)
|
||||
google-api-client (0.36.3)
|
||||
addressable (~> 2.5, >= 2.5.1)
|
||||
googleauth (>= 0.5, < 0.7.0)
|
||||
googleauth (~> 0.9)
|
||||
httpclient (>= 2.8.1, < 3.0)
|
||||
mime-types (~> 3.0)
|
||||
mini_mime (~> 1.0)
|
||||
representable (~> 3.0)
|
||||
retriable (>= 2.0, < 4.0)
|
||||
signet (~> 0.9)
|
||||
google-cloud-core (1.3.0)
|
||||
signet (~> 0.12)
|
||||
google-cloud-core (1.4.1)
|
||||
google-cloud-env (~> 1.0)
|
||||
google-cloud-env (1.0.5)
|
||||
google-cloud-env (1.3.0)
|
||||
faraday (~> 0.11)
|
||||
google-cloud-storage (1.16.0)
|
||||
google-cloud-storage (1.25.0)
|
||||
addressable (~> 2.5)
|
||||
digest-crc (~> 0.4)
|
||||
google-api-client (~> 0.23)
|
||||
google-api-client (~> 0.33)
|
||||
google-cloud-core (~> 1.2)
|
||||
googleauth (>= 0.6.2, < 0.10.0)
|
||||
googleauth (0.6.7)
|
||||
googleauth (~> 0.9)
|
||||
mini_mime (~> 1.0)
|
||||
googleauth (0.10.0)
|
||||
faraday (~> 0.12)
|
||||
jwt (>= 1.4, < 3.0)
|
||||
memoist (~> 0.16)
|
||||
multi_json (~> 1.11)
|
||||
os (>= 0.9, < 2.0)
|
||||
signet (~> 0.7)
|
||||
signet (~> 0.12)
|
||||
highline (1.7.10)
|
||||
http-cookie (1.0.3)
|
||||
domain_name (~> 0.5)
|
||||
httpclient (2.8.3)
|
||||
i18n (0.9.5)
|
||||
concurrent-ruby (~> 1.0)
|
||||
json (2.2.0)
|
||||
json (2.3.0)
|
||||
jwt (2.1.0)
|
||||
memoist (0.16.0)
|
||||
mime-types (3.2.2)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2019.0331)
|
||||
mini_magick (4.5.1)
|
||||
minitest (5.11.3)
|
||||
memoist (0.16.2)
|
||||
mini_magick (4.9.5)
|
||||
mini_mime (1.0.2)
|
||||
minitest (5.13.0)
|
||||
molinillo (0.6.6)
|
||||
multi_json (1.13.1)
|
||||
multi_json (1.14.1)
|
||||
multi_xml (0.6.0)
|
||||
multipart-post (2.0.0)
|
||||
nanaimo (0.2.6)
|
||||
@@ -163,14 +168,14 @@ GEM
|
||||
retriable (3.1.2)
|
||||
rouge (2.0.7)
|
||||
ruby-macho (1.4.0)
|
||||
rubyzip (1.2.2)
|
||||
rubyzip (1.3.0)
|
||||
security (0.1.3)
|
||||
signet (0.11.0)
|
||||
signet (0.12.0)
|
||||
addressable (~> 2.3)
|
||||
faraday (~> 0.9)
|
||||
jwt (>= 1.5, < 3.0)
|
||||
multi_json (~> 1.10)
|
||||
simctl (1.6.5)
|
||||
simctl (1.6.7)
|
||||
CFPropertyList
|
||||
naturally
|
||||
slack-notifier (2.3.2)
|
||||
@@ -178,19 +183,19 @@ GEM
|
||||
terminal-table (1.8.0)
|
||||
unicode-display_width (~> 1.1, >= 1.1.1)
|
||||
thread_safe (0.3.6)
|
||||
tty-cursor (0.6.1)
|
||||
tty-screen (0.6.5)
|
||||
tty-spinner (0.9.0)
|
||||
tty-cursor (~> 0.6.0)
|
||||
tzinfo (1.2.5)
|
||||
tty-cursor (0.7.0)
|
||||
tty-screen (0.7.0)
|
||||
tty-spinner (0.9.2)
|
||||
tty-cursor (~> 0.7)
|
||||
tzinfo (1.2.6)
|
||||
thread_safe (~> 0.1)
|
||||
uber (0.1.0)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.7.6)
|
||||
unicode-display_width (1.5.0)
|
||||
unicode-display_width (1.6.0)
|
||||
word_wrap (1.0.0)
|
||||
xcodeproj (1.9.0)
|
||||
xcodeproj (1.14.0)
|
||||
CFPropertyList (>= 2.3.3, < 4.0)
|
||||
atomos (~> 0.1.3)
|
||||
claide (>= 1.0.2, < 2.0)
|
||||
@@ -209,4 +214,4 @@ DEPENDENCIES
|
||||
fastlane
|
||||
|
||||
BUNDLED WITH
|
||||
1.17.2
|
||||
2.1.3
|
||||
|
||||
@@ -22,7 +22,9 @@ import Starscream
|
||||
Once imported, you can open a connection to your WebSocket server. Note that `socket` is probably best as a property, so it doesn't get deallocated right after being setup.
|
||||
|
||||
```swift
|
||||
socket = WebSocket(url: URL(string: "ws://localhost:8080/")!)
|
||||
var request = URLRequest(url: URL(string: "http://localhost:8080")!)
|
||||
request.timeoutInterval = 5
|
||||
socket = WebSocket(request: request)
|
||||
socket.delegate = self
|
||||
socket.connect()
|
||||
```
|
||||
@@ -50,7 +52,7 @@ func didReceive(event: WebSocketEvent, client: WebSocket) {
|
||||
break
|
||||
case .pong(_):
|
||||
break
|
||||
case .viablityChanged(_):
|
||||
case .viabilityChanged(_):
|
||||
break
|
||||
case .reconnectSuggested(_):
|
||||
break
|
||||
@@ -150,6 +152,15 @@ let socket = WebSocket(request: request)
|
||||
|
||||
SSL Pinning is also supported in Starscream.
|
||||
|
||||
|
||||
Allow Self-signed certificates:
|
||||
|
||||
```swift
|
||||
var request = URLRequest(url: URL(string: "ws://localhost:8080/")!)
|
||||
let pinner = FoundationSecurity(allowSelfSigned: true) // don't validate SSL certificates
|
||||
let socket = WebSocket(request: request, certPinner: pinner)
|
||||
```
|
||||
|
||||
TODO: Update docs on how to load certificates and public keys into an app bundle, use the builtin pinner and TrustKit.
|
||||
|
||||
### Compression Extensions
|
||||
@@ -157,8 +168,9 @@ TODO: Update docs on how to load certificates and public keys into an app bundle
|
||||
Compression Extensions ([RFC 7692](https://tools.ietf.org/html/rfc7692)) is supported in Starscream. Compression is enabled by default, however compression will only be used if it is supported by the server as well. You may enable or disable compression via the `.enableCompression` property:
|
||||
|
||||
```swift
|
||||
socket = WebSocket(url: URL(string: "ws://localhost:8080/")!)
|
||||
socket.enableCompression = false
|
||||
var request = URLRequest(url: URL(string: "ws://localhost:8080/")!)
|
||||
let compression = WSCompression()
|
||||
let socket = WebSocket(request: request, compressionHandler: compression)
|
||||
```
|
||||
|
||||
Compression should be disabled if your application is transmitting already-compressed, random, or other uncompressable data.
|
||||
|
||||
@@ -6,85 +6,91 @@
|
||||
// Copyright © 2019 Vluxe. All rights reserved.
|
||||
//
|
||||
|
||||
//import Foundation
|
||||
//
|
||||
//@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
//public class NativeEngine: Engine {
|
||||
// private var task: URLSessionWebSocketTask?
|
||||
// weak var delegate: EngineDelegate?
|
||||
//
|
||||
// public init() {
|
||||
// //TODO: I probably need to drop down into the NWConnection APIs to get this to work with all of Starscream's features
|
||||
// //
|
||||
// //NOTE: URLSessionWebSocketTask doesn't work with our ruby web server in the SimpleTest example.
|
||||
// //It allows crashes. It works fine with https://echo.websocket.org in either http or https. Not sure why though
|
||||
// //needs more debugging and probably needs radar filed.
|
||||
// }
|
||||
//
|
||||
// public func register(delegate: EngineDelegate) {
|
||||
// self.delegate = delegate
|
||||
// }
|
||||
//
|
||||
// public func start(request: URLRequest) {
|
||||
// task = URLSession.shared.webSocketTask(with: request)
|
||||
// doRead()
|
||||
// task?.resume()
|
||||
// }
|
||||
//
|
||||
// public func stop(closeCode: UInt16) {
|
||||
// let closeCode = URLSessionWebSocketTask.CloseCode(rawValue: Int(closeCode)) ?? .normalClosure
|
||||
// task?.cancel(with: closeCode, reason: nil)
|
||||
// }
|
||||
//
|
||||
// public func forceStop() {
|
||||
// stop(closeCode: UInt16(URLSessionWebSocketTask.CloseCode.abnormalClosure.rawValue))
|
||||
// }
|
||||
//
|
||||
// public func write(string: String, completion: (() -> ())?) {
|
||||
// task?.send(.string(string), completionHandler: { (error) in
|
||||
// completion?()
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// public func write(data: Data, opcode: FrameOpCode, completion: (() -> ())?) {
|
||||
// switch opcode {
|
||||
// case .binaryFrame:
|
||||
// task?.send(.data(data), completionHandler: { (error) in
|
||||
// completion?()
|
||||
// })
|
||||
// case .textFrame:
|
||||
// let text = String(data: data, encoding: .utf8)!
|
||||
// write(string: text, completion: completion)
|
||||
// case .ping:
|
||||
// task?.sendPing(pongReceiveHandler: { (error) in
|
||||
// completion?()
|
||||
// })
|
||||
// default:
|
||||
// break //unsupported
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private func doRead() {
|
||||
// task?.receive { [weak self] (result) in
|
||||
// switch result {
|
||||
// case .success(let message):
|
||||
// switch message {
|
||||
// case .string(let string):
|
||||
// self?.broadcast(event: .text(string))
|
||||
// case .data(let data):
|
||||
// self?.broadcast(event: .binary(data))
|
||||
// @unknown default:
|
||||
// break
|
||||
// }
|
||||
// break
|
||||
// case .failure(let error):
|
||||
// self?.broadcast(event: .error(error))
|
||||
// }
|
||||
// self?.doRead()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private func broadcast(event: WebSocketEvent) {
|
||||
// delegate?.didReceive(event: event)
|
||||
// }
|
||||
//}
|
||||
import Foundation
|
||||
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
public class NativeEngine: NSObject, Engine, URLSessionDataDelegate, URLSessionWebSocketDelegate {
|
||||
private var task: URLSessionWebSocketTask?
|
||||
weak var delegate: EngineDelegate?
|
||||
|
||||
public func register(delegate: EngineDelegate) {
|
||||
self.delegate = delegate
|
||||
}
|
||||
|
||||
public func start(request: URLRequest) {
|
||||
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil)
|
||||
task = session.webSocketTask(with: request)
|
||||
doRead()
|
||||
task?.resume()
|
||||
}
|
||||
|
||||
public func stop(closeCode: UInt16) {
|
||||
let closeCode = URLSessionWebSocketTask.CloseCode(rawValue: Int(closeCode)) ?? .normalClosure
|
||||
task?.cancel(with: closeCode, reason: nil)
|
||||
}
|
||||
|
||||
public func forceStop() {
|
||||
stop(closeCode: UInt16(URLSessionWebSocketTask.CloseCode.abnormalClosure.rawValue))
|
||||
}
|
||||
|
||||
public func write(string: String, completion: (() -> ())?) {
|
||||
task?.send(.string(string), completionHandler: { (error) in
|
||||
completion?()
|
||||
})
|
||||
}
|
||||
|
||||
public func write(data: Data, opcode: FrameOpCode, completion: (() -> ())?) {
|
||||
switch opcode {
|
||||
case .binaryFrame:
|
||||
task?.send(.data(data), completionHandler: { (error) in
|
||||
completion?()
|
||||
})
|
||||
case .textFrame:
|
||||
let text = String(data: data, encoding: .utf8)!
|
||||
write(string: text, completion: completion)
|
||||
case .ping:
|
||||
task?.sendPing(pongReceiveHandler: { (error) in
|
||||
completion?()
|
||||
})
|
||||
default:
|
||||
break //unsupported
|
||||
}
|
||||
}
|
||||
|
||||
private func doRead() {
|
||||
task?.receive { [weak self] (result) in
|
||||
switch result {
|
||||
case .success(let message):
|
||||
switch message {
|
||||
case .string(let string):
|
||||
self?.broadcast(event: .text(string))
|
||||
case .data(let data):
|
||||
self?.broadcast(event: .binary(data))
|
||||
@unknown default:
|
||||
break
|
||||
}
|
||||
break
|
||||
case .failure(let error):
|
||||
self?.broadcast(event: .error(error))
|
||||
}
|
||||
self?.doRead()
|
||||
}
|
||||
}
|
||||
|
||||
private func broadcast(event: WebSocketEvent) {
|
||||
delegate?.didReceive(event: event)
|
||||
}
|
||||
|
||||
public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?) {
|
||||
let p = `protocol` ?? ""
|
||||
broadcast(event: .connected([HTTPWSHeader.protocolName: p]))
|
||||
}
|
||||
|
||||
public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) {
|
||||
var r = ""
|
||||
if let d = reason {
|
||||
r = String(data: d, encoding: .utf8) ?? ""
|
||||
}
|
||||
broadcast(event: .disconnected(r, UInt16(closeCode.rawValue)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ FrameCollectorDelegate, HTTPHandlerDelegate {
|
||||
case .failed(let error):
|
||||
handleError(error)
|
||||
case .viability(let isViable):
|
||||
broadcast(event: .viablityChanged(isViable))
|
||||
broadcast(event: .viabilityChanged(isViable))
|
||||
case .shouldReconnect(let status):
|
||||
broadcast(event: .reconnectSuggested(status))
|
||||
case .receive(let data):
|
||||
@@ -157,6 +157,12 @@ FrameCollectorDelegate, HTTPHandlerDelegate {
|
||||
canSend = true
|
||||
mutex.signal()
|
||||
compressionHandler?.load(headers: headers)
|
||||
if let url = request.url {
|
||||
HTTPCookie.cookies(withResponseHeaderFields: headers, for: url).forEach {
|
||||
HTTPCookieStorage.shared.setCookie($0)
|
||||
}
|
||||
}
|
||||
|
||||
broadcast(event: .connected(headers))
|
||||
case .failure(let error):
|
||||
handleError(error)
|
||||
|
||||
@@ -183,6 +183,9 @@ public class WSFramer: Framer {
|
||||
closeCode = CloseCode.protocolError.rawValue
|
||||
dataLength = 0
|
||||
} else if payloadLen > 1 {
|
||||
if pointer.count < 4 {
|
||||
return .needsMoreData
|
||||
}
|
||||
let size = MemoryLayout<UInt16>.size
|
||||
closeCode = pointer.readUint16(offset: offset)
|
||||
offset += size
|
||||
|
||||
@@ -67,6 +67,13 @@ public struct HTTPWSHeader {
|
||||
req.setValue(HTTPWSHeader.versionValue, forHTTPHeaderField: HTTPWSHeader.versionName)
|
||||
req.setValue(secKeyValue, forHTTPHeaderField: HTTPWSHeader.keyName)
|
||||
|
||||
if let cookies = HTTPCookieStorage.shared.cookies(for: url), !cookies.isEmpty {
|
||||
let headers = HTTPCookie.requestHeaderFields(with: cookies)
|
||||
for (key, val) in headers {
|
||||
req.setValue(val, forHTTPHeaderField: key)
|
||||
}
|
||||
}
|
||||
|
||||
if supportsCompression {
|
||||
let val = "permessage-deflate; client_max_window_bits; server_max_window_bits=15"
|
||||
req.setValue(val, forHTTPHeaderField: HTTPWSHeader.extensionName)
|
||||
|
||||
@@ -101,10 +101,9 @@ public class StringHTTPHandler: HTTPHandler {
|
||||
code = c
|
||||
}
|
||||
} else {
|
||||
let responseSplit = str.components(separatedBy: ":")
|
||||
guard responseSplit.count > 1 else { break }
|
||||
let key = responseSplit[0].trimmingCharacters(in: .whitespaces)
|
||||
let val = responseSplit[1].trimmingCharacters(in: .whitespaces)
|
||||
guard let separatorIndex = str.firstIndex(of: ":") else { break }
|
||||
let key = str.prefix(upTo: separatorIndex).trimmingCharacters(in: .whitespaces)
|
||||
let val = str.suffix(from: str.index(after: separatorIndex)).trimmingCharacters(in: .whitespaces)
|
||||
headers[key.lowercased()] = val
|
||||
}
|
||||
i += 1
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>4.0.0</string>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
@@ -82,7 +82,7 @@ public enum WebSocketEvent {
|
||||
case pong(Data?)
|
||||
case ping(Data?)
|
||||
case error(Error?)
|
||||
case viablityChanged(Bool)
|
||||
case viabilityChanged(Bool)
|
||||
case reconnectSuggested(Bool)
|
||||
case cancelled
|
||||
}
|
||||
@@ -120,12 +120,10 @@ open class WebSocket: WebSocketClient, EngineDelegate {
|
||||
self.engine = engine
|
||||
}
|
||||
|
||||
public convenience init(request: URLRequest, certPinner: CertificatePinning? = FoundationSecurity(), compressionHandler: CompressionHandler? = nil) {
|
||||
//TODO: will release once Xcode 11 is out of beta
|
||||
// if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) {
|
||||
// self.init(request: request, engine: NativeEngine())
|
||||
// } else
|
||||
if #available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) {
|
||||
public convenience init(request: URLRequest, certPinner: CertificatePinning? = FoundationSecurity(), compressionHandler: CompressionHandler? = nil, useCustomEngine: Bool = true) {
|
||||
if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *), !useCustomEngine {
|
||||
self.init(request: request, engine: NativeEngine())
|
||||
} else if #available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) {
|
||||
self.init(request: request, engine: WSEngine(transport: TCPTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
|
||||
} else {
|
||||
self.init(request: request, engine: WSEngine(transport: FoundationTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
|
||||
|
||||
@@ -66,6 +66,12 @@ public class FoundationTransport: NSObject, Transport, StreamDelegate {
|
||||
inStream.delegate = self
|
||||
outStream.delegate = self
|
||||
|
||||
if isTLS {
|
||||
let key = CFStreamPropertyKey(rawValue: kCFStreamPropertySocketSecurityLevel)
|
||||
CFReadStreamSetProperty(inStream, key, kCFStreamSocketSecurityLevelNegotiatedSSL)
|
||||
CFWriteStreamSetProperty(outStream, key, kCFStreamSocketSecurityLevelNegotiatedSSL)
|
||||
}
|
||||
|
||||
onConnect?(inStream, outStream)
|
||||
|
||||
isOpen = false
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TCPTransport: Transport {
|
||||
sec_protocol_verify_complete(true)
|
||||
return
|
||||
}
|
||||
pinner.evaluateTrust(trust: trust, domain: url.absoluteString, completion: { (state) in
|
||||
pinner.evaluateTrust(trust: trust, domain: parts.host, completion: { (state) in
|
||||
switch state {
|
||||
case .success:
|
||||
sec_protocol_verify_complete(true)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Starscream"
|
||||
s.version = "4.0.0"
|
||||
s.version = "4.0.3"
|
||||
s.summary = "A conforming WebSocket RFC 6455 client library in Swift."
|
||||
s.homepage = "https://github.com/daltoniam/Starscream"
|
||||
s.license = 'Apache License, Version 2.0'
|
||||
|
||||
@@ -378,6 +378,7 @@
|
||||
buildSettings = {
|
||||
APPLICATION_EXTENSION_API_ONLY = NO;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
@@ -388,6 +389,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.vluxe.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator macosx";
|
||||
SUPPORTS_MACCATALYST = YES;
|
||||
SWIFT_INSTALL_OBJC_HEADER = NO;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
|
||||
@@ -400,12 +402,14 @@
|
||||
buildSettings = {
|
||||
APPLICATION_EXTENSION_API_ONLY = NO;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.vluxe.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator macosx";
|
||||
SUPPORTS_MACCATALYST = YES;
|
||||
SWIFT_INSTALL_OBJC_HEADER = NO;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
|
||||
@@ -427,10 +431,12 @@
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MARKETING_VERSION = 4.0.3;
|
||||
OTHER_LDFLAGS = "-all_load";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.vluxe.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SUPPORTS_MACCATALYST = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
|
||||
SWIFT_VERSION = 5.0;
|
||||
@@ -453,10 +459,12 @@
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MARKETING_VERSION = 4.0.3;
|
||||
OTHER_LDFLAGS = "-all_load";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.vluxe.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SUPPORTS_MACCATALYST = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
||||
@@ -60,7 +60,7 @@ class FuzzingTests: XCTestCase {
|
||||
print("reason: \(reason) code: \(code)")
|
||||
case .error(_):
|
||||
break
|
||||
case .viablityChanged(_):
|
||||
case .viabilityChanged(_):
|
||||
break
|
||||
case .reconnectSuggested(_):
|
||||
break
|
||||
|
||||
BIN
Binary file not shown.
@@ -44,7 +44,7 @@ class ViewController: UIViewController, WebSocketDelegate {
|
||||
// }
|
||||
// }
|
||||
//https://echo.websocket.org
|
||||
var request = URLRequest(url: URL(string: "http://localhost:8080")!)//https://localhost:8080
|
||||
var request = URLRequest(url: URL(string: "http://localhost:8080")!) //https://localhost:8080
|
||||
request.timeoutInterval = 5
|
||||
socket = WebSocket(request: request)
|
||||
socket.delegate = self
|
||||
@@ -68,7 +68,7 @@ class ViewController: UIViewController, WebSocketDelegate {
|
||||
break
|
||||
case .pong(_):
|
||||
break
|
||||
case .viablityChanged(_):
|
||||
case .viabilityChanged(_):
|
||||
break
|
||||
case .reconnectSuggested(_):
|
||||
break
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ or alternatively using `brew cask install fastlane`
|
||||
```
|
||||
fastlane ios release
|
||||
```
|
||||
Depoy new version
|
||||
Deploy new version
|
||||
|
||||
----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user