Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd48abe4cd | ||
|
|
acfbcb6fe1 | ||
|
|
47f5dcbbcd | ||
|
|
a161ed1756 | ||
|
|
3fda340ad1 | ||
|
|
e33309827f | ||
|
|
1753707bf8 | ||
|
|
cc99eae737 | ||
|
|
446cf57978 | ||
|
|
80cee820a4 | ||
|
|
e4c2da515b | ||
|
|
bb4d285928 |
No files matched your search
@@ -47,9 +47,13 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8
|
||||
- Can be used from Objective-C
|
||||
|
||||
##Installation
|
||||
Requires Swift 1.2/Xcode 6.3
|
||||
|
||||
If you need Swift 1.1/Xcode 6.2 use v1.5.2. (Pre-Swift 1.2 support is no longer maintained)
|
||||
Manually (iOS 7+)
|
||||
-----------------
|
||||
1. Copy the SocketIOClientSwift folder into your Xcode project
|
||||
1. Copy the SocketIOClientSwift folder into your Xcode project. (Make sure you add the files to your target(s))
|
||||
2. If you plan on using this from Objective-C, read [this](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) on exposing Swift code to Objective-C.
|
||||
|
||||
CocoaPods 0.36.0 or later (iOS 8+)
|
||||
------------------
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Socket.IO-Client-Swift"
|
||||
s.version = "2.0.5"
|
||||
s.version = "2.0.6"
|
||||
s.summary = "Socket.IO-client for iOS and OS X"
|
||||
s.description = <<-DESC
|
||||
Socket.IO-client for iOS and OS X.
|
||||
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
|
||||
s.author = { "Erik" => "nuclear.ace@gmail.com" }
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.osx.deployment_target = '10.10'
|
||||
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.0.5' }
|
||||
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.0.6' }
|
||||
s.source_files = "SocketIOClientSwift/**/*.swift"
|
||||
s.requires_arc = true
|
||||
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
|
||||
|
||||
@@ -104,6 +104,10 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
||||
delegate: sessionDelegate, delegateQueue: self.workQueue)
|
||||
}
|
||||
|
||||
deinit {
|
||||
SocketLogger.log("Engine is being deinit", client: self)
|
||||
}
|
||||
|
||||
public func close(#fast:Bool) {
|
||||
self.pingTimer?.invalidate()
|
||||
self.closed = true
|
||||
@@ -121,7 +125,9 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
||||
var byteArray = [UInt8](count: 1, repeatedValue: 0x0)
|
||||
byteArray[0] = 4
|
||||
var mutData = NSMutableData(bytes: &byteArray, length: 1)
|
||||
|
||||
mutData.appendData(data)
|
||||
|
||||
return (mutData, nil)
|
||||
} else {
|
||||
var str = "b4"
|
||||
@@ -150,15 +156,17 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
||||
}
|
||||
|
||||
if params != nil {
|
||||
let allowedCharacterSet = NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" ").invertedSet
|
||||
|
||||
for (key, value) in params! {
|
||||
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
NSCharacterSet.URLHostAllowedCharacterSet())!
|
||||
allowedCharacterSet)!
|
||||
urlPolling += "&\(keyEsc)="
|
||||
urlWebSocket += "&\(keyEsc)="
|
||||
|
||||
if value is String {
|
||||
let valueEsc = (value as! String).stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
NSCharacterSet.URLHostAllowedCharacterSet())!
|
||||
allowedCharacterSet)!
|
||||
urlPolling += "\(valueEsc)"
|
||||
urlWebSocket += "\(valueEsc)"
|
||||
} else {
|
||||
@@ -409,11 +417,10 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
||||
func testLength(length:String, inout n:Int) -> Bool {
|
||||
if let num = length.toInt() {
|
||||
n = num
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
for var i = 0, l = str.length; i < l; i = i &+ 1 {
|
||||
@@ -498,7 +505,8 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
||||
message.removeAtIndex(message.startIndex)
|
||||
let mesData = message.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
|
||||
|
||||
if let json = NSJSONSerialization.JSONObjectWithData(mesData, options: NSJSONReadingOptions.AllowFragments,
|
||||
if let json = NSJSONSerialization.JSONObjectWithData(mesData,
|
||||
options: NSJSONReadingOptions.AllowFragments,
|
||||
error: &err) as? NSDictionary, let sid = json["sid"] as? String {
|
||||
self.sid = sid
|
||||
self._connected = true
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class SocketIOClient: NSObject, NSURLSessionDelegate, SocketEngineClient, SocketLogClient {
|
||||
public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient {
|
||||
private lazy var params = [String: AnyObject]()
|
||||
private var anyHandler:((SocketAnyEvent) -> Void)?
|
||||
private var _closed = false
|
||||
@@ -40,7 +40,6 @@ public final class SocketIOClient: NSObject, NSURLSessionDelegate, SocketEngineC
|
||||
private var _reconnecting = false
|
||||
private var reconnectTimer:NSTimer?
|
||||
|
||||
|
||||
let reconnectAttempts:Int!
|
||||
let logType = "SocketClient"
|
||||
var ackHandlers = SocketAckManager()
|
||||
@@ -144,6 +143,10 @@ public final class SocketIOClient: NSObject, NSURLSessionDelegate, SocketEngineC
|
||||
self.init(socketURL: socketURL, opts: options)
|
||||
}
|
||||
|
||||
deinit {
|
||||
SocketLogger.log("Client is being deinit", client: self)
|
||||
}
|
||||
|
||||
private func addEngine() {
|
||||
SocketLogger.log("Adding engine", client: self)
|
||||
|
||||
@@ -344,7 +347,7 @@ public final class SocketIOClient: NSObject, NSURLSessionDelegate, SocketEngineC
|
||||
str = packet.createAck()
|
||||
|
||||
SocketLogger.log("Emitting Ack: \(str)", client: self!)
|
||||
|
||||
|
||||
if packet.type == SocketPacket.PacketType.BINARY_ACK {
|
||||
self?.engine?.send(str, withData: packet.binary)
|
||||
} else {
|
||||
|
||||
@@ -37,8 +37,8 @@ final class SocketLogger {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(printQueue) {
|
||||
NSLog("%@: %@", altType ?? client.logType, message)
|
||||
dispatch_async(printQueue) {[type = client.logType] in
|
||||
NSLog("%@: %@", altType ?? type, message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ final class SocketLogger {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(printQueue) {
|
||||
NSLog("ERROR %@: %@", altType ?? client.logType, message)
|
||||
dispatch_async(printQueue) {[type = client.logType] in
|
||||
NSLog("ERROR %@: %@", altType ?? type, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,10 +242,7 @@ class SocketParser {
|
||||
}
|
||||
}
|
||||
|
||||
// Handles binary data
|
||||
static func parseBinaryData(data:NSData, socket:SocketIOClient) {
|
||||
// NSLog(data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros))
|
||||
|
||||
if socket.waitingData.count == 0 {
|
||||
SocketLogger.err("Got data when not remaking packet", client: socket, altType: "SocketParser")
|
||||
return
|
||||
|
||||
@@ -152,7 +152,7 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
pos = matchRange.location + matchRange.length
|
||||
}
|
||||
|
||||
out.appendString(substring( NSRange(location:pos, length:targetRange.length-pos))!)
|
||||
out.appendString(substring(NSRange(location:pos, length:targetRange.length-pos))!)
|
||||
|
||||
return out as String
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user