commit
3275816769
|
|
@ -66,7 +66,7 @@ public final class OnAckCallback : NSObject {
|
|||
DefaultSocketLogger.Logger.log("OnAckCallback for \(ackNumber) being released", type: "OnAckCallback")
|
||||
}
|
||||
|
||||
public func timingOut(after seconds: Int, callback: @escaping AckCallback) {
|
||||
@objc public func timingOut(after seconds: Int, callback: @escaping AckCallback) {
|
||||
guard let socket = self.socket else { return }
|
||||
|
||||
socket.ackQueue.sync() {
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||
|
||||
private func handleBase64(message: String) {
|
||||
// binary in base64 string
|
||||
let noPrefix = message[message.index(message.startIndex, offsetBy: 2)..<message.endIndex]
|
||||
let noPrefix = String(message[message.index(message.startIndex, offsetBy: 2)..<message.endIndex])
|
||||
|
||||
if let data = NSData(base64Encoded: noPrefix, options: .ignoreUnknownCharacters) {
|
||||
client?.parseEngineBinaryData(data as Data)
|
||||
|
|
@ -437,13 +437,13 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||
|
||||
switch type {
|
||||
case .message:
|
||||
handleMessage(String(fixedString.characters.dropFirst()))
|
||||
handleMessage(String(fixedString.dropFirst()))
|
||||
case .noop:
|
||||
handleNOOP()
|
||||
case .pong:
|
||||
handlePong(with: fixedString)
|
||||
case .open:
|
||||
handleOpen(openData: String(fixedString.characters.dropFirst()))
|
||||
handleOpen(openData: String(fixedString.dropFirst()))
|
||||
case .close:
|
||||
handleClose(fixedString)
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ extension SocketEnginePollable {
|
|||
var postStr = ""
|
||||
|
||||
for packet in postWait {
|
||||
let len = packet.characters.count
|
||||
let len = packet.count
|
||||
|
||||
postStr += "\(len):\(packet)"
|
||||
}
|
||||
|
|
@ -183,7 +183,7 @@ extension SocketEnginePollable {
|
|||
}
|
||||
|
||||
func parsePollingMessage(_ str: String) {
|
||||
guard str.characters.count != 1 else { return }
|
||||
guard str.count != 1 else { return }
|
||||
|
||||
var reader = SocketStringReader(message: str)
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||
|
||||
/// Not so type safe way to create a SocketIOClient, meant for Objective-C compatiblity.
|
||||
/// If using Swift it's recommended to use `init(socketURL: NSURL, options: Set<SocketIOClientOption>)`
|
||||
public convenience init(socketURL: NSURL, config: NSDictionary?) {
|
||||
@objc public convenience init(socketURL: NSURL, config: NSDictionary?) {
|
||||
self.init(socketURL: socketURL as URL, config: config?.toSocketConfiguration() ?? [])
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||
|
||||
/// Connect to the server. If we aren't connected after timeoutAfter, call withHandler
|
||||
/// 0 Never times out
|
||||
public func connect(timeoutAfter: Int, withHandler handler: (() -> Void)?) {
|
||||
@objc public func connect(timeoutAfter: Int, withHandler handler: (() -> Void)?) {
|
||||
assert(timeoutAfter >= 0, "Invalid timeout: \(timeoutAfter)")
|
||||
|
||||
guard status != .connected else {
|
||||
|
|
@ -196,7 +196,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||
}
|
||||
|
||||
/// Disconnects the socket.
|
||||
public func disconnect() {
|
||||
@objc public func disconnect() {
|
||||
DefaultSocketLogger.Logger.log("Closing socket", type: logType)
|
||||
|
||||
didDisconnect(reason: "Disconnect")
|
||||
|
|
@ -208,7 +208,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||
}
|
||||
|
||||
/// Same as emit, but meant for Objective-C
|
||||
public func emit(_ event: String, with items: [Any]) {
|
||||
@objc public func emit(_ event: String, with items: [Any]) {
|
||||
guard status == .connected else {
|
||||
handleEvent("error", data: ["Tried emitting \(event) when not connected"], isInternalMessage: true)
|
||||
return
|
||||
|
|
@ -224,7 +224,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||
}
|
||||
|
||||
/// Same as emitWithAck, but for Objective-C
|
||||
public func emitWithAck(_ event: String, with items: [Any]) -> OnAckCallback {
|
||||
@objc public func emitWithAck(_ event: String, with items: [Any]) -> OnAckCallback {
|
||||
return createOnAck([event] + items)
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +347,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||
/// Adds a handler for an event.
|
||||
/// Returns: A unique id for the handler
|
||||
@discardableResult
|
||||
public func on(_ event: String, callback: @escaping NormalCallback) -> UUID {
|
||||
@objc public func on(_ event: String, callback: @escaping NormalCallback) -> UUID {
|
||||
DefaultSocketLogger.Logger.log("Adding handler for event: %@", type: logType, args: event)
|
||||
|
||||
let handler = SocketEventHandler(event: event, id: UUID(), callback: callback)
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ extension SocketParsable {
|
|||
|
||||
|
||||
|
||||
var dataArray = message[message.characters.index(reader.currentIndex, offsetBy: 1)..<message.endIndex]
|
||||
var dataArray = String(message[message.index(reader.currentIndex, offsetBy: 1)..<message.endIndex])
|
||||
|
||||
if type == .error && !dataArray.hasPrefix("[") && !dataArray.hasSuffix("]") {
|
||||
dataArray = "[" + dataArray + "]"
|
||||
|
|
|
|||
|
|
@ -40,17 +40,17 @@ struct SocketStringReader {
|
|||
|
||||
@discardableResult
|
||||
mutating func advance(by: Int) -> String.Index {
|
||||
currentIndex = message.characters.index(currentIndex, offsetBy: by)
|
||||
currentIndex = message.index(currentIndex, offsetBy: by)
|
||||
|
||||
return currentIndex
|
||||
}
|
||||
|
||||
mutating func read(count: Int) -> String {
|
||||
let readString = message[currentIndex..<message.characters.index(currentIndex, offsetBy: count)]
|
||||
let readString = message[currentIndex..<message.index(currentIndex, offsetBy: count)]
|
||||
|
||||
advance(by: count)
|
||||
|
||||
return readString
|
||||
return String(readString)
|
||||
}
|
||||
|
||||
mutating func readUntilOccurence(of string: String) -> String {
|
||||
|
|
@ -59,15 +59,15 @@ struct SocketStringReader {
|
|||
guard let foundRange = substring.range(of: string) else {
|
||||
currentIndex = message.endIndex
|
||||
|
||||
return substring
|
||||
return String(substring)
|
||||
}
|
||||
|
||||
advance(by: message.characters.distance(from: message.characters.startIndex, to: foundRange.lowerBound) + 1)
|
||||
advance(by: message.distance(from: message.startIndex, to: foundRange.lowerBound) + 1)
|
||||
|
||||
return substring.substring(to: foundRange.lowerBound)
|
||||
return String(substring[..<foundRange.lowerBound])
|
||||
}
|
||||
|
||||
mutating func readUntilEnd() -> String {
|
||||
return read(count: message.characters.distance(from: currentIndex, to: message.endIndex))
|
||||
return read(count: message.distance(from: currentIndex, to: message.endIndex))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ open class WebSocket : NSObject, StreamDelegate {
|
|||
|
||||
|
||||
// MARK: - Block based API.
|
||||
public var onConnect: ((Void) -> Void)?
|
||||
public var onConnect: (() -> Void)?
|
||||
public var onDisconnect: ((NSError?) -> Void)?
|
||||
public var onText: ((String) -> Void)?
|
||||
public var onData: ((Data) -> Void)?
|
||||
|
|
|
|||
Loading…
Reference in New Issue