redo types

This commit is contained in:
Erik 2015-04-08 20:51:44 -04:00
parent 903c578e75
commit eb5d03c88b
7 changed files with 69 additions and 44 deletions

View File

@ -24,13 +24,6 @@
import Foundation
// @objc_block is undocumented, but is used because Swift assumes that all
// Objective-C blocks are copied, but Objective-C assumes that Swift will copy it.
// And the way things are done here, the bridging fails to copy the block in
// SocketAckMap#addAck
public typealias AckCallback = @objc_block (NSArray?) -> Void
public typealias OnAckCallback = (timeout:UInt64, callback:AckCallback) -> Void
struct SocketAckMap {
private var acks = [Int: AckCallback]()
private var waiting = [Int: Bool]()

View File

@ -30,20 +30,10 @@ extension String {
}
}
private typealias Probe = (msg:String, type:PacketType, data:ContiguousArray<NSData>?)
private typealias ProbeWaitQueue = [Probe]
public enum PacketType:String {
case OPEN = "0"
case CLOSE = "1"
case PING = "2"
case PONG = "3"
case MESSAGE = "4"
case UPGRADE = "5"
case NOOP = "6"
}
public class SocketEngine: NSObject, WebSocketDelegate {
private typealias Probe = (msg:String, type:PacketType, data:ContiguousArray<NSData>?)
private typealias ProbeWaitQueue = [Probe]
private let workQueue = NSOperationQueue()
private let emitQueue = dispatch_queue_create(
"engineEmitQueue".cStringUsingEncoding(NSUTF8StringEncoding), DISPATCH_QUEUE_SERIAL)
@ -83,6 +73,16 @@ public class SocketEngine: NSObject, WebSocketDelegate {
return self._websocket
}
var ws:WebSocket?
public enum PacketType:String {
case OPEN = "0"
case CLOSE = "1"
case PING = "2"
case PONG = "3"
case MESSAGE = "4"
case UPGRADE = "5"
case NOOP = "6"
}
public init(client:SocketEngineClient, forcePolling:Bool,
forceWebsockets:Bool, withCookies cookies:[NSHTTPCookie]?) {

View File

@ -24,9 +24,6 @@
import Foundation
public typealias NormalCallback = (NSArray?, AckEmitter?) -> Void
public typealias AckEmitter = (AnyObject...) -> Void
private func emitAckCallback(socket:SocketIOClient, num:Int)
// Curried
(items:AnyObject...) -> Void {

View File

@ -3,6 +3,7 @@
// Socket.IO-Swift
//
// Created by Erik Little on 3/16/15.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights

View File

@ -306,7 +306,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
}
let packet = SocketPacket(type: nil, data: args, nsp: self.nsp, id: ack)
var str:String
let str:String
SocketParser.parseForEmit(packet)
str = packet.createMessageForEvent(event)
@ -326,7 +326,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
}
let packet = SocketPacket(type: nil, data: args, nsp: self!.nsp, id: ack)
var str:String
let str:String
SocketParser.parseForEmit(packet)
str = packet.createAck()

View File

@ -24,24 +24,6 @@
import Foundation
enum SocketPacketType:Int {
case CONNECT = 0
case DISCONNECT = 1
case EVENT = 2
case ACK = 3
case ERROR = 4
case BINARY_EVENT = 5
case BINARY_ACK = 6
init(str:String) {
if let int = str.toInt() {
self = SocketPacketType(rawValue: int)!
} else {
self = SocketPacketType(rawValue: 4)!
}
}
}
class SocketPacket {
var binary = ContiguousArray<NSData>()
var currentPlace = 0
@ -90,7 +72,7 @@ class SocketPacket {
}
func createMessageForEvent(event:String) -> String {
var message:String
let message:String
var jsonSendError:NSError?
if self.binary.count == 0 {

52
SwiftIO/SocketTypes.swift Normal file
View File

@ -0,0 +1,52 @@
//
// SocketTypes.swift
// SocketIO-Swift
//
// Created by Erik Little on 4/8/15.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import Foundation
// @objc_block is undocumented, but is used because Swift assumes that all
// Objective-C blocks are copied, but Objective-C assumes that Swift will copy it.
// And the way things are done here, the bridging fails to copy the block in
// SocketAckMap#addAck
public typealias AckCallback = @objc_block (NSArray?) -> Void
public typealias AckEmitter = (AnyObject...) -> Void
public typealias NormalCallback = (NSArray?, AckEmitter?) -> Void
public typealias OnAckCallback = (timeout:UInt64, callback:AckCallback) -> Void
enum SocketPacketType:Int {
case CONNECT = 0
case DISCONNECT = 1
case EVENT = 2
case ACK = 3
case ERROR = 4
case BINARY_EVENT = 5
case BINARY_ACK = 6
init(str:String) {
if let int = str.toInt() {
self = SocketPacketType(rawValue: int)!
} else {
self = SocketPacketType(rawValue: 4)!
}
}
}