Compare commits

...
3 Commits
Author SHA1 Message Date
Erik 58571e5387 bump version 2015-06-07 13:15:03 -04:00
Erik 1a54decd51 fix socketio/socket.io-client-swift#93 2015-06-06 22:30:56 -04:00
Erik d982cdc1b2 only do interpolation when logging 2015-06-06 13:15:22 -04:00
5 changed files with 52 additions and 30 deletions

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Socket.IO-Client-Swift"
s.version = "2.3.3"
s.version = "2.3.4"
s.summary = "Socket.IO-client for iOS and OS X"
s.description = <<-DESC
Socket.IO-client for iOS and OS X.
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.author = { "Erik" => "nuclear.ace@gmail.com" }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.3.3' }
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.3.4' }
s.source_files = "SocketIOClientSwift/**/*.swift"
s.requires_arc = true
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
+11 -9
View File
@@ -116,7 +116,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
}
public func close(#fast:Bool) {
SocketLogger.log("Engine is being closed. Fast: \(fast)", client: self)
SocketLogger.log("Engine is being closed. Fast: %@", client: self, args: fast)
pingTimer?.invalidate()
closed = true
@@ -324,7 +324,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
waitingForPost = true
SocketLogger.log("POSTing: \(postStr)", client: self)
SocketLogger.log("POSTing: %@", client: self, args: postStr)
session.dataTaskWithRequest(req) {[weak self] data, res, err in
if let this = self {
@@ -509,7 +509,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
length += chr
} else {
if length == "" || testLength(length, &n) {
SocketLogger.err("Parsing error: \(str)", client: self)
SocketLogger.err("Parsing error: %@", client: self, args: str)
handlePollingFailed("Error parsing XHR message")
return
}
@@ -517,7 +517,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
msg = String(strArray[i+1...i+n])
if let lengthInt = length.toInt() where lengthInt != count(msg) {
SocketLogger.err("parsing error: \(str)", client: self)
SocketLogger.err("Parsing error: %@", client: self, args: str)
return
}
@@ -543,7 +543,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
}
private func parseEngineMessage(var message:String, fromPolling:Bool) {
SocketLogger.log("Got message: \(message)", client: self)
SocketLogger.log("Got message: %@", client: self, args: message)
if fromPolling {
fixDoubleUTF8(&message)
@@ -603,7 +603,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
/// Only call on emitQueue
private func sendPollMessage(var msg:String, withType type:PacketType,
datas:ContiguousArray<NSData>? = nil) {
SocketLogger.log("Sending poll: \(msg) as type: \(type.rawValue)", client: self)
SocketLogger.log("Sending poll: %@ as type: %@", client: self, args: msg, type.rawValue)
doubleEncodeUTF8(&msg)
let strMsg = "\(type.rawValue)\(msg)"
@@ -627,7 +627,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
/// Only call on emitQueue
private func sendWebSocketMessage(str:String, withType type:PacketType,
datas:ContiguousArray<NSData>? = nil) {
SocketLogger.log("Sending ws: \(str) as type: \(type.rawValue)", client: self)
SocketLogger.log("Sending ws: %@ as type: %@", client: self, args: str, type.rawValue)
ws?.writeString("\(type.rawValue)\(str)")
@@ -678,10 +678,12 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
dispatch_async(emitQueue) {[weak self] in
if let this = self where this.connected {
if this.websocket {
SocketLogger.log("Writing ws: \(msg):\(data)", client: this)
SocketLogger.log("Writing ws: %@ has data: %@", client: this,
args: msg, data == nil ? false : true)
this.sendWebSocketMessage(msg, withType: type, datas: data)
} else {
SocketLogger.log("Writing poll: \(msg):\(data)", client: this)
SocketLogger.log("Writing poll: %@ has data: %@", client: this,
args: msg, data == nil ? false : true)
this.sendPollMessage(msg, withType: type, datas: data)
}
}
+13 -10
View File
@@ -131,6 +131,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
deinit {
SocketLogger.log("Client is being deinit", client: self)
engine?.close(fast: true)
}
private func addEngine() {
@@ -235,7 +236,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
return
}
SocketLogger.log("Disconnected: \(reason)", client: self)
SocketLogger.log("Disconnected: %@", client: self, args: reason)
_closed = true
_connected = false
@@ -250,7 +251,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
/// error
public func didError(reason:AnyObject) {
SocketLogger.err("Error: \(reason)", client: self)
SocketLogger.err("%@", client: self, args: reason)
handleEvent("error", data: reason as? [AnyObject] ?? [reason],
isInternalMessage: true)
@@ -323,7 +324,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
SocketParser.parseForEmit(packet)
str = packet.createMessageForEvent(event)
SocketLogger.log("Emitting: \(str)", client: self)
SocketLogger.log("Emitting: %@", client: self, args: str)
if packet.type == SocketPacket.PacketType.BINARY_EVENT {
engine?.send(str, withData: packet.binary)
@@ -342,7 +343,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
SocketParser.parseForEmit(packet)
str = packet.createAck()
SocketLogger.log("Emitting Ack: \(str)", client: this)
SocketLogger.log("Emitting Ack: %@", client: this, args: str)
if packet.type == SocketPacket.PacketType.BINARY_ACK {
this.engine?.send(str, withData: packet.binary)
@@ -368,7 +369,8 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
// Called when the socket gets an ack for something it sent
func handleAck(ack:Int, data:AnyObject?) {
SocketLogger.log("Handling ack: \(ack) with data: \(data)", client: self)
SocketLogger.log("Handling ack: %@ with data: %@", client: self,
args: ack, data ?? "")
ackHandlers.executeAck(ack,
items: (data as? [AnyObject]?) ?? (data != nil ? [data!] : nil))
@@ -384,7 +386,8 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
return
}
SocketLogger.log("Handling event: \(event) with data: \(data)", client: self)
SocketLogger.log("Handling event: %@ with data: %@", client: self,
args: event, data ?? "")
if anyHandler != nil {
dispatch_async(dispatch_get_main_queue()) {[weak self] in
@@ -428,7 +431,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
Removes handler(s)
*/
public func off(event:String) {
SocketLogger.log("Removing handler for event: \(event)", client: self)
SocketLogger.log("Removing handler for event: %@", client: self, args: event)
handlers = handlers.filter {$0.event == event ? false : true}
}
@@ -436,10 +439,10 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
/**
Adds a handler for an event.
*/
public func on(name:String, callback:NormalCallback) {
SocketLogger.log("Adding handler for event: \(name)", client: self)
public func on(event:String, callback:NormalCallback) {
SocketLogger.log("Adding handler for event: %@", client: self, args: event)
let handler = SocketEventHandler(event: name, callback: callback)
let handler = SocketEventHandler(event: event, callback: callback)
handlers.append(handler)
}
+24 -4
View File
@@ -24,6 +24,8 @@
import Foundation
private let MESSAGE_LENGTH_MAX = 10000
protocol SocketLogClient {
var log:Bool {get set}
var logType:String {get}
@@ -32,23 +34,41 @@ protocol SocketLogClient {
final class SocketLogger {
private static let printQueue = dispatch_queue_create("printQueue", DISPATCH_QUEUE_SERIAL)
static func log(message:String, client:SocketLogClient, altType:String? = nil) {
private static func shorten(item:AnyObject) -> CVarArgType {
var str = toString(item)
if count(str) > MESSAGE_LENGTH_MAX {
let endIndex = advance(str.startIndex, MESSAGE_LENGTH_MAX)
str = str.substringToIndex(endIndex)
}
return str
}
static func log(message:String, client:SocketLogClient, altType:String? = nil, args:AnyObject...) {
if !client.log {
return
}
dispatch_async(printQueue) {[type = client.logType] in
NSLog("%@: %@", altType ?? type, message)
let newArgs = args.map(SocketLogger.shorten)
let replaced = String(format: message, arguments: newArgs)
NSLog("%@: %@", altType ?? type, replaced)
}
}
static func err(message:String, client:SocketLogClient, altType:String? = nil) {
static func err(message:String, client:SocketLogClient, altType:String? = nil, args:AnyObject...) {
if !client.log {
return
}
dispatch_async(printQueue) {[type = client.logType] in
NSLog("ERROR %@: %@", altType ?? type, message)
let newArgs = args.map(SocketLogger.shorten)
let replaced = String(format: message, arguments: newArgs)
NSLog("ERROR %@: %@", altType ?? type, replaced)
}
}
}
+2 -5
View File
@@ -185,7 +185,7 @@ class SocketParser {
return nsp == "" && socket.nsp != "/"
}
SocketLogger.log("Parsing \(stringMessage)", client: socket, altType: "SocketParser")
SocketLogger.log("Parsing %@", client: socket, altType: "SocketParser", args: stringMessage)
let p:SocketPacket
@@ -196,10 +196,7 @@ class SocketParser {
return
}
// Don't call SocketPacket.description unless we need to
if socket.log {
SocketLogger.log("Decoded packet as: \(p)", client: socket, altType: "SocketParser")
}
SocketLogger.log("Decoded packet as: %@", client: socket, altType: "SocketParser", args: p)
if p.type == SocketPacket.PacketType.EVENT {
if checkNSP(p.nsp) {