This commit is contained in:
Erik 2015-03-28 16:16:03 -04:00
parent 57731bebf8
commit da1cf9eb89
3 changed files with 38 additions and 4 deletions

View File

@ -0,0 +1,35 @@
//
// SocketAnyEvent.swift
// Socket.IO-Swift
//
// Created by Erik Little on 3/28/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 public class SocketAnyEvent {
public let event:String!
public var items:[AnyObject]?
init(event:String, items:[AnyObject]?) {
self.event = event
self.items = items
}
}

View File

@ -25,7 +25,6 @@
import Foundation
public typealias NormalCallback = (NSArray?, AckEmitter?) -> Void
public typealias AnyHandler = (event:String, items:AnyObject?)
public typealias AckEmitter = (AnyObject...) -> Void
private func emitAckCallback(socket:SocketIOClient, num:Int)

View File

@ -28,7 +28,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
let reconnectAttempts:Int!
private lazy var params = [String: AnyObject]()
private var ackHandlers = ContiguousArray<SocketAckHandler>()
private var anyHandler:((AnyHandler) -> Void)?
private var anyHandler:((SocketAnyEvent) -> Void)?
private var _closed = false
private var _connected = false
private var _connecting = false
@ -360,7 +360,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
if self.anyHandler != nil {
dispatch_async(dispatch_get_main_queue()) {[weak self] in
self?.anyHandler?((event, data))
self?.anyHandler?(SocketAnyEvent(event: event, items: data))
return
}
}
@ -400,7 +400,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
/**
Adds a handler that will be called on every event.
*/
public func onAny(handler:(AnyHandler) -> Void) {
public func onAny(handler:(SocketAnyEvent) -> Void) {
self.anyHandler = handler
}