Skip to content

Commit eab7311

Browse files
committed
create write method that can be used from objc
1 parent 7c0c12b commit eab7311

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

SocketIOClientSwift/SocketEngine.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,9 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
646646
}
647647
}
648648

649+
/**
650+
Write a message, independent of transport.
651+
*/
649652
public func write(msg:String, withType type:PacketType, withData data:ContiguousArray<NSData>?) {
650653
dispatch_async(self.emitQueue) {[weak self] in
651654
if self == nil || !self!.connected {
@@ -662,6 +665,23 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
662665
}
663666
}
664667

668+
/**
669+
Write a message, independent of transport. For Objective-C. withData should be an NSArray of NSData
670+
*/
671+
public func writeObjc(msg:String, withType type:Int, withData data:NSArray?) {
672+
if let pType = PacketType(rawValue: type) {
673+
var arr = ContiguousArray<NSData>()
674+
675+
if data != nil {
676+
for d in data! {
677+
arr.append(d as! NSData)
678+
}
679+
}
680+
681+
self.write(msg, withType: pType, withData: arr)
682+
}
683+
}
684+
665685
// Delagate methods
666686

667687
public func websocketDidConnect(socket:WebSocket) {

SocketIOClientSwift/SocketIOClient.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
490490

491491
self?.reconnectTimer = NSTimer.scheduledTimerWithTimeInterval(Double(self!.reconnectWait),
492492
target: self!, selector: "tryReconnect", userInfo: nil, repeats: true)
493-
return
494493
}
495494
}
496495

0 commit comments

Comments
 (0)