Merge branch '1.2'
This commit is contained in:
commit
a0dff2fea4
@ -26,7 +26,7 @@ import Foundation
|
||||
|
||||
extension String {
|
||||
private var length:Int {
|
||||
return countElements(self)
|
||||
return count(self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
|
||||
urlWebSocket += "&\(keyEsc)="
|
||||
|
||||
if value is String {
|
||||
let valueEsc = (value as String).stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
let valueEsc = (value as! String).stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
NSCharacterSet.URLHostAllowedCharacterSet())!
|
||||
urlPolling += "\(valueEsc)"
|
||||
urlWebSocket += "\(valueEsc)"
|
||||
@ -227,6 +227,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
|
||||
}
|
||||
|
||||
self?.waitingForPoll = false
|
||||
|
||||
if self!.fastUpgrade {
|
||||
self?.doFastUpgrade()
|
||||
return
|
||||
@ -266,7 +267,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
|
||||
var postStr = ""
|
||||
|
||||
for packet in self.postWait {
|
||||
let len = countElements(packet)
|
||||
let len = count(packet)
|
||||
|
||||
postStr += "\(len):\(packet)"
|
||||
}
|
||||
@ -320,6 +321,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
|
||||
}
|
||||
|
||||
// A poll failed, tell the client about it
|
||||
|
||||
private func handlePollingFailed(reason:String) {
|
||||
self._connected = false
|
||||
self.ws?.disconnect()
|
||||
|
||||
@ -195,7 +195,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
return
|
||||
}
|
||||
|
||||
self?.ackHandlers.addAck(ack, callback)
|
||||
self?.ackHandlers.addAck(ack, callback: callback)
|
||||
|
||||
dispatch_async(self!.emitQueue) {
|
||||
self?._emit(event, items, ack: ack)
|
||||
@ -344,7 +344,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
var ackData:[AnyObject]?
|
||||
|
||||
if data is NSArray {
|
||||
ackData = data as? NSArray
|
||||
ackData = (data as? [AnyObject]?)!
|
||||
} else if data != nil {
|
||||
ackData = [data!]
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ class SocketPacket {
|
||||
}
|
||||
|
||||
func getEvent() -> String {
|
||||
return data?.removeAtIndex(0) as String
|
||||
return data?.removeAtIndex(0) as! String
|
||||
}
|
||||
|
||||
func addData(data:NSData) -> Bool {
|
||||
@ -164,7 +164,6 @@ class SocketPacket {
|
||||
}
|
||||
|
||||
for arg in self.data! {
|
||||
|
||||
if arg is NSDictionary || arg is [AnyObject] {
|
||||
let jsonSend = NSJSONSerialization.dataWithJSONObject(arg,
|
||||
options: NSJSONWritingOptions(0), error: &err)
|
||||
@ -205,7 +204,7 @@ class SocketPacket {
|
||||
}
|
||||
}
|
||||
|
||||
self.data = newArr
|
||||
self.data = newArr as [AnyObject]
|
||||
}
|
||||
|
||||
private func _fillInPlaceholders(data:AnyObject) -> AnyObject {
|
||||
@ -219,7 +218,7 @@ class SocketPacket {
|
||||
var newDict = NSMutableDictionary(dictionary: dict)
|
||||
|
||||
for (key, value) in dict {
|
||||
newDict[key as NSCopying] = _fillInPlaceholders(value)
|
||||
newDict[key as! NSCopying] = _fillInPlaceholders(value)
|
||||
}
|
||||
|
||||
return newDict
|
||||
|
||||
@ -22,9 +22,9 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
private let shredder = SocketParser.PacketShredder()
|
||||
|
||||
class SocketParser {
|
||||
private static let shredder = SocketParser.PacketShredder()
|
||||
|
||||
// Translation of socket.io-parser#deconstructPacket
|
||||
private class PacketShredder {
|
||||
var buf = ContiguousArray<NSData>()
|
||||
@ -48,7 +48,7 @@ class SocketParser {
|
||||
var newDict = NSMutableDictionary(dictionary: dict)
|
||||
|
||||
for (key, value) in newDict {
|
||||
newDict[key as NSCopying] = shred(value)
|
||||
newDict[key as! NSCopying] = shred(value)
|
||||
}
|
||||
|
||||
return newDict
|
||||
@ -148,7 +148,7 @@ class SocketParser {
|
||||
let d = String(arr[++i...arr.count-1])
|
||||
let noPlaceholders = d["(\\{\"_placeholder\":true,\"num\":(\\d*)\\})"] ~= "\"~~$2\""
|
||||
|
||||
let data = SocketParser.parseData(noPlaceholders) as [AnyObject]
|
||||
let data = SocketParser.parseData(noPlaceholders) as! [AnyObject]
|
||||
|
||||
return SocketPacket(type: SocketPacketType(str: type), data: data,
|
||||
nsp: nsp, placeholders: placeholders, id: id)
|
||||
|
||||
@ -43,7 +43,7 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
}
|
||||
|
||||
final var targetRange: NSRange {
|
||||
return NSRange(location: 0,length: countElements(target.utf16))
|
||||
return NSRange(location: 0,length: count(target.utf16))
|
||||
}
|
||||
|
||||
final func substring(range: NSRange) -> String? {
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
import Foundation
|
||||
import CoreFoundation
|
||||
|
||||
public protocol WebSocketDelegate: class {
|
||||
func websocketDidConnect(socket: WebSocket)
|
||||
@ -236,8 +235,8 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
if self.selfSignedSSL {
|
||||
let settings: Dictionary<NSObject, NSObject> = [kCFStreamSSLValidatesCertificateChain: NSNumber(bool:false), kCFStreamSSLPeerName: kCFNull]
|
||||
inputStream!.setProperty(settings, forKey: kCFStreamPropertySSLSettings)
|
||||
outputStream!.setProperty(settings, forKey: kCFStreamPropertySSLSettings)
|
||||
inputStream!.setProperty(settings, forKey: kCFStreamPropertySSLSettings as String)
|
||||
outputStream!.setProperty(settings, forKey: kCFStreamPropertySSLSettings as String)
|
||||
}
|
||||
isRunLoop = true
|
||||
inputStream!.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
|
||||
@ -247,18 +246,18 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
let bytes = UnsafePointer<UInt8>(data.bytes)
|
||||
outputStream!.write(bytes, maxLength: data.length)
|
||||
while(isRunLoop) {
|
||||
NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture() as NSDate)
|
||||
NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture() as! NSDate)
|
||||
}
|
||||
}
|
||||
//delegate for the stream methods. Processes incoming bytes
|
||||
func stream(aStream: NSStream!, handleEvent eventCode: NSStreamEvent) {
|
||||
public func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {
|
||||
|
||||
if eventCode == .HasBytesAvailable {
|
||||
if(aStream == inputStream) {
|
||||
processInputStream()
|
||||
}
|
||||
} else if eventCode == .ErrorOccurred {
|
||||
disconnectStream(aStream!.streamError)
|
||||
disconnectStream(aStream.streamError)
|
||||
} else if eventCode == .EndEncountered {
|
||||
disconnectStream(nil)
|
||||
}
|
||||
@ -333,7 +332,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
///Finds the HTTP Packet in the TCP stream, by looking for the CRLF.
|
||||
private func processHTTP(buffer: UnsafePointer<UInt8>, bufferLen: Int) -> Bool {
|
||||
let CRLFBytes = [UInt8("\r"), UInt8("\n"), UInt8("\r"), UInt8("\n")]
|
||||
let CRLFBytes = [UInt8(ascii: "\r"), UInt8(ascii: "\n"), UInt8(ascii: "\r"), UInt8(ascii: "\n")]
|
||||
var k = 0
|
||||
var totalSize = 0
|
||||
for var i = 0; i < bufferLen; i++ {
|
||||
@ -376,7 +375,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
let cfHeaders = CFHTTPMessageCopyAllHeaderFields(response.takeUnretainedValue())
|
||||
let headers: NSDictionary = cfHeaders.takeUnretainedValue()
|
||||
let acceptKey = headers[headerWSAcceptName] as NSString
|
||||
let acceptKey = headers[headerWSAcceptName] as! NSString
|
||||
if acceptKey.length > 0 {
|
||||
return true
|
||||
}
|
||||
@ -500,7 +499,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
data = NSData(bytes: UnsafePointer<UInt8>((buffer+offset)), length: Int(len))
|
||||
}
|
||||
if receivedOpcode == OpCode.Pong.rawValue {
|
||||
let step = Int(offset+len)
|
||||
let step = offset + Int(len)
|
||||
let extra = bufferLen-step
|
||||
if extra > 0 {
|
||||
processRawMessage((buffer+step), bufferLen: extra)
|
||||
@ -565,7 +564,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
processResponse(response!)
|
||||
}
|
||||
|
||||
let step = Int(offset+len)
|
||||
let step = offset + Int(len)
|
||||
let extra = bufferLen-step
|
||||
if(extra > 0) {
|
||||
processExtra((buffer+step), bufferLen: extra)
|
||||
@ -597,9 +596,9 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
dispatch_async(queue,{
|
||||
if let textBlock = self.receivedTextBlock{
|
||||
textBlock(str!)
|
||||
textBlock(str! as String)
|
||||
}
|
||||
self.delegate?.websocketDidReceiveMessage(self, text: str!)
|
||||
self.delegate?.websocketDidReceiveMessage(self, text: str! as String)
|
||||
})
|
||||
} else if response.code == .BinaryFrame {
|
||||
let data = response.buffer! //local copy so it is perverse for writing
|
||||
@ -673,7 +672,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
buffer[1] |= self.MaskMask
|
||||
var maskKey = UnsafeMutablePointer<UInt8>(buffer + offset)
|
||||
SecRandomCopyBytes(kSecRandomDefault, UInt(sizeof(UInt32)), maskKey)
|
||||
SecRandomCopyBytes(kSecRandomDefault, Int(sizeof(UInt32)), maskKey)
|
||||
offset += sizeof(UInt32)
|
||||
|
||||
for (var i = 0; i < dataLength; i++) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user