Skip to content

Commit 4eccf87

Browse files
committed
some ugly for linux
1 parent b85e42b commit 4eccf87

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

Source/SocketIO/Client/SocketIOClientOption.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
// THE SOFTWARE.
2424

25+
import Dispatch
2526
import Foundation
2627
#if !os(Linux)
2728
import StarscreamSocketIO

Source/SocketIO/Engine/SocketEngineClient.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import Foundation
2727

28+
#if !os(Linux)
2829
/// Declares that a type will be a delegate to an engine.
2930
@objc public protocol SocketEngineClient {
3031
// MARK: Methods
@@ -54,3 +55,34 @@ import Foundation
5455
/// - parameter data: The data the engine received.
5556
func parseEngineBinaryData(_ data: Data)
5657
}
58+
#else
59+
/// Declares that a type will be a delegate to an engine.
60+
public protocol SocketEngineClient : class {
61+
// MARK: Methods
62+
63+
/// Called when the engine errors.
64+
///
65+
/// - parameter reason: The reason the engine errored.
66+
func engineDidError(reason: String)
67+
68+
/// Called when the engine closes.
69+
///
70+
/// - parameter reason: The reason that the engine closed.
71+
func engineDidClose(reason: String)
72+
73+
/// Called when the engine opens.
74+
///
75+
/// - parameter reason: The reason the engine opened.
76+
func engineDidOpen(reason: String)
77+
78+
/// Called when the engine has a message that must be parsed.
79+
///
80+
/// - parameter msg: The message that needs parsing.
81+
func parseEngineMessage(_ msg: String)
82+
83+
/// Called when the engine receives binary data.
84+
///
85+
/// - parameter data: The data the engine received.
86+
func parseEngineBinaryData(_ data: Data)
87+
}
88+
#endif

Source/SocketIO/Engine/SocketEngineSpec.swift

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
// THE SOFTWARE.
2424
//
2525

26+
import Dispatch
2627
import Foundation
2728
#if !os(Linux)
2829
import StarscreamSocketIO
2930
#else
3031
import WebSockets
3132
#endif
3233

34+
#if !os(Linux)
3335
/// Specifies a SocketEngine.
3436
@objc public protocol SocketEngineSpec {
3537
/// The client for this engine.
@@ -74,6 +76,7 @@ import WebSockets
7476
/// Whether or not this engine uses secure transports
7577
var secure: Bool { get }
7678

79+
/// A custom security validator for Starscream. Useful for SSL pinning.
7780
var security: SSLSecurity? { get }
7881

7982
/// Whether or not to allow self signed certificates.
@@ -146,6 +149,123 @@ import WebSockets
146149
/// - parameter withData: Any data that this message has.
147150
func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data])
148151
}
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
149269

150270
extension SocketEngineSpec {
151271
var urlPollingWithSid: URL {

0 commit comments

Comments
 (0)