|
19 | 19 | // THE SOFTWARE.
|
20 | 20 |
|
21 | 21 | import Foundation
|
22 |
| -import Starscream |
23 | 22 |
|
24 | 23 | #if canImport(FoundationNetworking)
|
25 | 24 | import FoundationNetworking
|
@@ -279,96 +278,3 @@ public class URLSessionTransport: NSObject, Transport, URLSessionWebSocketDelega
|
279 | 278 | delegate?.onClose(code: RealtimeClient.CloseCode.abnormal.rawValue)
|
280 | 279 | }
|
281 | 280 | }
|
282 |
| - |
283 |
| -public class StarscreamTransport: NSObject, Transport, WebSocketDelegate { |
284 |
| - /// The URL to connect to |
285 |
| - private let url: URL |
286 |
| - |
287 |
| - /// The underlying Starscream WebSocket that data is transfered over. |
288 |
| - private var socket: WebSocket? |
289 |
| - |
290 |
| - /** |
291 |
| - Initializes a `Transport` layer built using Starscream's WebSocket, which is available for |
292 |
| - previous iOS targets back to iOS 10. |
293 |
| - |
294 |
| - If you are targeting iOS 13 or later, then you do not need to use this transport layer unless |
295 |
| - you specifically prefer using Starscream as the underlying Socket connection. |
296 |
| - |
297 |
| - Example: |
298 |
| - |
299 |
| - ```swift |
300 |
| - let url = URL("wss://example.com/socket") |
301 |
| - let transport: Transport = StarscreamTransport(url: url) |
302 |
| - ``` |
303 |
| - |
304 |
| - - parameter url: URL to connect to |
305 |
| - */ |
306 |
| - public init(url: URL) { |
307 |
| - self.url = url |
308 |
| - super.init() |
309 |
| - } |
310 |
| - |
311 |
| - // MARK: - Transport |
312 |
| - |
313 |
| - public var readyState: TransportReadyState = .closed |
314 |
| - public var delegate: TransportDelegate? |
315 |
| - |
316 |
| - public func connect() { |
317 |
| - // Set the trasport state as connecting |
318 |
| - readyState = .connecting |
319 |
| - |
320 |
| - let socket = WebSocket(url: url) |
321 |
| - socket.delegate = self |
322 |
| - socket.connect() |
323 |
| - |
324 |
| - self.socket = socket |
325 |
| - } |
326 |
| - |
327 |
| - public func disconnect(code: Int, reason _: String?) { |
328 |
| - /* |
329 |
| - TODO: |
330 |
| - 1. Provide a "strict" mode that fails if an invalid close code is given |
331 |
| - 2. If strict mode is disabled, default to CloseCode.invalid |
332 |
| - 3. Provide default .normalClosure function |
333 |
| - */ |
334 |
| - guard |
335 |
| - let closeCode = CloseCode(rawValue: UInt16(code)) |
336 |
| - else { |
337 |
| - fatalError("Could not create a CloseCode with invalid code: [\(code)].") |
338 |
| - } |
339 |
| - |
340 |
| - readyState = .closing |
341 |
| - socket?.disconnect(closeCode: closeCode.rawValue) |
342 |
| - } |
343 |
| - |
344 |
| - public func send(data: Data) { |
345 |
| - socket?.write(data: data) |
346 |
| - } |
347 |
| - |
348 |
| - // MARK: - WebSocketDelegate |
349 |
| - |
350 |
| - public func websocketDidConnect(socket _: WebSocketClient) { |
351 |
| - readyState = .open |
352 |
| - delegate?.onOpen() |
353 |
| - } |
354 |
| - |
355 |
| - public func websocketDidDisconnect(socket _: WebSocketClient, error: Error?) { |
356 |
| - let closeCode = (error as? WSError)?.code ?? RealtimeClient.CloseCode.abnormal.rawValue |
357 |
| - // Set the state of the Transport to closed |
358 |
| - readyState = .closed |
359 |
| - |
360 |
| - // Inform the Transport's delegate that an error occurred. |
361 |
| - if let safeError = error { delegate?.onError(error: safeError) } |
362 |
| - |
363 |
| - // An abnormal error is results in an abnormal closure, such as internet getting dropped |
364 |
| - // so inform the delegate that the Transport has closed abnormally. This will kick off |
365 |
| - // the reconnect logic. |
366 |
| - delegate?.onClose(code: closeCode) |
367 |
| - } |
368 |
| - |
369 |
| - public func websocketDidReceiveMessage(socket _: WebSocketClient, text: String) { |
370 |
| - delegate?.onMessage(message: text) |
371 |
| - } |
372 |
| - |
373 |
| - public func websocketDidReceiveData(socket _: WebSocketClient, data _: Data) { /* no-op */ } |
374 |
| -} |
0 commit comments