Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ScClient.podspec → SocketClusterClient.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Pod::Spec.new do |s|
# summary should be tweet-length, and the description more in depth.
#

s.name = "ScClient"
s.version = "2.0.1"
s.name = "SocketClusterClient"
s.version = "2.0.4"
s.summary = "A socketcluster client for iOS and OSX."
s.swift_version = '4.0'

Expand All @@ -27,7 +27,7 @@ Pod::Spec.new do |s|
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = "Native iOS/macOS client written in swift. Provides support to for emitting and listening to remote events, publish-subscribe and authentication using JWT"

s.homepage = "https://github.com/sacOO7/socketcluster-client-swift.git"
s.homepage = "https://github.com/benedictchen/socketcluster-client-swift.git"
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


Expand All @@ -52,7 +52,7 @@ Pod::Spec.new do |s|
# profile URL.
#

s.author = { "sacOO7" => "[email protected]" }
s.author = "benedictchen"
# Or just: s.author = "sacOO7"
# s.authors = { "sacOO7" => "[email protected]" }
# s.social_media_url = "http://twitter.com/sacOO7"
Expand Down Expand Up @@ -84,7 +84,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/sacOO7/socketcluster-client-swift.git", :tag => s.version.to_s }
s.source = { :git => "https://github.com/benedictchen/socketcluster-client-swift.git", :tag => s.version.to_s }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down
12 changes: 8 additions & 4 deletions Sources/ScClient/Emitter/Listener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//

import Foundation
public class Listener {
var emitAckListener : [Int : (String, (String, AnyObject?, AnyObject? ) -> Void )]
var onListener :[String : (String, AnyObject?) -> Void]
var onAckListener : [String: (String, AnyObject?, (AnyObject?, AnyObject?) -> Void ) -> Void]
open class Listener {
open var emitAckListener : [Int : (String, (String, AnyObject?, AnyObject? ) -> Void )]
open var onListener :[String : (String, AnyObject?) -> Void]
open var onAckListener : [String: (String, AnyObject?, (AnyObject?, AnyObject?) -> Void ) -> Void]

public init() {
emitAckListener = [Int : (String, (String, AnyObject?, AnyObject? ) -> Void )]()
Expand All @@ -34,6 +34,10 @@ public class Listener {
self.onListener[eventName] = onListener
}

func removeListener(eventName: String) {
self.onListener.removeValue(forKey: eventName)
}

func handleOnListener (eventName : String, data : AnyObject?) {
if let on = onListener[eventName] {
on(eventName, data)
Expand Down
11 changes: 5 additions & 6 deletions Sources/ScClient/client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Starscream
import Foundation


public class ScClient : Listener, WebSocketDelegate {
open class ScClient : Listener, WebSocketDelegate {

var authToken : String?
var url : String?
Expand Down Expand Up @@ -68,13 +68,12 @@ public class ScClient : Listener, WebSocketDelegate {
authToken = ClientUtils.getAuthToken(message: messageObject)
self.onSetAuthentication?(self, authToken)
case .ackReceive:

handleEmitAck(id: rid!, error: error as AnyObject, data: data as AnyObject)
handleEmitAck(id: rid ?? -1, error: error as AnyObject, data: data as AnyObject)
case .event:
if hasEventAck(eventName: eventName!) {
handleOnAckListener(eventName: eventName!, data: data as AnyObject, ack: self.ack(cid: cid!))
if hasEventAck(eventName: eventName ?? "") {
handleOnAckListener(eventName: eventName ?? "", data: data as AnyObject, ack: self.ack(cid: cid!))
} else {
handleOnListener(eventName: eventName!, data: data as AnyObject)
handleOnListener(eventName: eventName ?? "", data: data as AnyObject)
}

}
Expand Down