• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple STOMP Client library, Swift 3 and 4, 4.2, 5 compatible

StompClientLib

License platform Cocoapods

Swift 5.0 Swift 4.2 Swift 3.0 Pod Version Issues

Swift 5+ StompClient Library

Introduction

StompClientLib is a stomp client in Swift. It uses Facebook's SocketRocket as a websocket dependency. SocketRocket is written in Objective-C but StompClientLib's STOMP part is written in Swift and its usage is Swift. You can use this library in your Swift 5+, 4+ and 3+ projects.

Supported Stomp Versions

Stomp version

  • 1.1
  • 1.2
  • Might not be worked with 1.0 (Never tested)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 8.0+
  • XCode 8.1, 8.2, 8.3
  • XCode 9.0+
  • XCode 10.0 +
  • XCode 12.1 +
  • Swift 3.0, 3.1, 3.2
  • Swift 4.0, Swift 4.1, Swift 4.2, Swift 5.0

Installation

StompClientLib is available through CocoaPods. To install it, simply add the following line to your Podfile:

Cocoapods

pod "StompClientLib"

Carthage

github "WrathChaos/StompClientLib"

Usage

import StompClientLib

Once imported, you can open a connection to your WebSocket server.

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

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

func stompClientDidDisconnect(client: StompClientLib!) {
print("Socket is Disconnected")
}

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

func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
print("Destination : \(destination)")
print("JSON Body : \(String(describing: jsonBody))")
print("String Body : \(stringBody ?? "nil")")
}

didReceiveMessageWithJSONBody ( Message Received via STOMP as String )

Your json message will be converted to JSON Body as AnyObject and you will receive your message in this function

func stompClientJSONBody(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
  print("DESTINATION : \(destination)")
  print("String 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

func serverDidSendReceipt(client: StompClientLib!, withReceiptId receiptId: String) {
  print("Receipt : \(receiptId)")
}

serverDidSendError

Your error message will be received in this function

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

func serverDidSendPing() {
  print("Server ping")
}

How to subscribe and unsubscribe

There are functions for subscribing and unsubscribing. Note : You should handle your subscribe and unsubscribe methods ! Suggestion : Subscribe to your topic in "stompClientDidConnect" function and unsubcribe to your topic in stompClientWillDisconnect method.

Subscribe

socketClient.subscribe(destination: topic)
// Note : topic needs to be a String object

Unsubscribe

socketClient.unsubscribe(destination: topic)

Important : You have to send your destination for both subscribe or unsubscribe!

Unsubsribe with header

let destination = "/topic/your_topic"
let ack = destination
let id = destination
let header = ["destination": destination, "ack": ack, "id": id]

// subscribe
socketClient?.subscribeWithHeader(destination: destination, withHeader: header)

// unsubscribe
socketClient?.unsubscribe(destination: subsId)

Auto Reconnect with a given time

You can use this feature if you need to auto reconnect with a specific time or it will just try to reconnect every second.

// Reconnect after 4 sec
socketClient.reconnect(request: NSURLRequest(url: url as URL) , delegate: self as StompClientLibDelegate, time: 4.0)

Auto Disconnect with a given time

// Auto Disconnect after 3 sec
socketClient.autoDisconnect(time: 3)

Login Passcode Implementation

This is just an example. You need to convert to your implementation. #42

let connectFrame = "CONNECT\n login:admin\n passcode:password\n\n\n\0"
socket.write(string: connectFrame)

Future Enhancements

  • Complete a working Example
  • Add Carthage installation option
  • Add Swift Package Manager installation option
  • XCode 9 compatibility
  • Swift 4 compatibility and tests
  • Apple's New Socket for iOS 13 Implementation from stratch

Changelog

Full Changelog

Implemented enhancements:

  • SUBSCRIBE and UNSUBSCRIBE Delegate is missing #16

Closed issues:

  • Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 403" #86
  • the delegate should be weak #83

1.3.8 (2020-03-08)

Full Changelog

Implemented enhancements:

  • Socket stopped working once I moved from ws//: to wss//: #67
  • Self sign certificate, 400 error #66
  • How to increase output buffer #37

Fixed bugs:

  • unable to install #78
  • Number of received messages is limited #76

Closed issues:

  • Can't find header in initial call #81
  • Can't connect to websocket : received bad response code from server 422 #80
  • I just closed the issue because of the stale & reproducible problem #79
  • unable to install #77
  • stompClientDidConnect not called with Spring boot #73
  • Issue with Cookies in header #71
  • Can't see any Websocket traffic in Charles Proxy #70
  • End of stream error #69
  • Cannot connect with Stomp Websocket when custom header #64
  • Can't connect Socket with Spring Boot 2.x.x #63
  • Multiple clients #48
  • IPV6 #38

Merged pull requests:

1.3.7 (2019-08-26)

Full Changelog

Closed issues:

  • The problem when receiving the messages from the Spring boot. #68

1.3.6 (2019-08-06)

Full Changelog

Implemented enhancements:

Fixed bugs:

  • v1.3.4 replaced my custom header in open socket? #58

Closed issues:

  • Json error: The data couldn’t be read because it isn’t in the correct format. #60

Merged pull requests:

  • Fixed ACK id header and added new ACK type #62 (rodmytro)

1.3.5 (2019-07-25)

Full Changelog

Fixed bugs:

  • StompClientDidConnect not called on a fresh project #51

Closed issues:

  • SendJSONForDict error #57
  • Can't connect to websocket with authorization header #39

Merged pull requests:

  • #58 fix open socket with custom header issue #59 (marain87)

1.3.4 (2019-07-19)

Full Changelog

1.3.3 (2019-07-18)

Full Changelog

Closed issues:

  • Missing merge #55
  • Data garbled problem,help #41

Merged pull requests:

  • String body parameter and ':'-in-header-value fix #56 (Erhannis)

1.3.2 (2019-07-10)

Full Changelog

Implemented enhancements:

  • stompClientWillDisconnect missing #44

1.3.1 (2019-06-14)

Full Changelog

Closed issues:

  • Can I subscribe to multiple topics with one stomp client? #47
  • After subscribing to a topic, how to handle messages from server side? #46
  • socket?.readyState is .OPEN and it never goes to my own "stompClientDidDisconnect" method #45
  • Didconnect function cannot be callback after successful connection #43
  • Login, passcode #42
  • App goes in background lock the kepad the socket disconnected #40
  • stompClientDidConnect not called with Spring boot #35
  • Delegate StompClientDidConnect not called after connect->disconnect->connect #15

1.3.0 (2019-04-30)

Full Changelog

Implemented enhancements:

  • invalidate reconnect #36

Closed issues:

  • Should add Carthage #33
  • Invalid Sec-WebSocket-Accept response #32
  • Socket is disconnected with 1007 code as soon as it connected #31
  • enable Assert (self.readyState != SR_CONNECTING) #24

1.2.7 (2018-10-23)

Full Changelog

1.2.6 (2018-10-23)

Full Changelog

Fixed bugs:

  • Error when connected to socket #23

Closed issues:

  • Auto disconnects #11

1.2.5 (2018-10-22)

Full Changelog

Closed issues:

  • Value for "message-id" is always "1" #22
  • Multiple subscription to topics #20
  • I think there is a memory leak for the delegate #19
  • Getting error when framwork is installed in Objective c project #9

1.2.4 (2018-10-17)

Full Changelog

Closed issues:

  • didCloseWithCode 1000, reason: nil #21

1.2.3 (2018-10-17)

Full Changelog

Implemented enhancements:

  • How to receive heartbeat? #18

Closed issues:

  • Socket is not getting connected #30
  • didCloseWithCode 1002 #29
  • No response #27
  • didCloseWithCode 1001, reason: "Stream end encountered" #26
  • Stream end encountered #17
  • unsubscribe socketclient #14
  • It not able to connect web socket. #13
  • One of the delegate method is not being called. #12
  • StompClient Disconnection. #10
  • Unable to find a specification for 'StompClientLib' #8

1.2.2 (2017-11-03)

Full Changelog

1.2.1 (2017-10-31)

Full Changelog

1.2.0 (2017-10-29)

Full Changelog

Closed issues:

  • Let client decide what to do with stomp frame body #4
  • Send message support #3
  • Error when calling delegate #1

1.1.7 (2017-10-02)

Full Changelog

1.1.6 (2017-08-08)

Full Changelog

0.1.5 (2017-07-10)

Full Changelog

0.1.4 (2017-07-10)

Full Changelog

0.1.3 (2017-07-10)

Full Changelog

0.1.2 (2017-07-08)

Full Changelog

0.1.1 (2017-07-08)

Full Changelog

0.1.0 (2017-07-08)

Full Changelog

* This Changelog was automatically generated by github_changelog_generator

Author

FreakyCoder, [email protected]

License

StompClientLib is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

react-native-header-view

Fully customizable Header View with multiple design options for React Native.
Java
548
star
2

react-native-dynamic-search-bar

Medium Article: https://freakycoder.com/react-native-library-dynamic-search-bar-c03fea9fae36
Java
481
star
3

react-native-bouncy-checkbox

Fully customizable animated bouncy checkbox for React Native
Java
462
star
4

react-native-apple-card-views

Customizable and perfect clone of Apple, App Store Card Views for React Native.
Java
336
star
5

react-native-typescript-boilerplate

πŸš€ Awesome fundamental features with Typescript support React Native Boilerplate
TypeScript
210
star
6

react-native-beautiful-timeline

Fully customizable, beautifully designed Timeline for React Native.
Java
175
star
7

react-native-login-screen

πŸš€ Fully Customizable Beautiful React Native Login Screen
TypeScript
155
star
8

react-native-gradient-header

Fully customizable and unique shape Gradient Header for React Native
JavaScript
138
star
9

react-native-header-search-bar

Fully customizable header search bar for React Native
JavaScript
111
star
10

react-native-imaged-carousel-card

Fully customizable & Lovely Imaged Carousel Card for React Native
JavaScript
99
star
11

react-native-dynamic-vector-icons

Wrapper of react-native-vector-icons to use dynamic types
TypeScript
86
star
12

react-native-single-select

Customizable & Easy to Use Single Select Library for React Native
TypeScript
85
star
13

react-native-progressive-fast-image

Customizable progressive image for React Native with FastImage
TypeScript
82
star
14

react-native-internet-connection-alert

Fully customizable internet connection listener with the built-in alert for React Native
Java
74
star
15

react-native-bottom-bar

Fully customizable BottomBar with unique design shape for React Native.
JavaScript
73
star
16

react-native-helpers

All helpers in one; iPhone series support, dimensions helper, hasNotch helper, normalize text helper and text helpers for React Native with very easy useEasy to use & awesome helpers for React Native.
TypeScript
71
star
17

react-native-gradient-card-view

Fully customizable Gradient Card View for React Native.
TypeScript
67
star
18

react-native-bounceable

πŸš€ Animate and bounce any component with RNBounceable for React Native
Java
56
star
19

react-native-typescript-library-starter

Ready to Rock πŸ”₯
JavaScript
53
star
20

react-navigation-helpers

Helpers for React Navigation
Java
49
star
21

MediaPickerLib

Kotlin based media picker library, to pick multiple images and/or vidoes from built-in gallery. Easy to implement and use :)
Kotlin
48
star
22

react-native-floating-action-button

Fully customizable Floating Action Button for React Native
JavaScript
47
star
23

react-native-redux-boilerplate

React Native Redux Boiler Plate
JavaScript
38
star
24

react-native-poll

Voting and poll library for React Native with fully customizable options
TypeScript
38
star
25

react-native-multiple-select

Customizable & Animated, Easy to Use Multiple Select Library for React Native
TypeScript
36
star
26

react-native-button

Fully customizable, Gradient, Outline and Solid Button for React Native.
TypeScript
34
star
27

MJPEGStreamLib

Simple and easy to use MJPEG Stream Library. It contains authentication if your stream url needs a username/password. It is based on UIImageView so it is all up to your custom design.
Swift
32
star
28

react-native-text-input-interactive

Fully customizable, animated text input for React Native with beautiful and elegant design
Java
32
star
29

react-native-duo-toggle-switch

Fully customizable animated duo toggle switch for React Native
Java
31
star
30

react-native-permissions-modal

Awesome & Fully Customizable Permissions Modal for React Native
JavaScript
31
star
31

react-native-time-date-picker

πŸš€ Easy to use time and date picker with lots of options for React Native πŸ₯³
TypeScript
28
star
32

react-native-dynamic-text-loading

Dynamically changes the text while loading screen for React Native. This is the loading like Heartstone and Discord's dynamically changes loading texts :)
JavaScript
27
star
33

react-native-picker-modal

Easy and fully customizable picker modal for React Native
TypeScript
26
star
34

react-native-animation-layout

Custom & Ready to GO partially customizable Animation Layouts for React Native.
JavaScript
25
star
35

react-native-animated-radio-button

Fully customizable animated radio button for React Native
Java
25
star
36

react-native-monthly

Animated and customizable monthly calendar for React Native
TypeScript
24
star
37

react-native-segmented-control-2

πŸš€ React Native Segmented Control, Pure Javascript for iOS and Android
Java
21
star
38

react-native-imaged-card-view

Rising Imaged Card View with Awesome Shadows and Fully Customizable Library for React Native
JavaScript
21
star
39

react-native-animated-component

Animate any component with React Native Animated Component
Java
20
star
40

react-native-easy-state-view

Fully customizable State View for React Native.
Java
20
star
41

react-native-circular-card-view

Fully customizable Circular Card View for React Native
JavaScript
20
star
42

react-native-rounded-checkbox

Rounded Checkbox with animated and fully customizable options library for React Native
TypeScript
20
star
43

react-native-text-area

Simple and easy to use TextArea for React Native.
Java
20
star
44

react-native-bottom-search-bar

Elegant & Cool also fully customizable bottom search bar for React Native.
Java
20
star
45

react-native-permission-service

Easy to use permission service which is all handled by itself for both iOS and Android on React Native
TypeScript
19
star
46

react-native-typescript-zustand-boilerplate

πŸš€ Ready to start Zustand Typescript React Native Boilerplate 🌟
TypeScript
19
star
47

react-native-checkbox-card

Checkbox Card is customizable and animated built-in check state integration for React Native
TypeScript
18
star
48

react-native-counter-input

Counter Input with fully customizable options for React Native
TypeScript
18
star
49

react-native-switch-button

Animated switch button with fully customizable React Native Component
TypeScript
18
star
50

iOS-StatusBar-Example

Medium Article: https://freakycoder.com/ios-notes-13-how-to-change-status-bar-color-1431c185e845
Swift
17
star
51

react-native-bouncy-checkbox-group

Fully customizable bouncy checkbox group for React Native
TypeScript
16
star
52

react-native-social-login-screen

Easy Login Screen with beautiful design and fully customizable options for React Native
TypeScript
16
star
53

react-native-colorful-card

Fully customizable colorful card component for React Native
TypeScript
16
star
54

react-native-animated-radio-button-group

Fully customizable, animated & easy to use radio button group
Java
16
star
55

react-native-subscribe-card

Beautifully designed & fully customizable subscribe card for React Native
TypeScript
15
star
56

react-native-instagram-story-circle

Fully customizable Instagram Story Circle with Bounceable Animated Library for React Native
TypeScript
15
star
57

react-native-alert-modalize

Awesome styled, fully customizable alert modalize for React Native.
JavaScript
14
star
58

react-native-bottom-menu

Fully customizable Bottom Menu for React Native.
JavaScript
14
star
59

react-native-image-swiper

Fully customizable & extremely easy to use Image Swiper for React Native
Java
14
star
60

Instagram-Style-Gradient-Background-Transition

Instagram Style Animated Gradient Background Login Screen
Java
14
star
61

react-native-typescript-redux-boilerplate

Awesome fundamental features with Typescript support and ready to use Redux implementation React Native Boilerplate
TypeScript
13
star
62

react-native-whatsnew-kit

Plug & Play, beautiful WhatsNewKit for React Native
JavaScript
13
star
63

react-native-review-modal

Review Modal with dynamic rate system and comment feature for React Native
JavaScript
12
star
64

react-native-gorgeous-header

Fully customizable & easy to use gorgeous header view for React Native
Java
12
star
65

react-native-flex-divider

Fully customizable flex divider with a easy use for React Native
Java
12
star
66

react-native-star-review

Fully customizable Star Review for React Native.
JavaScript
12
star
67

react-native-shake-text

TypeScript
11
star
68

react-native-custom-text

TypeScript
11
star
69

react-native-ticket-modal

Ready to GO Ticket Modal for React Native.
JavaScript
11
star
70

react-native-checkbox-flex

Fully customizable, easy to use checkbox with flexible component by React Native on Android and iOS
TypeScript
11
star
71

react-native-apple-header

React Native Apple Header
TypeScript
10
star
72

react-native-empty-state

Empty State library which is fully customizable and simple for any state view use-cases
Java
10
star
73

React-Native-Media-Controls

A sweet UI component to manipulate your media
JavaScript
10
star
74

react-native-beautiful-horizontal-list

JavaScript
10
star
75

react-native-premium-table

Fully customizable, easy to use premium table for React Native
Java
9
star
76

react-native-modern-header

React Native Modern Header
Java
9
star
77

react-native-image-picker-modal

Easy to use image picker modal with awesome iOS Picker design for React Native
Java
9
star
78

react-native-global-modal-2

🌍 Global modal and callable from anywhere on the app for React Native
TypeScript
9
star
79

react-native-ios-like-navigation-transition

Java
9
star
80

react-native-basic-modal

Basic & Elegant Modal for React Native
Java
9
star
81

react-native-profile-header

Customizable Profile Header with cool icons for React Native
TypeScript
8
star
82

react-native-social-auth-helper

React Native Social Auth Helper
Java
8
star
83

react-native-text-input

React Native Text Input
Java
8
star
84

react-native-imaged-card

Beautiful and Fully Customizable Imaged Card for React Native
JavaScript
8
star
85

react-native-easy-cached-image

Easy Peasy Cached Image for React Native.
JavaScript
8
star
86

react-native-improved-text-input

Improved Text Input with placeholder style option for React Native
Objective-C
6
star
87

react-native-custom-icon

Medium Article: https://freakycoder.com/react-native-library-react-native-custom-icon-1ec0b734d691
JavaScript
6
star
88

react-native-pure-boilerplate

React Native Pure BoilerPlate
JavaScript
6
star
89

react-native-countdown

Moment based extremely easy to use Countdown for React Native
Java
6
star
90

react-native-multi-grid-selection

Fully customizable Multi Grid Card Selection component for React Native on both iOS and Android
TypeScript
5
star
91

react-native-beautiful-state-view

Fully customizable & Beautiful State View for React Native
Java
5
star
92

React-Native-Translucent-StatusBar-Example

Medium Article:
Objective-C
5
star
93

react-native-rounded-checkbox-group

Fully customizable react native checkbox group for React Native
Java
5
star
94

react-use-state-with-callback

Make the useState hook with a callback for React and React Native
Java
5
star
95

react-native-permission-item

Customizable, easy to use permission item component for React Native
TypeScript
4
star
96

react-native-get-premium-screen

Easy to use and fully customizable get premium screen for React Native
TypeScript
4
star
97

react-native-dash-2

Java
4
star
98

react-native-social-button

Easy & Elegant Social Button for React Native
JavaScript
3
star
99

react-native-splash-screen-example

React Native Notes 25: How to build a native Splash Screen on React Native App?
TypeScript
3
star
100

react-native-card-collection

Easy to use & Ready to Go Fully Customizable Awesome Card Collection for React Native.
JavaScript
3
star