some ugly for linux

This commit is contained in:
Erik Little 2017-09-17 10:35:52 -04:00
parent b85e42bbf9
commit 4eccf87ecc
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D
3 changed files with 153 additions and 0 deletions

View File

@ -22,6 +22,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import Dispatch
import Foundation
#if !os(Linux)
import StarscreamSocketIO

View File

@ -25,6 +25,7 @@
import Foundation
#if !os(Linux)
/// Declares that a type will be a delegate to an engine.
@objc public protocol SocketEngineClient {
// MARK: Methods
@ -54,3 +55,34 @@ import Foundation
/// - parameter data: The data the engine received.
func parseEngineBinaryData(_ data: Data)
}
#else
/// Declares that a type will be a delegate to an engine.
public protocol SocketEngineClient : class {
// MARK: Methods
/// Called when the engine errors.
///
/// - parameter reason: The reason the engine errored.
func engineDidError(reason: String)
/// Called when the engine closes.
///
/// - parameter reason: The reason that the engine closed.
func engineDidClose(reason: String)
/// Called when the engine opens.
///
/// - parameter reason: The reason the engine opened.
func engineDidOpen(reason: String)
/// Called when the engine has a message that must be parsed.
///
/// - parameter msg: The message that needs parsing.
func parseEngineMessage(_ msg: String)
/// Called when the engine receives binary data.
///
/// - parameter data: The data the engine received.
func parseEngineBinaryData(_ data: Data)
}
#endif

View File

@ -23,6 +23,7 @@
// THE SOFTWARE.
//
import Dispatch
import Foundation
#if !os(Linux)
import StarscreamSocketIO
@ -30,6 +31,7 @@ import StarscreamSocketIO
import WebSockets
#endif
#if !os(Linux)
/// Specifies a SocketEngine.
@objc public protocol SocketEngineSpec {
/// The client for this engine.
@ -74,6 +76,123 @@ import WebSockets
/// Whether or not this engine uses secure transports
var secure: Bool { get }
/// A custom security validator for Starscream. Useful for SSL pinning.
var security: SSLSecurity? { get }
/// Whether or not to allow self signed certificates.
var selfSigned: Bool { get }
/// The session id for this engine.
var sid: String { get }
/// The path to engine.io.
var socketPath: String { get }
/// The url for polling.
var urlPolling: URL { get }
/// The url for WebSockets.
var urlWebSocket: URL { get }
/// If `true`, then the engine is currently in WebSockets mode.
var websocket: Bool { get }
/// The WebSocket for this engine.
var ws: WebSocket? { get set }
/// Creates a new engine.
///
/// - parameter client: The client for this engine.
/// - parameter url: The url for this engine.
/// - parameter options: The options for this engine.
init(client: SocketEngineClient, url: URL, options: NSDictionary?)
/// Starts the connection to the server.
func connect()
/// Called when an error happens during execution. Causes a disconnection.
func didError(reason: String)
/// Disconnects from the server.
///
/// - parameter reason: The reason for the disconnection. This is communicated up to the client.
func disconnect(reason: String)
/// Called to switch from HTTP long-polling to WebSockets. After calling this method the engine will be in
/// WebSocket mode.
///
/// **You shouldn't call this directly**
func doFastUpgrade()
/// Causes any packets that were waiting for POSTing to be sent through the WebSocket. This happens because when
/// the engine is attempting to upgrade to WebSocket it does not do any POSTing.
///
/// **You shouldn't call this directly**
func flushWaitingForPostToWebSocket()
/// Parses raw binary received from engine.io.
///
/// - parameter data: The data to parse.
func parseEngineData(_ data: Data)
/// Parses a raw engine.io packet.
///
/// - parameter message: The message to parse.
/// - parameter fromPolling: Whether this message is from long-polling.
/// If `true` we might have to fix utf8 encoding.
func parseEngineMessage(_ message: String)
/// Writes a message to engine.io, independent of transport.
///
/// - parameter msg: The message to send.
/// - parameter withType: The type of this message.
/// - parameter withData: Any data that this message has.
func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data])
}
#else
public protocol SocketEngineSpec : class {
/// The client for this engine.
var client: SocketEngineClient? { get set }
/// `true` if this engine is closed.
var closed: Bool { get }
/// `true` if this engine is connected. Connected means that the initial poll connect has succeeded.
var connected: Bool { get }
/// The connect parameters sent during a connect.
var connectParams: [String: Any]? { get set }
/// Whether or not to use WebSocket compression.
var compress: Bool { get }
/// An array of HTTPCookies that are sent during the connection.
var cookies: [HTTPCookie]? { get }
/// The queue that all engine actions take place on.
var engineQueue: DispatchQueue { get }
/// A dictionary of extra http headers that will be set during connection.
var extraHeaders: [String: String]? { get }
/// When `true`, the engine is in the process of switching to WebSockets.
var fastUpgrade: Bool { get }
/// When `true`, the engine will only use HTTP long-polling as a transport.
var forcePolling: Bool { get }
/// When `true`, the engine will only use WebSockets as a transport.
var forceWebsockets: Bool { get }
/// If `true`, the engine is currently in HTTP long-polling mode.
var polling: Bool { get }
/// If `true`, the engine is currently seeing whether it can upgrade to WebSockets.
var probing: Bool { get }
/// Whether or not this engine uses secure transports
var secure: Bool { get }
var security: SSLSecurity? { get }
/// Whether or not to allow self signed certificates.
@ -146,6 +265,7 @@ import WebSockets
/// - parameter withData: Any data that this message has.
func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data])
}
#endif
extension SocketEngineSpec {
var urlPollingWithSid: URL {