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
/// socket.
///
/// - parameter pack: The packet to handle.
open func handlePacket(_ pack: SocketPacket) {
func handleConnect(_ packetNamespace: String) {
guard packetNamespace == nsp else { return }
/// - parameter packet: The packet to handle.
open func handlePacket(_ packet: SocketPacket) {
guard packet.nsp == nsp else { return }
didConnect(toNamespace: packetNamespace)
}
switch pack.type {
switch packet.type {
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:
handleAck(pack.id, data: pack.data)
handleAck(packet.id, data: packet.data)
case .connect:
handleConnect(pack.nsp)
didConnect(toNamespace: nsp)
case .disconnect:
didDisconnect(reason: "Got Disconnect")
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
/// socket.
///
/// - parameter pack: The packet to handle.
func handlePacket(_ pack: SocketPacket)
/// - parameter packet: The packet to handle.
func handlePacket(_ packet: SocketPacket)
/// Call when you wish to leave a namespace and disconnect this socket.
func leaveNamespace()