refactor SocketIOClient.handlePacket

This commit is contained in:
Erik Little 2017-10-25 08:16:44 -04:00
parent c9e6d3ec33
commit 5cfc97386a
No known key found for this signature in database
GPG Key ID: 62F837E56F4E9320
2 changed files with 10 additions and 14 deletions

View File

@ -345,25 +345,21 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
/// Causes a client to handle a socket.io packet. The namespace for the packet must match the namespace of the /// Causes a client to handle a socket.io packet. The namespace for the packet must match the namespace of the
/// socket. /// socket.
/// ///
/// - parameter pack: The packet to handle. /// - parameter packet: The packet to handle.
open func handlePacket(_ pack: SocketPacket) { open func handlePacket(_ packet: SocketPacket) {
func handleConnect(_ packetNamespace: String) { guard packet.nsp == nsp else { return }
guard packetNamespace == nsp else { return }
didConnect(toNamespace: packetNamespace) switch packet.type {
}
switch pack.type {
case .event, .binaryEvent: case .event, .binaryEvent:
handleEvent(pack.event, data: pack.args, isInternalMessage: false, withAck: pack.id) handleEvent(packet.event, data: packet.args, isInternalMessage: false, withAck: packet.id)
case .ack, .binaryAck: case .ack, .binaryAck:
handleAck(pack.id, data: pack.data) handleAck(packet.id, data: packet.data)
case .connect: case .connect:
handleConnect(pack.nsp) didConnect(toNamespace: nsp)
case .disconnect: case .disconnect:
didDisconnect(reason: "Got Disconnect") didDisconnect(reason: "Got Disconnect")
case .error: case .error:
handleEvent("error", data: pack.data, isInternalMessage: true, withAck: pack.id) handleEvent("error", data: packet.data, isInternalMessage: true, withAck: packet.id)
} }
} }

View File

@ -140,8 +140,8 @@ public protocol SocketIOClientSpec : class {
/// Causes a client to handle a socket.io packet. The namespace for the packet must match the namespace of the /// Causes a client to handle a socket.io packet. The namespace for the packet must match the namespace of the
/// socket. /// socket.
/// ///
/// - parameter pack: The packet to handle. /// - parameter packet: The packet to handle.
func handlePacket(_ pack: SocketPacket) func handlePacket(_ packet: SocketPacket)
/// Call when you wish to leave a namespace and disconnect this socket. /// Call when you wish to leave a namespace and disconnect this socket.
func leaveNamespace() func leaveNamespace()