Skip to content

Commit b1177fe

Browse files
committed
It compiles
1 parent 42da871 commit b1177fe

23 files changed

+176
-85
lines changed

Package.resolved

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
{
2-
"object": {
3-
"pins": [
4-
{
5-
"package": "Starscream",
6-
"repositoryURL": "https://github.com/daltoniam/Starscream",
7-
"state": {
8-
"branch": null,
9-
"revision": "c6bfd1af48efcc9a9ad203665db12375ba6b145a",
10-
"version": "4.0.8"
11-
}
2+
"pins" : [
3+
{
4+
"identity" : "starscream",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/theleftbit/Starscream.git",
7+
"state" : {
8+
"branch" : "android",
9+
"revision" : "fd27e744f358663eb8802692269000f45a630138"
1210
}
13-
]
14-
},
15-
"version": 1
11+
},
12+
{
13+
"identity" : "swift-asn1",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/apple/swift-asn1.git",
16+
"state" : {
17+
"revision" : "7faebca1ea4f9aaf0cda1cef7c43aecd2311ddf6",
18+
"version" : "1.3.0"
19+
}
20+
},
21+
{
22+
"identity" : "swift-crypto",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/apple/swift-crypto.git",
25+
"state" : {
26+
"revision" : "ff0f781cf7c6a22d52957e50b104f5768b50c779",
27+
"version" : "3.10.0"
28+
}
29+
}
30+
],
31+
"version" : 2
1632
}

Package.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version:5.9
22

33
import PackageDescription
44

55
let package = Package(
66
name: "SocketIO",
7+
platforms: [
8+
.iOS(.v13),
9+
.macOS(.v10_15),
10+
.tvOS(.v13),
11+
.watchOS(.v6)
12+
],
713
products: [
814
.library(name: "SocketIO", targets: ["SocketIO"])
915
],
1016
dependencies: [
11-
.package(url: "https://github.com/daltoniam/Starscream", .upToNextMajor(from: "4.0.8")),
17+
.package(url: "https://github.com/theleftbit/Starscream.git", branch: "android"),
1218
],
1319
targets: [
1420
.target(name: "SocketIO", dependencies: ["Starscream"]),

Source/SocketIO/Ack/SocketAckEmitter.swift

-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public final class SocketAckEmitter: NSObject {
4141
/// ```
4242
///
4343
/// **NOTE**: It is not safe to hold on to this view beyond the life of the socket.
44-
@objc
4544
public private(set) lazy var rawEmitView = SocketRawAckView(socket: socket, ackNum: ackNum)
4645

4746
// MARK: Properties
@@ -83,7 +82,6 @@ public final class SocketAckEmitter: NSObject {
8382
/// Call to ack receiving this event.
8483
///
8584
/// - parameter items: An array of items to send when acking. Use `[]` to send nothing.
86-
@objc
8785
public func with(_ items: [Any]) {
8886
guard ackNum != -1 else { return }
8987

@@ -127,7 +125,6 @@ public final class OnAckCallback: NSObject {
127125
/// - parameter seconds: The number of seconds before this emit times out if an ack hasn't been received.
128126
/// - parameter callback: The callback called when an ack is received, or when a timeout happens.
129127
/// To check for timeout, use `SocketAckStatus`'s `noAck` case.
130-
@objc
131128
public func timingOut(after seconds: Double, callback: @escaping AckCallback) {
132129
guard let socket = self.socket, ackNumber != -1 else { return }
133130

Source/SocketIO/Client/SocketAnyEvent.swift

-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ public final class SocketAnyEvent : NSObject {
2929
// MARK: Properties
3030

3131
/// The event name.
32-
@objc
3332
public let event: String
3433

3534
/// The data items for this event.
36-
@objc
3735
public let items: [Any]?
3836

3937
/// The description of this event.

Source/SocketIO/Client/SocketIOClient.swift

+14-8
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
212212
/// - parameter event: The event to send.
213213
/// - parameter items: The items to send with this event. May be left out.
214214
/// - parameter completion: Callback called on transport write completion.
215-
open func emit(_ event: String, _ items: SocketData..., completion: (() -> ())? = nil) {
215+
open func emit(_ event: String, _ items: SocketData..., completion: (@Sendable() -> ())? = nil) {
216216
emit(event, with: items, completion: completion)
217217
}
218218

@@ -224,7 +224,7 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
224224
/// - parameter event: The event to send.
225225
/// - parameter items: The items to send with this event. May be left out.
226226
/// - parameter completion: Callback called on transport write completion.
227-
open func emit(_ event: String, with items: [SocketData], completion: (() -> ())?) {
227+
open func emit(_ event: String, with items: [SocketData], completion: (@Sendable () -> ())?) {
228228

229229
do {
230230
emit([event] + (try items.map({ try $0.socketRepresentation() })), completion: completion)
@@ -296,15 +296,21 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
296296
ack: Int? = nil,
297297
binary: Bool = true,
298298
isAck: Bool = false,
299-
completion: (() -> ())? = nil
299+
completion: (@Sendable () -> ())? = nil
300300
) {
301301
// wrap the completion handler so it always runs async via handlerQueue
302-
let wrappedCompletion: (() -> ())? = (completion == nil) ? nil : {[weak self] in
303-
guard let this = self else { return }
304-
this.manager?.handleQueue.async {
305-
completion!()
302+
let wrappedCompletion: (@Sendable () -> ())? = {
303+
if let completion {
304+
return completion
305+
} else {
306+
return { [weak self] in
307+
guard let this = self else { return }
308+
this.manager?.handleQueue.async {
309+
completion!()
310+
}
311+
}
306312
}
307-
}
313+
}()
308314

309315
guard status == .connected else {
310316
wrappedCompletion?()

Source/SocketIO/Client/SocketIOClientOption.swift

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
import Foundation
2626
import Starscream
27+
#if os(Android)
28+
import FoundationNetworking
29+
#endif
2730

2831
/// The socket.io version being used.
2932
public enum SocketIOVersion: Int {

Source/SocketIO/Client/SocketIOClientSpec.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public protocol SocketIOClientSpec : AnyObject {
106106
/// - parameter event: The event to send.
107107
/// - parameter items: The items to send with this event. May be left out.
108108
/// - parameter completion: Callback called on transport write completion.
109-
func emit(_ event: String, _ items: SocketData..., completion: (() -> ())?)
109+
func emit(_ event: String, _ items: SocketData..., completion: (@Sendable () -> ())?)
110110

111111
/// Send an event to the server, with optional data items and optional write completion handler.
112112
///
@@ -116,7 +116,7 @@ public protocol SocketIOClientSpec : AnyObject {
116116
/// - parameter event: The event to send.
117117
/// - parameter items: The items to send with this event. May be left out.
118118
/// - parameter completion: Callback called on transport write completion.
119-
func emit(_ event: String, with items: [SocketData], completion: (() -> ())?)
119+
func emit(_ event: String, with items: [SocketData], completion: (@Sendable () -> ())?)
120120

121121
/// Call when you wish to tell the server that you've received the event for `ack`.
122122
///

Source/SocketIO/Client/SocketIOStatus.swift

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import Foundation
2626

2727
/// Represents state of a manager or client.
28-
@objc
2928
public enum SocketIOStatus : Int, CustomStringConvertible {
3029
// MARK: Cases
3130

Source/SocketIO/Client/SocketRawView.swift

-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public final class SocketRawView : NSObject {
6060
///
6161
/// - parameter event: The event to send.
6262
/// - parameter items: The items to send with this event. Send an empty array to send no data.
63-
@objc
6463
public func emit(_ event: String, with items: [Any]) {
6564
socket.emit([event] + items, binary: false)
6665
}
@@ -113,7 +112,6 @@ public final class SocketRawView : NSObject {
113112
/// - parameter event: The event to send.
114113
/// - parameter items: The items to send with this event. Use `[]` to send nothing.
115114
/// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent.
116-
@objc
117115
public func emitWithAck(_ event: String, with items: [Any]) -> OnAckCallback {
118116
return socket.createOnAck([event] + items, binary: false)
119117
}
@@ -154,7 +152,6 @@ public final class SocketRawAckView : NSObject {
154152
/// Call to ack receiving this event.
155153
///
156154
/// - parameter items: An array of items to send when acking. Use `[]` to send nothing.
157-
@objc
158155
public func with(_ items: [Any]) {
159156
guard ackNum != -1 else { return }
160157

Source/SocketIO/Engine/SocketEngine.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import Dispatch
2626
import Foundation
2727
import Starscream
28+
#if os(Android)
29+
import FoundationNetworking
30+
#endif
2831

2932
/// The class that handles the engine.io protocol and transports.
3033
/// See `SocketEnginePollable` and `SocketEngineWebsocket` for transport specific methods.
@@ -563,7 +566,11 @@ open class SocketEngine: NSObject, WebSocketDelegate, URLSessionDelegate,
563566
polling = true
564567
probing = false
565568
invalidated = false
569+
#if os(Android)
570+
session = FoundationNetworking.URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: queue)
571+
#else
566572
session = Foundation.URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: queue)
573+
#endif
567574
sid = ""
568575
waitingForPoll = false
569576
waitingForPost = false
@@ -656,7 +663,7 @@ open class SocketEngine: NSObject, WebSocketDelegate, URLSessionDelegate,
656663
/// - parameter type: The type of this message.
657664
/// - parameter data: Any data that this message has.
658665
/// - parameter completion: Callback called on transport write completion.
659-
open func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: (() -> ())? = nil) {
666+
open func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: (@Sendable () -> ())? = nil) {
660667
engineQueue.async {
661668
guard self.connected else {
662669
completion?()

Source/SocketIO/Engine/SocketEngineClient.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
//
2525

2626
import Foundation
27+
#if os(Android)
28+
import FoundationNetworking
29+
#endif
2730

2831
/// Declares that a type will be a delegate to an engine.
29-
@objc public protocol SocketEngineClient {
32+
public protocol SocketEngineClient: AnyObject {
3033
// MARK: Methods
3134

3235
/// Called when the engine errors.

Source/SocketIO/Engine/SocketEnginePacketType.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import Foundation
2727

2828
/// Represents the type of engine.io packet types.
29-
@objc public enum SocketEnginePacketType: Int {
29+
public enum SocketEnginePacketType: Int {
3030
/// Open message.
3131
case open
3232

Source/SocketIO/Engine/SocketEnginePollable.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
// THE SOFTWARE.
2424

2525
import Foundation
26+
#if os(Android)
27+
import FoundationNetworking
28+
#endif
2629

2730
/// Protocol that is used to implement socket.io polling support
2831
public protocol SocketEnginePollable: SocketEngineSpec {
@@ -65,7 +68,7 @@ public protocol SocketEnginePollable: SocketEngineSpec {
6568
/// - parameter message: The message to send.
6669
/// - parameter withType: The type of message to send.
6770
/// - parameter withData: The data associated with this message.
68-
func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: (() -> ())?)
71+
func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: (@Sendable () -> ())?)
6972

7073
/// Call to stop polling and invalidate the URLSession.
7174
func stopPolling()
@@ -237,7 +240,7 @@ extension SocketEnginePollable {
237240
/// - parameter withType: The type of message to send.
238241
/// - parameter withData: The data associated with this message.
239242
/// - parameter completion: Callback called on transport write completion.
240-
public func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: (() -> ())? = nil) {
243+
public func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: (@Sendable () -> ())? = nil) {
241244
DefaultSocketLogger.Logger.log("Sending poll: \(message) as type: \(type.rawValue)", type: "SocketEnginePolling")
242245

243246
postWait.append((String(type.rawValue) + message, completion))

Source/SocketIO/Engine/SocketEngineSpec.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
import Foundation
2727
import Starscream
28+
#if os(Android)
29+
import FoundationNetworking
30+
#endif
2831

2932
/// Specifies a SocketEngine.
3033
public protocol SocketEngineSpec: AnyObject {
@@ -141,7 +144,7 @@ public protocol SocketEngineSpec: AnyObject {
141144
/// - parameter type: The type of this message.
142145
/// - parameter data: Any data that this message has.
143146
/// - parameter completion: Callback called on transport write completion.
144-
func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: (() -> ())?)
147+
func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: (@Sendable () -> ())?)
145148
}
146149

147150
extension SocketEngineSpec {
@@ -203,7 +206,7 @@ extension SocketEngineSpec {
203206
}
204207

205208
/// Send an engine message (4)
206-
func send(_ msg: String, withData datas: [Data], completion: (() -> ())? = nil) {
209+
func send(_ msg: String, withData datas: [Data], completion: (@Sendable () -> ())? = nil) {
207210
write(msg, withType: .message, withData: datas, completion: completion)
208211
}
209212
}

Source/SocketIO/Engine/SocketEngineWebsocket.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public protocol SocketEngineWebsocket: SocketEngineSpec {
4646
func sendWebSocketMessage(_ str: String,
4747
withType type: SocketEnginePacketType,
4848
withData datas: [Data],
49-
completion: (() -> ())?)
49+
completion: (@Sendable () -> ())?)
5050
}
5151

5252
// WebSocket methods
@@ -68,7 +68,7 @@ extension SocketEngineWebsocket {
6868
public func sendWebSocketMessage(_ str: String,
6969
withType type: SocketEnginePacketType,
7070
withData data: [Data],
71-
completion: (() -> ())?
71+
completion: (@Sendable () -> ())?
7272
) {
7373
DefaultSocketLogger.Logger.log("Sending ws: \(str) as type: \(type.rawValue)", type: "SocketEngineWebSocket")
7474

Source/SocketIO/Manager/SocketManager.swift

-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ open class SocketManager: NSObject, SocketManagerSpec, SocketParsable, SocketDat
155155
///
156156
/// - parameter socketURL: The url of the socket.io server.
157157
/// - parameter config: The config for this socket.
158-
@objc
159158
public convenience init(socketURL: URL, config: [String: Any]?) {
160159
self.init(socketURL: socketURL, config: config?.toSocketConfiguration() ?? [])
161160
}

Source/SocketIO/Util/SocketExtensions.swift

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
import Foundation
2626
import Starscream
27+
#if os(Android)
28+
import FoundationNetworking
29+
#endif
2730

2831
enum JSONError : Error {
2932
case notArray

Source/SocketIO/Util/SocketTypes.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public typealias AckCallback = ([Any]) -> ()
7474
public typealias NormalCallback = ([Any], SocketAckEmitter) -> ()
7575

7676
/// A typealias for a queued POST
77-
public typealias Post = (msg: String, completion: (() -> ())?)
77+
public typealias Post = (msg: String, completion: (@Sendable () -> ())?)
7878

7979
typealias JSON = [String: Any]
80-
typealias Probe = (msg: String, type: SocketEnginePacketType, data: [Data], completion: (() -> ())?)
80+
typealias Probe = (msg: String, type: SocketEnginePacketType, data: [Data], completion: (@Sendable () -> ())?)
8181
typealias ProbeWaitQueue = [Probe]
8282

8383
enum Either<E, V> {

Tests/TestSocketIO/SocketAckManagerTest.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class SocketAckManagerTest : XCTestCase {
2323
ackManager.addAck(1, callback: callback)
2424
ackManager.executeAck(1, with: itemsArray)
2525

26-
waitForExpectations(timeout: 3.0, handler: nil)
26+
let result = XCTWaiter().wait(for: [callbackExpection], timeout: 3)
27+
XCTAssert(result == .completed)
2728
}
2829

2930
func testManagerTimeoutAck() {
@@ -45,6 +46,7 @@ class SocketAckManagerTest : XCTestCase {
4546
ackManager.addAck(1, callback: callback)
4647
ackManager.timeoutAck(1)
4748

48-
waitForExpectations(timeout: 0.2, handler: nil)
49+
let result = XCTWaiter().wait(for: [callbackExpection], timeout: 0.2)
50+
XCTAssert(result == .completed)
4951
}
5052
}

0 commit comments

Comments
 (0)