|
23 | 23 | // THE SOFTWARE.
|
24 | 24 | //
|
25 | 25 |
|
| 26 | +import Dispatch |
26 | 27 | import Foundation
|
27 | 28 | #if !os(Linux)
|
28 | 29 | import StarscreamSocketIO
|
29 | 30 | #else
|
30 | 31 | import WebSockets
|
31 | 32 | #endif
|
32 | 33 |
|
| 34 | +#if !os(Linux) |
33 | 35 | /// Specifies a SocketEngine.
|
34 | 36 | @objc public protocol SocketEngineSpec {
|
35 | 37 | /// The client for this engine.
|
@@ -74,6 +76,7 @@ import WebSockets
|
74 | 76 | /// Whether or not this engine uses secure transports
|
75 | 77 | var secure: Bool { get }
|
76 | 78 |
|
| 79 | + /// A custom security validator for Starscream. Useful for SSL pinning. |
77 | 80 | var security: SSLSecurity? { get }
|
78 | 81 |
|
79 | 82 | /// Whether or not to allow self signed certificates.
|
@@ -146,6 +149,123 @@ import WebSockets
|
146 | 149 | /// - parameter withData: Any data that this message has.
|
147 | 150 | func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data])
|
148 | 151 | }
|
| 152 | +#else |
| 153 | +public protocol SocketEngineSpec : class { |
| 154 | + /// The client for this engine. |
| 155 | + var client: SocketEngineClient? { get set } |
| 156 | + |
| 157 | + /// `true` if this engine is closed. |
| 158 | + var closed: Bool { get } |
| 159 | + |
| 160 | + /// `true` if this engine is connected. Connected means that the initial poll connect has succeeded. |
| 161 | + var connected: Bool { get } |
| 162 | + |
| 163 | + /// The connect parameters sent during a connect. |
| 164 | + var connectParams: [String: Any]? { get set } |
| 165 | + |
| 166 | + /// Whether or not to use WebSocket compression. |
| 167 | + var compress: Bool { get } |
| 168 | + |
| 169 | + /// An array of HTTPCookies that are sent during the connection. |
| 170 | + var cookies: [HTTPCookie]? { get } |
| 171 | + |
| 172 | + /// The queue that all engine actions take place on. |
| 173 | + var engineQueue: DispatchQueue { get } |
| 174 | + |
| 175 | + /// A dictionary of extra http headers that will be set during connection. |
| 176 | + var extraHeaders: [String: String]? { get } |
| 177 | + |
| 178 | + /// When `true`, the engine is in the process of switching to WebSockets. |
| 179 | + var fastUpgrade: Bool { get } |
| 180 | + |
| 181 | + /// When `true`, the engine will only use HTTP long-polling as a transport. |
| 182 | + var forcePolling: Bool { get } |
| 183 | + |
| 184 | + /// When `true`, the engine will only use WebSockets as a transport. |
| 185 | + var forceWebsockets: Bool { get } |
| 186 | + |
| 187 | + /// If `true`, the engine is currently in HTTP long-polling mode. |
| 188 | + var polling: Bool { get } |
| 189 | + |
| 190 | + /// If `true`, the engine is currently seeing whether it can upgrade to WebSockets. |
| 191 | + var probing: Bool { get } |
| 192 | + |
| 193 | + /// Whether or not this engine uses secure transports |
| 194 | + var secure: Bool { get } |
| 195 | + |
| 196 | + var security: SSLSecurity? { get } |
| 197 | + |
| 198 | + /// Whether or not to allow self signed certificates. |
| 199 | + var selfSigned: Bool { get } |
| 200 | + |
| 201 | + /// The session id for this engine. |
| 202 | + var sid: String { get } |
| 203 | + |
| 204 | + /// The path to engine.io. |
| 205 | + var socketPath: String { get } |
| 206 | + |
| 207 | + /// The url for polling. |
| 208 | + var urlPolling: URL { get } |
| 209 | + |
| 210 | + /// The url for WebSockets. |
| 211 | + var urlWebSocket: URL { get } |
| 212 | + |
| 213 | + /// If `true`, then the engine is currently in WebSockets mode. |
| 214 | + var websocket: Bool { get } |
| 215 | + |
| 216 | + /// The WebSocket for this engine. |
| 217 | + var ws: WebSocket? { get set } |
| 218 | + |
| 219 | + /// Creates a new engine. |
| 220 | + /// |
| 221 | + /// - parameter client: The client for this engine. |
| 222 | + /// - parameter url: The url for this engine. |
| 223 | + /// - parameter options: The options for this engine. |
| 224 | + init(client: SocketEngineClient, url: URL, options: NSDictionary?) |
| 225 | + |
| 226 | + /// Starts the connection to the server. |
| 227 | + func connect() |
| 228 | + |
| 229 | + /// Called when an error happens during execution. Causes a disconnection. |
| 230 | + func didError(reason: String) |
| 231 | + |
| 232 | + /// Disconnects from the server. |
| 233 | + /// |
| 234 | + /// - parameter reason: The reason for the disconnection. This is communicated up to the client. |
| 235 | + func disconnect(reason: String) |
| 236 | + |
| 237 | + /// Called to switch from HTTP long-polling to WebSockets. After calling this method the engine will be in |
| 238 | + /// WebSocket mode. |
| 239 | + /// |
| 240 | + /// **You shouldn't call this directly** |
| 241 | + func doFastUpgrade() |
| 242 | + |
| 243 | + /// Causes any packets that were waiting for POSTing to be sent through the WebSocket. This happens because when |
| 244 | + /// the engine is attempting to upgrade to WebSocket it does not do any POSTing. |
| 245 | + /// |
| 246 | + /// **You shouldn't call this directly** |
| 247 | + func flushWaitingForPostToWebSocket() |
| 248 | + |
| 249 | + /// Parses raw binary received from engine.io. |
| 250 | + /// |
| 251 | + /// - parameter data: The data to parse. |
| 252 | + func parseEngineData(_ data: Data) |
| 253 | + |
| 254 | + /// Parses a raw engine.io packet. |
| 255 | + /// |
| 256 | + /// - parameter message: The message to parse. |
| 257 | + /// - parameter fromPolling: Whether this message is from long-polling. |
| 258 | + /// If `true` we might have to fix utf8 encoding. |
| 259 | + func parseEngineMessage(_ message: String) |
| 260 | + |
| 261 | + /// Writes a message to engine.io, independent of transport. |
| 262 | + /// |
| 263 | + /// - parameter msg: The message to send. |
| 264 | + /// - parameter withType: The type of this message. |
| 265 | + /// - parameter withData: Any data that this message has. |
| 266 | + func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data]) |
| 267 | +} |
| 268 | +#endif |
149 | 269 |
|
150 | 270 | extension SocketEngineSpec {
|
151 | 271 | var urlPollingWithSid: URL {
|
|
0 commit comments