Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
* development:
  Refactor engine. Fix infinite recursion in configuration
  Don't send whole packet to handleConnect
  • Loading branch information
nuclearace committed Aug 27, 2016
2 parents e3c8cc7 + bd7f943 commit 89ab458
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
58 changes: 30 additions & 28 deletions Source/SocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,36 +359,38 @@ public final class SocketEngine : NSObject, NSURLSessionDelegate, SocketEnginePo
private func handleOpen(openData: String) {
do {
let json = try openData.toNSDictionary()
guard let sid = json[sid] as? String else {
client?.engineDidError("Open packet contained no sid")
return
}

if let sid = json["sid"] as? String {
let upgradeWs: Bool

self.sid = sid
connected = true

if let upgrades = json["upgrades"] as? [String] {
upgradeWs = upgrades.contains("websocket")
} else {
upgradeWs = false
}

if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
self.pingInterval = pingInterval / 1000.0
self.pingTimeout = pingTimeout / 1000.0
}

if !forcePolling && !forceWebsockets && upgradeWs {
createWebsocketAndConnect()
}

sendPing()

if !forceWebsockets {
doPoll()
}

client?.engineDidOpen("Connect")
let upgradeWs: Bool

self.sid = sid
connected = true

if let upgrades = json["upgrades"] as? [String] {
upgradeWs = upgrades.contains("websocket")
} else {
upgradeWs = false
}

if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
self.pingInterval = pingInterval / 1000.0
self.pingTimeout = pingTimeout / 1000.0
}

if !forcePolling && !forceWebsockets && upgradeWs {
createWebsocketAndConnect()
}

sendPing()

if !forceWebsockets {
doPoll()
}

client?.engineDidOpen("Connect")
} catch {
didError("Error parsing open packet")
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SocketIOClientConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public struct SocketIOClientConfiguration : ArrayLiteralConvertible, CollectionT

@warn_unused_result
public func prefixThrough(position: Index) -> SubSequence {
return prefixThrough(position)
return backingArray.prefixThrough(position)
}

@warn_unused_result
Expand Down
6 changes: 3 additions & 3 deletions Source/SocketParsable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extension SocketParsable {
return nsp == self.nsp
}

private func handleConnect(p: SocketPacket) {
if p.nsp == "/" && nsp != "/" {
private func handleConnect(packetNamespace: String) {
if packetNamespace == "/" && nsp != "/" {
joinNamespace(nsp)
} else {
didConnect()
Expand All @@ -51,7 +51,7 @@ extension SocketParsable {
case .BinaryAck where isCorrectNamespace(pack.nsp):
waitingPackets.append(pack)
case .Connect:
handleConnect(pack)
handleConnect(pack.nsp)
case .Disconnect:
didDisconnect("Got Disconnect")
case .Error:
Expand Down

0 comments on commit 89ab458

Please sign in to comment.