forked from WrathChaos/StompClientLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subscribe and Unsubscibe methods are changed. Unnecessary prints and …
…methods are removed. New ReadME file is added.
- Loading branch information
1 parent
f936d34
commit e057429
Showing
3 changed files
with
106 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,107 @@ it, simply add the following line to your Podfile: | |
pod "StompClientLib" | ||
``` | ||
|
||
## Usage | ||
```ruby | ||
import StompClientLib | ||
``` | ||
|
||
Once imported, you can open a connection to your WebSocket server. | ||
|
||
```ruby | ||
var socketClient = StompClientLib() | ||
let url = NSURL(string: "your-socket-url-is-here")! | ||
socketClient.openSocketWithURLRequest(request: NSURLRequest(url: url as URL) , delegate: self) | ||
``` | ||
|
||
After you are connected, there are some delegate methods that you need to implement. | ||
|
||
## StompClientLibDelegate | ||
|
||
# stompClientDidConnect | ||
```ruby | ||
func stompClientDidConnect(client: StompClientLib!) { | ||
print("Socket is connected") | ||
// Stomp subscribe will be here! | ||
socketClient.subscribe(destination: topic) | ||
// Note : topic needs to be a String object | ||
} | ||
``` | ||
|
||
# stompClientDidDisconnect | ||
```ruby | ||
func stompClientDidDisconnect(client: StompClientLib!) { | ||
print("Socket is Disconnected") | ||
} | ||
``` | ||
|
||
|
||
# stompClientWillDisconnect | ||
```ruby | ||
func stompClientWillDisconnect(client: StompClientLib!, withError error: NSError) { | ||
|
||
} | ||
``` | ||
|
||
# didReceiveMessageWithJSONBody ( Message Received via STOMP ) | ||
|
||
Your json message will be converted to JSON Body as AnyObject and you will receive your message in this function | ||
```ruby | ||
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) { | ||
print("Destination : \(destination)") | ||
print("JSON Body : \(String(describing: jsonBody))") | ||
} | ||
``` | ||
|
||
# serverDidSendReceipt | ||
|
||
If you will use STOMP for in-app purchase, you might need to use this function to get receipt | ||
```ruby | ||
func serverDidSendReceipt(client: StompClientLib!, withReceiptId receiptId: String) { | ||
print("Receipt : \(receiptId)") | ||
} | ||
``` | ||
|
||
#serverDidSendError | ||
|
||
Your error message will be received in this function | ||
|
||
```ruby | ||
func serverDidSendError(client: StompClientLib!, withErrorMessage description: String, detailedErrorMessage message: String?) { | ||
print("Error Send : \(String(describing: message))") | ||
} | ||
``` | ||
|
||
# serverDidSendPing | ||
|
||
If you need to control your server's ping, here is your part | ||
|
||
```ruby | ||
func serverDidSendPing() { | ||
print("Server ping") | ||
} | ||
``` | ||
|
||
|
||
## How to subscribe and unsubscribe | ||
|
||
There are functions for subscribing and unsubscribing. | ||
Note : You should handle your subscribe and unsubscibe methods ! | ||
Suggestion : Subscribe to your topic in "stompClientDidConnect" function and unsubcribe to your topic in stompClientWillDisconnect method. | ||
|
||
# Subscribe | ||
```ruby | ||
socketClient.subscribe(destination: topic) | ||
// Note : topic needs to be a String object | ||
``` | ||
# Unsubscribe | ||
|
||
```ruby | ||
socketClient.unsubscribe(destination: topic) | ||
``` | ||
|
||
Important : You have to send your destination for both subscribe or unsubscribe! | ||
|
||
## Author | ||
|
||
FreakyCoder, [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,9 @@ StompClientLib let the websocket use the Stomp protocol. STOMP Protocol let the | |
s.license = { :type => 'MIT', :file => 'LICENSE' } | ||
s.author = { 'FreakyCoder' => '[email protected]' } | ||
s.source = { :git => 'https://github.com/wrathchaos/StompClientLib.git', :tag => s.version.to_s } | ||
# s.social_media_url = 'https://twitter.com/freakycodercom' | ||
s.social_media_url = 'https://twitter.com/freakycodercom' | ||
|
||
s.ios.deployment_target = '8.0' | ||
s.ios.deployment_target = '10.0' | ||
|
||
s.source_files = 'StompClientLib/Classes/**/*' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters