diff --git a/README.md b/README.md new file mode 100644 index 0000000..069e00c --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# StompClient +--- +StompClien it's implementation [STOMP](https://stomp.github.io) on native [WebSocket](https://developer.apple.com/documentation/foundation/urlsessionwebsockettask) started support from iOS 13 + +## Requirements +--- + - iOS 13.0+ + - macOS 10.15+ + - Mac Catalyst 13.0+ + - tvOS 13.0+ + - watchOS 6.0+ + +## Example using StompClient +--- +```swift +let request = URLRequest(url: "wss://,ws://") +let webSocket = WebSocket(request: request) +let heartBeat = HeartBeat(clientHeartBeating: "2000,5000") +let stompClient = StompClient(webSocket: webSocket, heartBeat: heartBeat) + +stompClient.stompDelegate = self +stompClient.openWebSocketConnection() +``` + +```request``` request must contain ws:// or wss:// + +```webSocket``` webSocket connection for sending STOMP frames + +```heartBeat``` heartBeat optinal parameter for reciving pong frame and sending ping frame, init with string "2000,5000" where 2000 (in milliseconds) time to sending ping frame to server, 5000 wating handling pong frame from server, for more detail visit [Heart-beating](https://stomp.github.io/stomp-specification-1.2.html#Heart-beating) + +```stompDelegate``` implement handling webSocket connection/disconnection, resiving frames ```CONNECTED, MESSAGE, RECEIPT, ERROR, \n``` + +```openWebSocketConnection()``` open webSocket connection, handle opening webSocket ```func handleWebSocketConnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol: String?)``` then you can use ```sendFrame(frame: StompFrameProtocol)``` + +```closeWebSocketConnection()``` disconnect webSocket connection, handle disconnect webSocket ```func handleWebSocketDisconnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?)``` + +```sendFrame(frame: StompFrameProtocol)``` send STOMP frame via websocket, for sending custom frame (if needed) just subsribe object to `StompFrameProtocol` diff --git a/SwiftStompClient.xcodeproj/project.pbxproj b/SwiftStompClient.xcodeproj/project.pbxproj new file mode 100644 index 0000000..5cc63b7 --- /dev/null +++ b/SwiftStompClient.xcodeproj/project.pbxproj @@ -0,0 +1,591 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 373221D924E3015F0004C746 /* SwiftStompClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 373221D724E3015F0004C746 /* SwiftStompClient.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 373221F024E302C30004C746 /* DisconnectStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221DF24E302C30004C746 /* DisconnectStompFrame.swift */; }; + 373221F124E302C30004C746 /* BasicCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E024E302C30004C746 /* BasicCommands.swift */; }; + 373221F224E302C30004C746 /* UnsubscribeStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E124E302C30004C746 /* UnsubscribeStompFrame.swift */; }; + 373221F324E302C30004C746 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E224E302C30004C746 /* WebSocket.swift */; }; + 373221F424E302C30004C746 /* SubscribeStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E324E302C30004C746 /* SubscribeStompFrame.swift */; }; + 373221F524E302C30004C746 /* SendStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E424E302C30004C746 /* SendStompFrame.swift */; }; + 373221F624E302C30004C746 /* HeartBeat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E524E302C30004C746 /* HeartBeat.swift */; }; + 373221F724E302C30004C746 /* ConnectStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E624E302C30004C746 /* ConnectStompFrame.swift */; }; + 373221F824E302C30004C746 /* AckStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E724E302C30004C746 /* AckStompFrame.swift */; }; + 373221F924E302C30004C746 /* PingStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E824E302C30004C746 /* PingStompFrame.swift */; }; + 373221FA24E302C30004C746 /* HeaderCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E924E302C30004C746 /* HeaderCommands.swift */; }; + 373221FB24E302C30004C746 /* StompFrameProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EA24E302C30004C746 /* StompFrameProtocol.swift */; }; + 373221FC24E302C30004C746 /* SwiftStompClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EB24E302C30004C746 /* SwiftStompClient.swift */; }; + 373221FD24E302C30004C746 /* AckMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EC24E302C30004C746 /* AckMode.swift */; }; + 373221FE24E302C30004C746 /* BeginStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221ED24E302C30004C746 /* BeginStompFrame.swift */; }; + 373221FF24E302C30004C746 /* AbortStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EE24E302C30004C746 /* AbortStompFrame.swift */; }; + 3732220024E302C30004C746 /* CommitStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EF24E302C30004C746 /* CommitStompFrame.swift */; }; + 3732220824E303940004C746 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3732220724E303940004C746 /* AppDelegate.swift */; }; + 3732220A24E303940004C746 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3732220924E303940004C746 /* SceneDelegate.swift */; }; + 3732220C24E303940004C746 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3732220B24E303940004C746 /* ViewController.swift */; }; + 3732220F24E303940004C746 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3732220D24E303940004C746 /* Main.storyboard */; }; + 3732221124E303950004C746 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3732221024E303950004C746 /* Assets.xcassets */; }; + 3732221424E303950004C746 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3732221224E303950004C746 /* LaunchScreen.storyboard */; }; + 3732221A24E306700004C746 /* AbortStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EE24E302C30004C746 /* AbortStompFrame.swift */; }; + 3732221B24E306700004C746 /* AckMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EC24E302C30004C746 /* AckMode.swift */; }; + 3732221C24E306700004C746 /* AckStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E724E302C30004C746 /* AckStompFrame.swift */; }; + 3732221D24E306700004C746 /* BasicCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E024E302C30004C746 /* BasicCommands.swift */; }; + 3732221E24E306700004C746 /* BeginStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221ED24E302C30004C746 /* BeginStompFrame.swift */; }; + 3732221F24E306700004C746 /* CommitStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EF24E302C30004C746 /* CommitStompFrame.swift */; }; + 3732222024E306700004C746 /* ConnectStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E624E302C30004C746 /* ConnectStompFrame.swift */; }; + 3732222124E306700004C746 /* DisconnectStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221DF24E302C30004C746 /* DisconnectStompFrame.swift */; }; + 3732222224E306700004C746 /* HeaderCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E924E302C30004C746 /* HeaderCommands.swift */; }; + 3732222324E306700004C746 /* HeartBeat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E524E302C30004C746 /* HeartBeat.swift */; }; + 3732222424E306700004C746 /* PingStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E824E302C30004C746 /* PingStompFrame.swift */; }; + 3732222524E306700004C746 /* SendStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E424E302C30004C746 /* SendStompFrame.swift */; }; + 3732222624E306700004C746 /* SwiftStompClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EB24E302C30004C746 /* SwiftStompClient.swift */; }; + 3732222724E306700004C746 /* StompFrameProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221EA24E302C30004C746 /* StompFrameProtocol.swift */; }; + 3732222824E306700004C746 /* SubscribeStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E324E302C30004C746 /* SubscribeStompFrame.swift */; }; + 3732222924E306700004C746 /* UnsubscribeStompFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E124E302C30004C746 /* UnsubscribeStompFrame.swift */; }; + 3732222A24E306700004C746 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373221E224E302C30004C746 /* WebSocket.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 373221D424E3015F0004C746 /* SwiftStompClient.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftStompClient.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 373221D724E3015F0004C746 /* SwiftStompClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftStompClient.h; sourceTree = ""; }; + 373221D824E3015F0004C746 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 373221DF24E302C30004C746 /* DisconnectStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisconnectStompFrame.swift; sourceTree = ""; }; + 373221E024E302C30004C746 /* BasicCommands.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCommands.swift; sourceTree = ""; }; + 373221E124E302C30004C746 /* UnsubscribeStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnsubscribeStompFrame.swift; sourceTree = ""; }; + 373221E224E302C30004C746 /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebSocket.swift; sourceTree = ""; }; + 373221E324E302C30004C746 /* SubscribeStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscribeStompFrame.swift; sourceTree = ""; }; + 373221E424E302C30004C746 /* SendStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendStompFrame.swift; sourceTree = ""; }; + 373221E524E302C30004C746 /* HeartBeat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeartBeat.swift; sourceTree = ""; }; + 373221E624E302C30004C746 /* ConnectStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectStompFrame.swift; sourceTree = ""; }; + 373221E724E302C30004C746 /* AckStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AckStompFrame.swift; sourceTree = ""; }; + 373221E824E302C30004C746 /* PingStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PingStompFrame.swift; sourceTree = ""; }; + 373221E924E302C30004C746 /* HeaderCommands.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderCommands.swift; sourceTree = ""; }; + 373221EA24E302C30004C746 /* StompFrameProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StompFrameProtocol.swift; sourceTree = ""; }; + 373221EB24E302C30004C746 /* SwiftStompClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftStompClient.swift; sourceTree = ""; }; + 373221EC24E302C30004C746 /* AckMode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AckMode.swift; sourceTree = ""; }; + 373221ED24E302C30004C746 /* BeginStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BeginStompFrame.swift; sourceTree = ""; }; + 373221EE24E302C30004C746 /* AbortStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AbortStompFrame.swift; sourceTree = ""; }; + 373221EF24E302C30004C746 /* CommitStompFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommitStompFrame.swift; sourceTree = ""; }; + 3732220524E303940004C746 /* SwiftStompClientExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftStompClientExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 3732220724E303940004C746 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 3732220924E303940004C746 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 3732220B24E303940004C746 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 3732220E24E303940004C746 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 3732221024E303950004C746 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 3732221324E303950004C746 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 3732221524E303950004C746 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 3732221924E304C00004C746 /* SwiftStompClientExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SwiftStompClientExample.entitlements; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 373221D124E3015F0004C746 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 3732220224E303940004C746 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 373221CA24E3015F0004C746 = { + isa = PBXGroup; + children = ( + 373221D624E3015F0004C746 /* SwiftStompClient */, + 3732220624E303940004C746 /* SwiftStompClientExample */, + 373221D524E3015F0004C746 /* Products */, + ); + sourceTree = ""; + }; + 373221D524E3015F0004C746 /* Products */ = { + isa = PBXGroup; + children = ( + 373221D424E3015F0004C746 /* SwiftStompClient.framework */, + 3732220524E303940004C746 /* SwiftStompClientExample.app */, + ); + name = Products; + sourceTree = ""; + }; + 373221D624E3015F0004C746 /* SwiftStompClient */ = { + isa = PBXGroup; + children = ( + 373221D724E3015F0004C746 /* SwiftStompClient.h */, + 373221EE24E302C30004C746 /* AbortStompFrame.swift */, + 373221EC24E302C30004C746 /* AckMode.swift */, + 373221E724E302C30004C746 /* AckStompFrame.swift */, + 373221E024E302C30004C746 /* BasicCommands.swift */, + 373221ED24E302C30004C746 /* BeginStompFrame.swift */, + 373221EF24E302C30004C746 /* CommitStompFrame.swift */, + 373221E624E302C30004C746 /* ConnectStompFrame.swift */, + 373221DF24E302C30004C746 /* DisconnectStompFrame.swift */, + 373221E924E302C30004C746 /* HeaderCommands.swift */, + 373221E524E302C30004C746 /* HeartBeat.swift */, + 373221E824E302C30004C746 /* PingStompFrame.swift */, + 373221E424E302C30004C746 /* SendStompFrame.swift */, + 373221EB24E302C30004C746 /* SwiftStompClient.swift */, + 373221EA24E302C30004C746 /* StompFrameProtocol.swift */, + 373221E324E302C30004C746 /* SubscribeStompFrame.swift */, + 373221E124E302C30004C746 /* UnsubscribeStompFrame.swift */, + 373221E224E302C30004C746 /* WebSocket.swift */, + 373221D824E3015F0004C746 /* Info.plist */, + ); + path = SwiftStompClient; + sourceTree = ""; + }; + 3732220624E303940004C746 /* SwiftStompClientExample */ = { + isa = PBXGroup; + children = ( + 3732221924E304C00004C746 /* SwiftStompClientExample.entitlements */, + 3732220724E303940004C746 /* AppDelegate.swift */, + 3732220924E303940004C746 /* SceneDelegate.swift */, + 3732220B24E303940004C746 /* ViewController.swift */, + 3732220D24E303940004C746 /* Main.storyboard */, + 3732221024E303950004C746 /* Assets.xcassets */, + 3732221224E303950004C746 /* LaunchScreen.storyboard */, + 3732221524E303950004C746 /* Info.plist */, + ); + path = SwiftStompClientExample; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 373221CF24E3015F0004C746 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 373221D924E3015F0004C746 /* SwiftStompClient.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 373221D324E3015F0004C746 /* SwiftStompClient */ = { + isa = PBXNativeTarget; + buildConfigurationList = 373221DC24E3015F0004C746 /* Build configuration list for PBXNativeTarget "SwiftStompClient" */; + buildPhases = ( + 373221CF24E3015F0004C746 /* Headers */, + 373221D024E3015F0004C746 /* Sources */, + 373221D124E3015F0004C746 /* Frameworks */, + 373221D224E3015F0004C746 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SwiftStompClient; + productName = SwiftStompClient; + productReference = 373221D424E3015F0004C746 /* SwiftStompClient.framework */; + productType = "com.apple.product-type.framework"; + }; + 3732220424E303940004C746 /* SwiftStompClientExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3732221624E303950004C746 /* Build configuration list for PBXNativeTarget "SwiftStompClientExample" */; + buildPhases = ( + 3732220124E303940004C746 /* Sources */, + 3732220224E303940004C746 /* Frameworks */, + 3732220324E303940004C746 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SwiftStompClientExample; + productName = SwiftStompClientExample; + productReference = 3732220524E303940004C746 /* SwiftStompClientExample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 373221CB24E3015F0004C746 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1160; + LastUpgradeCheck = 1160; + ORGANIZATIONNAME = "Oleksandr Zhurba"; + TargetAttributes = { + 373221D324E3015F0004C746 = { + CreatedOnToolsVersion = 11.6; + LastSwiftMigration = 1160; + }; + 3732220424E303940004C746 = { + CreatedOnToolsVersion = 11.6; + }; + }; + }; + buildConfigurationList = 373221CE24E3015F0004C746 /* Build configuration list for PBXProject "SwiftStompClient" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 373221CA24E3015F0004C746; + productRefGroup = 373221D524E3015F0004C746 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 373221D324E3015F0004C746 /* SwiftStompClient */, + 3732220424E303940004C746 /* SwiftStompClientExample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 373221D224E3015F0004C746 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 3732220324E303940004C746 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3732221424E303950004C746 /* LaunchScreen.storyboard in Resources */, + 3732221124E303950004C746 /* Assets.xcassets in Resources */, + 3732220F24E303940004C746 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 373221D024E3015F0004C746 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 373221F124E302C30004C746 /* BasicCommands.swift in Sources */, + 373221F524E302C30004C746 /* SendStompFrame.swift in Sources */, + 373221FD24E302C30004C746 /* AckMode.swift in Sources */, + 373221F724E302C30004C746 /* ConnectStompFrame.swift in Sources */, + 373221FB24E302C30004C746 /* StompFrameProtocol.swift in Sources */, + 373221FC24E302C30004C746 /* SwiftStompClient.swift in Sources */, + 373221FF24E302C30004C746 /* AbortStompFrame.swift in Sources */, + 373221FE24E302C30004C746 /* BeginStompFrame.swift in Sources */, + 373221F324E302C30004C746 /* WebSocket.swift in Sources */, + 373221F024E302C30004C746 /* DisconnectStompFrame.swift in Sources */, + 373221F924E302C30004C746 /* PingStompFrame.swift in Sources */, + 373221FA24E302C30004C746 /* HeaderCommands.swift in Sources */, + 373221F224E302C30004C746 /* UnsubscribeStompFrame.swift in Sources */, + 373221F824E302C30004C746 /* AckStompFrame.swift in Sources */, + 3732220024E302C30004C746 /* CommitStompFrame.swift in Sources */, + 373221F424E302C30004C746 /* SubscribeStompFrame.swift in Sources */, + 373221F624E302C30004C746 /* HeartBeat.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 3732220124E303940004C746 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3732222624E306700004C746 /* SwiftStompClient.swift in Sources */, + 3732221D24E306700004C746 /* BasicCommands.swift in Sources */, + 3732220C24E303940004C746 /* ViewController.swift in Sources */, + 3732222924E306700004C746 /* UnsubscribeStompFrame.swift in Sources */, + 3732222124E306700004C746 /* DisconnectStompFrame.swift in Sources */, + 3732222824E306700004C746 /* SubscribeStompFrame.swift in Sources */, + 3732220824E303940004C746 /* AppDelegate.swift in Sources */, + 3732221E24E306700004C746 /* BeginStompFrame.swift in Sources */, + 3732222024E306700004C746 /* ConnectStompFrame.swift in Sources */, + 3732222A24E306700004C746 /* WebSocket.swift in Sources */, + 3732221B24E306700004C746 /* AckMode.swift in Sources */, + 3732222424E306700004C746 /* PingStompFrame.swift in Sources */, + 3732221C24E306700004C746 /* AckStompFrame.swift in Sources */, + 3732221A24E306700004C746 /* AbortStompFrame.swift in Sources */, + 3732222524E306700004C746 /* SendStompFrame.swift in Sources */, + 3732220A24E303940004C746 /* SceneDelegate.swift in Sources */, + 3732222224E306700004C746 /* HeaderCommands.swift in Sources */, + 3732222324E306700004C746 /* HeartBeat.swift in Sources */, + 3732221F24E306700004C746 /* CommitStompFrame.swift in Sources */, + 3732222724E306700004C746 /* StompFrameProtocol.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 3732220D24E303940004C746 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 3732220E24E303940004C746 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 3732221224E303950004C746 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 3732221324E303950004C746 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 373221DA24E3015F0004C746 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + 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_IMPLICIT_RETAIN_SELF = 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_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 373221DB24E3015F0004C746 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + 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_IMPLICIT_RETAIN_SELF = 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_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 373221DD24E3015F0004C746 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = SwiftStompClient/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + MARKETING_VERSION = 0.0.1; + PRODUCT_BUNDLE_IDENTIFIER = OZH.SwiftStompClient; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 373221DE24E3015F0004C746 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = SwiftStompClient/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + MARKETING_VERSION = 0.0.1; + PRODUCT_BUNDLE_IDENTIFIER = OZH.SwiftStompClient; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 3732221724E303950004C746 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = SwiftStompClientExample/SwiftStompClientExample.entitlements; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = SwiftStompClientExample/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 0.0.1; + PRODUCT_BUNDLE_IDENTIFIER = OZH.SwiftStompClientExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 3732221824E303950004C746 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = SwiftStompClientExample/SwiftStompClientExample.entitlements; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = SwiftStompClientExample/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 0.0.1; + PRODUCT_BUNDLE_IDENTIFIER = OZH.SwiftStompClientExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 373221CE24E3015F0004C746 /* Build configuration list for PBXProject "SwiftStompClient" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 373221DA24E3015F0004C746 /* Debug */, + 373221DB24E3015F0004C746 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 373221DC24E3015F0004C746 /* Build configuration list for PBXNativeTarget "SwiftStompClient" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 373221DD24E3015F0004C746 /* Debug */, + 373221DE24E3015F0004C746 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 3732221624E303950004C746 /* Build configuration list for PBXNativeTarget "SwiftStompClientExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3732221724E303950004C746 /* Debug */, + 3732221824E303950004C746 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 373221CB24E3015F0004C746 /* Project object */; +} diff --git a/SwiftStompClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/SwiftStompClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..e675da1 --- /dev/null +++ b/SwiftStompClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/SwiftStompClient.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SwiftStompClient.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/SwiftStompClient.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SwiftStompClient.xcodeproj/project.xcworkspace/xcuserdata/oleksandrzhurba.xcuserdatad/UserInterfaceState.xcuserstate b/SwiftStompClient.xcodeproj/project.xcworkspace/xcuserdata/oleksandrzhurba.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..78fb4b4 Binary files /dev/null and b/SwiftStompClient.xcodeproj/project.xcworkspace/xcuserdata/oleksandrzhurba.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SwiftStompClient.xcodeproj/xcuserdata/oleksandrzhurba.xcuserdatad/xcschemes/xcschememanagement.plist b/SwiftStompClient.xcodeproj/xcuserdata/oleksandrzhurba.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..11ca59f --- /dev/null +++ b/SwiftStompClient.xcodeproj/xcuserdata/oleksandrzhurba.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,19 @@ + + + + + SchemeUserState + + SwiftStompClient.xcscheme_^#shared#^_ + + orderHint + 0 + + SwiftStompClientExample.xcscheme_^#shared#^_ + + orderHint + 1 + + + + diff --git a/SwiftStompClient/AbortStompFrame.swift b/SwiftStompClient/AbortStompFrame.swift new file mode 100644 index 0000000..e09f8a7 --- /dev/null +++ b/SwiftStompClient/AbortStompFrame.swift @@ -0,0 +1,15 @@ +public struct AbortStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.abort + } + public var headers: [String : String] + public var body: String? + + ///STOMP frame ABORT with + /// - Parameters: + /// - transactionId: transaction Id + public init(transactionId: String) { + let abortHeaders = [HeaderCommands.transaction : transactionId] + self.headers = abortHeaders + } +} diff --git a/SwiftStompClient/AckMode.swift b/SwiftStompClient/AckMode.swift new file mode 100644 index 0000000..4f050e9 --- /dev/null +++ b/SwiftStompClient/AckMode.swift @@ -0,0 +1,6 @@ +///Server mode AckMode +public enum AckMode: String, CaseIterable { + case clientIndividual = "client-individual" + case client = "client" + case auto = "auto" +} diff --git a/SwiftStompClient/AckStompFrame.swift b/SwiftStompClient/AckStompFrame.swift new file mode 100644 index 0000000..242a88d --- /dev/null +++ b/SwiftStompClient/AckStompFrame.swift @@ -0,0 +1,19 @@ +public struct AckStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.ack + } + public var headers: [String : String] + public var body: String? + + ///STOMP frame ACK with + /// - Parameters: + /// - messageId: message Id + /// - subscription: optional value subscription + public init(messageId: String, subscription: String?) { + var ackHeaders = [HeaderCommands.headerMessageId : messageId] + if let subscription = subscription { + ackHeaders[HeaderCommands.subscription] = subscription + } + self.headers = ackHeaders + } +} diff --git a/SwiftStompClient/BasicCommands.swift b/SwiftStompClient/BasicCommands.swift new file mode 100644 index 0000000..fb09bdc --- /dev/null +++ b/SwiftStompClient/BasicCommands.swift @@ -0,0 +1,15 @@ +///Basic client frames +public struct BasicCommands { + static let connect = "CONNECT" + static let send = "SEND" + static let subscribe = "SUBSCRIBE" + static let unsubscribe = "UNSUBSCRIBE" + static let begin = "BEGIN" + static let commit = "COMMIT" + static let abort = "ABORT" + static let ack = "ACK" + static let disconnect = "DISCONNECT" + static let ping = "\n" + + static let controlChar = "\u{0000}" +} diff --git a/SwiftStompClient/BeginStompFrame.swift b/SwiftStompClient/BeginStompFrame.swift new file mode 100644 index 0000000..66b8624 --- /dev/null +++ b/SwiftStompClient/BeginStompFrame.swift @@ -0,0 +1,15 @@ +public struct BeginStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.begin + } + public var headers: [String : String] + public var body: String? + + ///STOMP frame BEGIN with + /// - Parameters: + /// - transactionId: transaction Id + public init(transactionId: String) { + let beginHeaders = [HeaderCommands.transaction : transactionId] + self.headers = beginHeaders + } +} diff --git a/SwiftStompClient/CommitStompFrame.swift b/SwiftStompClient/CommitStompFrame.swift new file mode 100644 index 0000000..dcbb57c --- /dev/null +++ b/SwiftStompClient/CommitStompFrame.swift @@ -0,0 +1,15 @@ +public struct CommitStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.commit + } + public var headers: [String : String] + public var body: String? + + ///STOMP frame COMMIT with + /// - Parameters: + /// - transactionId: transaction Id + public init(transactionId: String) { + let commitHeaders = [HeaderCommands.transaction : transactionId] + self.headers = commitHeaders + } +} diff --git a/SwiftStompClient/ConnectStompFrame.swift b/SwiftStompClient/ConnectStompFrame.swift new file mode 100644 index 0000000..83abbd1 --- /dev/null +++ b/SwiftStompClient/ConnectStompFrame.swift @@ -0,0 +1,42 @@ +public struct ConnectStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.connect + } + public var headers: [String : String] + public var body: String? + + public var clientHeartBeat: String? + + ///STOMP frame CONNECT with + /// - Parameters: + /// - acceptVersion: accept STOMP version + /// - login: login + /// - passcode: passcode + /// - host: host + /// - heartBeat: optional value heart-beat + public init(acceptVersion: String, login: String, passcode: String, host: String, heartBeat client: String? = nil) { + var connectionHeaders = [HeaderCommands.acceptVersion : acceptVersion, + HeaderCommands.login : login, + HeaderCommands.passcode : passcode, + HeaderCommands.host : host] + if let clientHeartBeat = client { + self.clientHeartBeat = clientHeartBeat + connectionHeaders[HeaderCommands.heartBeat] = clientHeartBeat + } + self.headers = connectionHeaders + } + + ///STOMP frame CONNECT with + /// - Parameters: + /// - acceptVersion: accept STOMP version + /// - heartBeat: optional value heart-beat + public init(acceptVersion: String, heartBeat client: String? = nil) { + var connectionHeaders = [HeaderCommands.acceptVersion : acceptVersion] + + if let clientHeartBeat = client { + self.clientHeartBeat = clientHeartBeat + connectionHeaders[HeaderCommands.heartBeat] = clientHeartBeat + } + self.headers = connectionHeaders + } +} diff --git a/SwiftStompClient/DisconnectStompFrame.swift b/SwiftStompClient/DisconnectStompFrame.swift new file mode 100644 index 0000000..c49b97b --- /dev/null +++ b/SwiftStompClient/DisconnectStompFrame.swift @@ -0,0 +1,15 @@ +import Foundation + +public struct DisconnectStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.disconnect + } + public var headers: [String : String] + public var body: String? + + ///STOMP frame DISCONNECT with disconnected time in + public init() { + let disconnectHeaders = [HeaderCommands.disconnected : "\(Int(Date().timeIntervalSince1970))"] + self.headers = disconnectHeaders + } +} diff --git a/SwiftStompClient/HeaderCommands.swift b/SwiftStompClient/HeaderCommands.swift new file mode 100644 index 0000000..e5c41c5 --- /dev/null +++ b/SwiftStompClient/HeaderCommands.swift @@ -0,0 +1,18 @@ +///Headers commands +public struct HeaderCommands { + static let receipt = "receipt" + static let destination = "destination" + static let destinationId = "id" + static let headerMessageId = "id" + static let contentLength = "content-length" + static let contentType = "content-type" + static let ack = "ack" + static let transaction = "transaction" + static let subscription = "subscription" + static let disconnected = "disconnected" + static let heartBeat = "heart-beat" + static let acceptVersion = "accept-version" + static let login = "login" + static let passcode = "passcode" + static let host = "host" +} diff --git a/SwiftStompClient/HeartBeat.swift b/SwiftStompClient/HeartBeat.swift new file mode 100644 index 0000000..75fb17e --- /dev/null +++ b/SwiftStompClient/HeartBeat.swift @@ -0,0 +1,99 @@ +import Foundation + +public class HeartBeat { + private var timerPing = DispatchSource.makeTimerSource() + private var timerPong: DispatchSourceTimer? + + private let leeway = DispatchTimeInterval.never + + private var clientHeartBeating: String + + private var pingTime: Double = 0.0 + private var pongTime: Double = 0.0 + + public var pingAction: (() -> Void)? + public var pongAction: (() -> Void)? + + public init(clientHeartBeating: String) { + self.clientHeartBeating = clientHeartBeating + } + + public func handleFrames(headers: [String : String], frame: SwiftStompClient.FrameResponseKeys) { + switch frame { + case .connected where headers.contains(where: { $0.key == HeaderCommands.heartBeat }): + heartBeating(client: clientHeartBeating, server: headers[HeaderCommands.heartBeat]!) + case .message: + resetListeningServerBeating() + case .receipt: + resetListeningServerBeating() + case .ping: + resetListeningServerBeating() + default: + return + } + } + + ///reset timer for sending DISCONNECT stomp frame + private func resetListeningServerBeating() { + timerPong?.setEventHandler(handler: nil) + timerPong?.cancel() + timerPong = nil + pongAction = nil + // + startListeningServerBeating() + } + + private func startListeningServerBeating() { + timerPong = DispatchSource.makeTimerSource() + timerPong?.schedule(deadline: .now() + pongTime, repeating: pongTime, leeway: leeway) + timerPong?.setEventHandler(handler: pongAction) + timerPong?.resume() + } + + private func stomAllTimers() { + timerPong?.setEventHandler(handler: nil) + timerPong?.cancel() + timerPong = nil + pongAction = nil + // + timerPing.setEventHandler(handler: nil) + timerPing.cancel() + pingAction = nil + } + + ///Heart-beart implemetation looks like "5000,5000" were first part in client time beating, second part server time beating(miliseconds) + /// - Parameters: + /// - client: client beating + /// - server: server beating + private func heartBeating(client: String, server: String) { + var client = String(client) + var server = String(server) + + guard let commaClientIndex = client.firstIndex(of: ","), + let commaServerIndex = server.firstIndex(of: ",") else { + print("Seams like doesn't contain comma") + return + } + client.remove(at: commaClientIndex) + server.remove(at: commaServerIndex) + + let cx = Int(client[.. 0 { + timerPing.schedule(deadline: .now(), repeating: pingTime, leeway: leeway) + timerPing.setEventHandler(handler: pingAction) + timerPing.activate() + } + + if pongTime > 0 { + startListeningServerBeating() + } + } +} diff --git a/SwiftStompClient/Info.plist b/SwiftStompClient/Info.plist new file mode 100644 index 0000000..c0701c6 --- /dev/null +++ b/SwiftStompClient/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + $(MARKETING_VERSION) + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + + diff --git a/SwiftStompClient/PingStompFrame.swift b/SwiftStompClient/PingStompFrame.swift new file mode 100644 index 0000000..9d36612 --- /dev/null +++ b/SwiftStompClient/PingStompFrame.swift @@ -0,0 +1,9 @@ +public struct PingStompFrame: StompFrameProtocol { + ///STOMP frame PING with empty headers + + public var command: String { + return BasicCommands.ping + } + public var headers: [String : String] = [String : String]() + public var body: String? +} diff --git a/SwiftStompClient/SendStompFrame.swift b/SwiftStompClient/SendStompFrame.swift new file mode 100644 index 0000000..dd7032d --- /dev/null +++ b/SwiftStompClient/SendStompFrame.swift @@ -0,0 +1,35 @@ +public struct SendStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.send + } + public var headers: [String : String] + public var body: String? + + ///STOMP frame SEND with + /// - Parameters: + /// - body: string body + /// - destination: destination + /// - headers: optional headers + /// - transaction: transaction + public init(body: String, destination: String, headers: [String : String]?, transaction: String?) { + var sendHeaders = [String : String]() + + if let additionalHeaders = headers { + sendHeaders = additionalHeaders + } + + if let transaction = transaction { + sendHeaders[HeaderCommands.transaction] = transaction + } + + if !sendHeaders.contains(where: { $0.key == HeaderCommands.contentType }) { + sendHeaders[HeaderCommands.contentType] = "text/plain" + } + + sendHeaders[HeaderCommands.destination] = destination + sendHeaders[HeaderCommands.contentLength] = "\(body.utf8.count)" + + self.headers = sendHeaders + self.body = body + } +} diff --git a/SwiftStompClient/StompFrameProtocol.swift b/SwiftStompClient/StompFrameProtocol.swift new file mode 100644 index 0000000..f26e38a --- /dev/null +++ b/SwiftStompClient/StompFrameProtocol.swift @@ -0,0 +1,5 @@ +public protocol StompFrameProtocol { + var command: String { get } + var headers: [String: String] { get set } + var body: String? { get set } +} diff --git a/SwiftStompClient/SubscribeStompFrame.swift b/SwiftStompClient/SubscribeStompFrame.swift new file mode 100644 index 0000000..b9facc4 --- /dev/null +++ b/SwiftStompClient/SubscribeStompFrame.swift @@ -0,0 +1,29 @@ +public struct SubscribeStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.subscribe + } + public var headers: [String : String] + public var body: String? + + ///STOMP frame SUBSCRIBE with + /// - Parameters: + /// - destination: destination + /// - destinationId: destinationId + /// - ackMode: ack mode by default is auto + public init(destination: String, destinationId: String, ackMode: AckMode = .auto) { + let subscribeHeaders = [HeaderCommands.destination : destination, + HeaderCommands.destinationId : destinationId, + HeaderCommands.ack : ackMode.rawValue] + self.headers = subscribeHeaders + } + + ///STOMP frame SUBSCRIBE with headers + /// - Parameters: + /// - destination: destination + /// - headers: headers + public init(destination: String, headers: [String : String]) { + var subscribeHeaders = headers + subscribeHeaders[HeaderCommands.destination] = destination + self.headers = subscribeHeaders + } +} diff --git a/SwiftStompClient/SwiftStompClient.h b/SwiftStompClient/SwiftStompClient.h new file mode 100644 index 0000000..17498cd --- /dev/null +++ b/SwiftStompClient/SwiftStompClient.h @@ -0,0 +1,16 @@ +// +// SwiftStompClient.h +// SwiftStompClient +// + +#import + +//! Project version number for SwiftStompClient. +FOUNDATION_EXPORT double SwiftStompClientVersionNumber; + +//! Project version string for SwiftStompClient. +FOUNDATION_EXPORT const unsigned char SwiftStompClientVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/SwiftStompClient/SwiftStompClient.swift b/SwiftStompClient/SwiftStompClient.swift new file mode 100644 index 0000000..334247f --- /dev/null +++ b/SwiftStompClient/SwiftStompClient.swift @@ -0,0 +1,182 @@ +import Foundation + +///STOMP protocol handle webSocket open/close state for sending CONNECT STOMP frame +public protocol StompProtocol: class { + func clientSendFrame(result: Result) + func clientReciveFrame(stomp: SwiftStompClient, frameType: SwiftStompClient.FrameResponseKeys, headers: [String: String], body: String?) + func handleWebSocketResponse(result: Result) + func handleWebSocketConnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol: String?) + func handleWebSocketDisconnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) +} + +public class SwiftStompClient { + + ///Basic server frames + public enum FrameResponseKeys: String { + case connected = "CONNECTED" + case message = "MESSAGE" + case receipt = "RECEIPT" + case error = "ERROR" + case ping = "\n" + } + + public let webSocket: WebSocket + public let heartBeat: HeartBeat? + + public weak var stompDelegate: StompProtocol? + + ///Init with webSocket + /// - Parameters: + /// - webSocket: WebSocket + /// - heartBeat: HeartBeat + public init(webSocket: WebSocket, heartBeat: HeartBeat? = nil) { + self.webSocket = webSocket + self.heartBeat = heartBeat + self.webSocket.webSocketDelegate = self + // + sendPingFrame() + sendDisconnectFrame() + } + + private func sendPingFrame() { + heartBeat?.pingAction = { [weak self] in + let pingFrame = PingStompFrame() + self?.sendFrame(frame: pingFrame) + } + } + + private func sendDisconnectFrame() { + heartBeat?.pongAction = { [weak self] in + let disconnectFrame = DisconnectStompFrame() + self?.sendFrame(frame: disconnectFrame) + } + } + + ///Open webSocket connection + public func openWebSocketConnection() { + webSocket.connect() + } + + ///Close webSocket connection + public func closeWebSocketConnection() { + webSocket.disconnect(code: .normalClosure, reason: nil) + } + + ///Send frames via webSocket with + /// - Parameters: + /// - command: basic server commands + /// - headers: additionaly headers for making correct frame + /// - body: body for frame if needed + public func sendFrame(frame: StompFrameProtocol) { + var stompFrame = String() + + //add command + stompFrame.append(frame.command + "\n") + + //add headers + frame.headers.forEach({ + stompFrame.append($0.key + ":" + $0.value + "\n") + }) + + stompFrame.append("\n") + + //add body if exist + if let body = frame.body { + stompFrame.append("\n" + body) + } + + //add control char + stompFrame.append(BasicCommands.controlChar) + + webSocket.webSocketSend(message: .string(stompFrame), onResult: { [weak stompDelegate] in + stompDelegate?.clientSendFrame(result: $0) + }) + } + + ///Handle server frames with heart-beat implementation + private func receiveFrame(commands: String, headers: [String : String], body: String? = nil) { + guard let command = FrameResponseKeys(rawValue: commands) else { + print("ERROR FRAME HANDLING COMMAND: \(commands), HEADERS: \(headers), BODY: \(body?.description ?? "empty body")") + return + } + stompDelegate?.clientReciveFrame(stomp: self, frameType: command, headers: headers, body: body) + heartBeat?.handleFrames(headers: headers, frame: command) + } + + ///Decode string on fragments command, headers, body + private func decodeString(webSocketString: String) { + var headers = [String: String]() + var body = String() + + //handling ping frame + guard webSocketString == "\n" else { + var hasHeaders = true + var contents = webSocketString.components(separatedBy: "\n") + + if contents.first == "" { + contents.removeFirst() + } + + guard let command = contents.first else { + print("current decoded string doesn't containe any command") + return + } + + //remove command after reading + contents.removeFirst() + + contents.forEach({ + if hasHeaders && !$0.isEmpty { + let headersComponents = $0.components(separatedBy: ":") + if let key = headersComponents.first { + headers[key] = headersComponents.dropFirst().joined(separator: ":") + } + } else { + hasHeaders = false + body.append($0) + } + }) + receiveFrame(commands: command, headers: headers, body: body) + return + } + receiveFrame(commands: "\n", headers: headers, body: body) + } + + ///Handle webSocket responce + /// - Parameters: + /// - responce: data, string or error + private func handleWebSocketResult(responce: Result) { + do { + let responce = try responce.get() + switch responce { + case .data(let dataFrame): + guard let decodedFrame = String(data: dataFrame, encoding: .utf8) else { + print("can't convert data to string in function \(#function)") + return + } + decodeString(webSocketString: decodedFrame) + case .string(let frame): + decodeString(webSocketString: frame) + @unknown default: + print("unknown default webSocket responce") + } + } catch let error { + print("webSocket handle error: \(error.localizedDescription)") + } + } +} + +extension SwiftStompClient: WebSocketProtocol { + public func handleConnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol: String?) { + stompDelegate?.handleWebSocketConnect(session: session, webSocketTask: webSocketTask, didOpenWithProtocol: didOpenWithProtocol) + } + + public func handleDisconnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) { + stompDelegate?.handleWebSocketDisconnect(session: session, webSocketTask: webSocketTask, closeCode: closeCode, reason: reason) + } + + public func handleResponse(result: Result) { + handleWebSocketResult(responce: result) + stompDelegate?.handleWebSocketResponse(result: result) + } +} diff --git a/SwiftStompClient/UnsubscribeStompFrame.swift b/SwiftStompClient/UnsubscribeStompFrame.swift new file mode 100644 index 0000000..3ab75bd --- /dev/null +++ b/SwiftStompClient/UnsubscribeStompFrame.swift @@ -0,0 +1,15 @@ +public struct UnsubscribeStompFrame: StompFrameProtocol { + public var command: String { + return BasicCommands.unsubscribe + } + public var headers: [String : String] + public var body: String? + + ///STOMP frame UNSUBSCRIBE with + /// - Parameters: + /// - destination: destination + public init(destination: String) { + let unsubscribeHeaders = [HeaderCommands.destination : destination] + self.headers = unsubscribeHeaders + } +} diff --git a/SwiftStompClient/WebSocket.swift b/SwiftStompClient/WebSocket.swift new file mode 100644 index 0000000..4049a1c --- /dev/null +++ b/SwiftStompClient/WebSocket.swift @@ -0,0 +1,92 @@ +import Network +import Foundation + +public protocol WebSocketProtocol: class { + func handleConnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol: String?) + func handleDisconnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) + func handleResponse(result: Result) +} + +public class WebSocket: NSObject { + ///URLSession with configuration + private lazy var urlSession: URLSession = { [weak self, unowned delegateQueue] in + return URLSession(configuration: .default, delegate: self, delegateQueue: delegateQueue) + }() + + ///Operation queue by default set maximum concurrent operation count + var delegateQueue = OperationQueue() + + ///WebSocket task + var sessionWebSocketTask: URLSessionWebSocketTask! + + ///WebSocket delegate + weak var webSocketDelegate: WebSocketProtocol? + + private(set) var isConnected = false + + ///Init with request + /// - Parameters: + /// - request: must contain ws:// or wss:// + init(request: URLRequest) { + super.init() + self.sessionWebSocketTask = urlSession.webSocketTask(with: request) + } + + ///Send ping with completions + /// - Parameters: + /// - onSuccess: success send ping frame + /// - onError: error with Error + func webSocketSendPing(onSuccess: @escaping (() -> Void), onError: @escaping ((Error) -> Void)) { + sessionWebSocketTask.sendPing(pongReceiveHandler: { + $0 == nil ? onSuccess() : onError($0!) + }) + } + + ///Send webSocket message with completions + /// - Parameters: + /// - message: URLSessionWebSocketTask.Message + /// - onSuccess: successed send webSocket message + /// - onError: error with Error + func webSocketSend(message: URLSessionWebSocketTask.Message, onResult: @escaping ((Result) -> Void)) { + sessionWebSocketTask.send(message, completionHandler: { error in + let result: Result = .init(catching: { + return + }) + onResult(result) + }) + } + + ///Connect webSocket connection + func connect() { + webSocketReceive() + sessionWebSocketTask.resume() + } + + ///Disconnect webSocket connection + func disconnect(code: URLSessionWebSocketTask.CloseCode, reason: Data?) { + sessionWebSocketTask.cancel(with: code, reason: reason) + } + + ///Handle webSocket responce + private func webSocketReceive() { + sessionWebSocketTask.receive(completionHandler: { [weak webSocketDelegate] in + webSocketDelegate?.handleResponse(result: $0) + if let _ = try? $0.get() { + self.webSocketReceive() + } + }) + } +} + +///Handle webSocket open/close actions +extension WebSocket: URLSessionWebSocketDelegate { + public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?) { + webSocketDelegate?.handleConnect(session: session, webSocketTask: webSocketTask, didOpenWithProtocol: `protocol`) + isConnected = true + } + + public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) { + webSocketDelegate?.handleDisconnect(session: session, webSocketTask: webSocketTask, closeCode: closeCode, reason: reason) + isConnected = false + } +} diff --git a/SwiftStompClientExample/AppDelegate.swift b/SwiftStompClientExample/AppDelegate.swift new file mode 100644 index 0000000..79af806 --- /dev/null +++ b/SwiftStompClientExample/AppDelegate.swift @@ -0,0 +1,37 @@ +// +// AppDelegate.swift +// SwiftStompClientExample +// +// Created by Oleksandr Zhurba on 11.08.2020. +// Copyright © 2020 Oleksandr Zhurba. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/SwiftStompClientExample/Assets.xcassets/AppIcon.appiconset/Contents.json b/SwiftStompClientExample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..9221b9b --- /dev/null +++ b/SwiftStompClientExample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftStompClientExample/Assets.xcassets/Contents.json b/SwiftStompClientExample/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/SwiftStompClientExample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftStompClientExample/Base.lproj/LaunchScreen.storyboard b/SwiftStompClientExample/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/SwiftStompClientExample/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SwiftStompClientExample/Base.lproj/Main.storyboard b/SwiftStompClientExample/Base.lproj/Main.storyboard new file mode 100644 index 0000000..25a7638 --- /dev/null +++ b/SwiftStompClientExample/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SwiftStompClientExample/Info.plist b/SwiftStompClientExample/Info.plist new file mode 100644 index 0000000..4c80724 --- /dev/null +++ b/SwiftStompClientExample/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + $(MARKETING_VERSION) + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/SwiftStompClientExample/SceneDelegate.swift b/SwiftStompClientExample/SceneDelegate.swift new file mode 100644 index 0000000..dbff9f4 --- /dev/null +++ b/SwiftStompClientExample/SceneDelegate.swift @@ -0,0 +1,53 @@ +// +// SceneDelegate.swift +// SwiftStompClientExample +// +// Created by Oleksandr Zhurba on 11.08.2020. +// Copyright © 2020 Oleksandr Zhurba. All rights reserved. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/SwiftStompClientExample/SwiftStompClientExample.entitlements b/SwiftStompClientExample/SwiftStompClientExample.entitlements new file mode 100644 index 0000000..ee95ab7 --- /dev/null +++ b/SwiftStompClientExample/SwiftStompClientExample.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.network.client + + + diff --git a/SwiftStompClientExample/ViewController.swift b/SwiftStompClientExample/ViewController.swift new file mode 100644 index 0000000..640eefb --- /dev/null +++ b/SwiftStompClientExample/ViewController.swift @@ -0,0 +1,58 @@ +// +// ViewController.swift +// SwiftStompClientExample +// +// Created by Oleksandr Zhurba on 11.08.2020. +// Copyright © 2020 Oleksandr Zhurba. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + struct NetworkConstants { + static let baseSTOMP = URL(string: "ws://127.0.0.1:8080/ws")! + static let baseWebSocket = URL(string: "wss://echo.websocket.org")! + } + + let webSocket = WebSocket(request: URLRequest(url: NetworkConstants.baseSTOMP)) + + let heartBeat = HeartBeat(clientHeartBeating: "2000,5000") + + lazy var stompClient = SwiftStompClient(webSocket: webSocket, heartBeat: heartBeat) + + override func viewDidLoad() { + super.viewDidLoad() + + stompClient.stompDelegate = self + stompClient.openWebSocketConnection() + } +} + +extension ViewController: StompProtocol { + func clientSendFrame(result: Result) { + print("client did send frame \(result)") + } + + func clientReciveFrame(stomp: SwiftStompClient, frameType: SwiftStompClient.FrameResponseKeys, headers: [String : String], body: String?) { + print("server did recive frame") + print(frameType) + print(stomp) + print(headers) + print(body ?? "empty body") + } + + func handleWebSocketResponse(result: Result) { + print("handle WebSocketResponse \(result)") + } + + func handleWebSocketConnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol: String?) { + print("handle opening webSocket connection") + let connectFrame = ConnectStompFrame(acceptVersion: "1.1,1.2", heartBeat: "2000,5000") + stompClient.sendFrame(frame: connectFrame) + } + + func handleWebSocketDisconnect(session: URLSession, webSocketTask: URLSessionWebSocketTask, closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) { + print("webSocket is disconnected") + } +}