Skip to content
This repository has been archived by the owner on Apr 4, 2020. It is now read-only.

Commit

Permalink
Updated to Swift4. Migrated to Starscream
Browse files Browse the repository at this point in the history
  • Loading branch information
mogol committed Jan 14, 2018
1 parent 816ce83 commit 54f517e
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 129 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: objective-c
podfile: Example/Podfile
osx_image: xcode8.2
osx_image: xcode9.1
rvm:
- 2.2.2
before_install:
Expand All @@ -9,4 +9,4 @@ before_install:
- pod install --project-directory=Example
script:
- set -o pipefail && xcodebuild test -workspace Example/CentrifugeiOS.xcworkspace -scheme CentrifugeiOS-Example -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=10.0,name=iPhone SE' ONLY_ACTIVE_ARCH=NO | xcpretty
- pod lib lint
- pod lib lint --allow-warnings
6 changes: 3 additions & 3 deletions CentrifugeiOS.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CentrifugeiOS"
s.version = "3.1.0"
s.version = "4.0.0"
s.summary = "Swifty iOS client for Centrifuge."
s.description = <<-DESC
iOS client for Centrifuge https://github.com/centrifugal/Centrifuge. It uses SwiftWebSocket and helpers classes to communicate with Centrifuge server.
Expand All @@ -16,6 +16,6 @@ Pod::Spec.new do |s|

s.source_files = 'CentrifugeiOS/Classes/**/*'

s.dependency 'SwiftWebSocket', '~>2.6.0'
s.dependency 'IDZSwiftCommonCrypto', '~>0.9.0'
s.dependency 'IDZSwiftCommonCrypto', '~>0.10.0'
s.dependency 'Starscream', '~>3.0.4'
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CentrifugeClientMessageBuilderImpl.swift
// Pods
//
// Created by Herman Saprykin on 18/04/16.
// Created by German Saprykin on 18/04/16.
//
//

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CentrifugeServerMessageParserImpl.swift
// Pods
//
// Created by Herman Saprykin on 19/04/16.
// Created by German Saprykin on 19/04/16.
//
//

Expand Down
3 changes: 1 addition & 2 deletions CentrifugeiOS/Classes/Centrifuge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Centrifugal.swift
// Pods
//
// Created by Herman Saprykin on 18/04/16.
// Created by German Saprykin on 18/04/16.
//
//

Expand All @@ -25,7 +25,6 @@ public class Centrifuge {
client.parser = CentrifugeServerMessageParserImpl()
client.creds = creds
client.url = url
// TODO: Check references cycle
client.delegate = delegate

return client
Expand Down
52 changes: 30 additions & 22 deletions CentrifugeiOS/Classes/CentrifugeClientImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// Clients.swift
// Pods
//
// Created by Herman Saprykin on 20/04/16.
// Created by German Saprykin on 20/04/16.
//
//

import SwiftWebSocket
import Starscream

typealias CentrifugeBlockingHandler = ([CentrifugeServerMessage]?, NSError?) -> Void

class CentrifugeClientImpl: NSObject, WebSocketDelegate, CentrifugeClient {
var ws: CentrifugeWebSocket!
class CentrifugeClientImpl: NSObject, CentrifugeClient, WebSocketDelegate {
var ws: WebSocket!
var url: String!
var creds: CentrifugeCredentials!
var builder: CentrifugeClientMessageBuilder!
Expand All @@ -32,13 +32,13 @@ class CentrifugeClientImpl: NSObject, WebSocketDelegate, CentrifugeClient {
func connect(withCompletion completion: @escaping CentrifugeMessageHandler) {
blockingHandler = connectionProcessHandler
connectionCompletion = completion
ws = CentrifugeWebSocket(url)
ws = WebSocket(url: URL(string: url)!)
ws.delegate = self
ws.connect()
}

func disconnect() {
ws.delegate = nil
ws.close()
ws.disconnect()
}

func ping(withCompletion completion: @escaping CentrifugeMessageHandler) {
Expand All @@ -54,7 +54,7 @@ class CentrifugeClientImpl: NSObject, WebSocketDelegate, CentrifugeClient {
messageCallbacks[message.uid] = completion
send(message: message)
}

func subscribe(toChannel channel: String, delegate: CentrifugeChannelDelegate, lastMessageUID uid: String, completion: @escaping CentrifugeMessageHandler) {
let message = builder.buildSubscribeMessageTo(channel: channel, lastMessageUUID: uid)
subscription[channel] = delegate
Expand Down Expand Up @@ -92,7 +92,11 @@ class CentrifugeClientImpl: NSObject, WebSocketDelegate, CentrifugeClient {
}

func send(message: CentrifugeClientMessage) {
try! ws.send(centrifugeMessage: message)
let dict: [String:Any] = ["uid" : message.uid,
"method" : message.method.rawValue,
"params" : message.params]
let data = try! JSONSerialization.data(withJSONObject: dict, options: JSONSerialization.WritingOptions())
ws.write(data: data)
}

func setupConnectedState() {
Expand Down Expand Up @@ -213,7 +217,7 @@ class CentrifugeClientImpl: NSObject, WebSocketDelegate, CentrifugeClient {
// Client events
case .Disconnect:
delegate?.client(self, didDisconnect: message)
ws.close()
ws.disconnect()
resetState()
case .Refresh:
delegate?.client(self, didReceiveRefresh: message)
Expand All @@ -223,31 +227,35 @@ class CentrifugeClientImpl: NSObject, WebSocketDelegate, CentrifugeClient {
}

//MARK: - WebSocketDelegate
func webSocketOpen() {

func websocketDidConnect(socket: WebSocketClient) {
let message = builder.buildConnectMessage(credentials: creds)
send(message: message)
}

func webSocketMessageText(_ text: String) {
func websocketDidDisconnect(socket: WebSocketClient, error: Error?) {
guard let handler = blockingHandler else { return }
var err: NSError?
if let localizedDescription = error?.localizedDescription {
err = NSError(domain: CentrifugeWebSocketErrorDomain, code: 0, userInfo: [NSLocalizedDescriptionKey : localizedDescription])
}
handler(nil, err)
}

func websocketDidReceiveMessage(socket: WebSocketClient, text: String) {
let data = text.data(using: String.Encoding.utf8)!
let messages = try! parser.parse(data: data)

if let handler = blockingHandler {
handler(messages, nil)
}
}

func webSocketClose(_ code: Int, reason: String, wasClean: Bool) {
if let handler = blockingHandler {
let error = NSError(domain: CentrifugeWebSocketErrorDomain, code: code, userInfo: [NSLocalizedDescriptionKey : reason])
handler(nil, error)
}
func websocketDidReceiveData(socket: WebSocketClient, data: Data) {
let messages = try! parser.parse(data: data)

}

func webSocketError(_ error: NSError) {
if let handler = blockingHandler {
handler(nil, error)
handler(messages, nil)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CentrifugeiOS/Classes/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Messages.swift
// Pods
//
// Created by Herman Saprykin on 18/04/16.
// Created by German Saprykin on 18/04/16.
//
//

Expand Down
2 changes: 1 addition & 1 deletion CentrifugeiOS/Classes/Protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Protocols.swift
// Pods
//
// Created by Herman Saprykin on 26/04/16.
// Created by German Saprykin on 26/04/16.
//
//

Expand Down
21 changes: 0 additions & 21 deletions CentrifugeiOS/Classes/WebSocket.swift

This file was deleted.

46 changes: 41 additions & 5 deletions Example/CentrifugeiOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0810;
LastSwiftMigration = 0900;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0810;
LastSwiftMigration = 0900;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
Expand Down Expand Up @@ -291,9 +291,16 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-CentrifugeiOS_Example/Pods-CentrifugeiOS_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/CentrifugeiOS/CentrifugeiOS.framework",
"${BUILT_PRODUCTS_DIR}/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto.framework",
"${BUILT_PRODUCTS_DIR}/Starscream/Starscream.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CentrifugeiOS.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IDZSwiftCommonCrypto.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Starscream.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand All @@ -306,13 +313,16 @@
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-CentrifugeiOS_Example-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
C82D15DBF4CD35FC4A384A43 /* [CP] Copy Pods Resources */ = {
Expand Down Expand Up @@ -351,13 +361,16 @@
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-CentrifugeiOS_Tests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
F7C77600DD5EC9486A927B36 /* [CP] Embed Pods Frameworks */ = {
Expand All @@ -366,9 +379,16 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-CentrifugeiOS_Tests/Pods-CentrifugeiOS_Tests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/CentrifugeiOS/CentrifugeiOS.framework",
"${BUILT_PRODUCTS_DIR}/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto.framework",
"${BUILT_PRODUCTS_DIR}/Starscream/Starscream.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CentrifugeiOS.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IDZSwiftCommonCrypto.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Starscream.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -418,14 +438,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -466,14 +492,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -510,6 +542,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.CentrifugeiOS-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -524,6 +557,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.CentrifugeiOS-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -543,6 +577,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -558,6 +593,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Loading

0 comments on commit 54f517e

Please sign in to comment.