Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit cb576bf

Browse files
committed
Updating docs
1 parent cbb19a1 commit cb576bf

File tree

4 files changed

+52
-39
lines changed

4 files changed

+52
-39
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ install:
55
- ./install_dependencies.sh
66

77
script:
8-
- bundle exec fastlane ci
8+
- fastlane ci

Classes/RxWebSocket.swift

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,10 @@ import RxSwift
1212
import Starscream
1313

1414

15-
/**
16-
* This is the abstraction over Starscream to make it reactive.
17-
*/
18-
public class RxWebSocket: WebSocket {
15+
/// This is the abstraction over Starscream to make it reactive.
16+
open class RxWebSocket: WebSocket {
1917

20-
/**
21-
Every message received by the websocket is converted to an `StreamEvent`.
22-
23-
- connect: The "connect" message, flagging that the websocket did connect to the server.
24-
- disconnect: A disconnect message that may contain an `Error` containing the reason for the disconection.
25-
- pong: The "pong" message the server may respond to a "ping".
26-
- text: Any string messages received by the client.
27-
- data: Any data messages received by the client, excluding strings.
28-
*/
18+
/// Every message received by the websocket is converted to an `StreamEvent`.
2919
public enum StreamEvent {
3020
/// The "connect" message, flagging that the websocket did connect to the server.
3121
case connect
@@ -43,17 +33,17 @@ public class RxWebSocket: WebSocket {
4333
case data(Data)
4434
}
4535

46-
// MARK: Private Properties
47-
4836
fileprivate let publishStream: PublishSubject<StreamEvent>
4937

5038
/**
51-
The creation of a `RxWebSocket` object. The client is automatically connected to the server uppon initialization.
52-
53-
- parameter url: The server url.
54-
- parameter protocols: The protocols that should be used in the comms. May be nil.
55-
39+
- parameters:
40+
- request: A URL Request to be started.
41+
- protocols: The protocols that should be used in the comms. May be nil.
42+
- stream: A stream to which the client should connect.
43+
5644
- returns: An instance of `RxWebSocket`
45+
46+
The creation of a `RxWebSocket` object. The client is automatically connected to the server uppon initialization.
5747
*/
5848
override public init(request: URLRequest, protocols: [String]? = nil, stream: WSStream = FoundationStream()) {
5949
let publish = PublishSubject<StreamEvent>()
@@ -69,6 +59,22 @@ public class RxWebSocket: WebSocket {
6959

7060
connect()
7161
}
62+
63+
/**
64+
- parameters:
65+
- url: The server url.
66+
- protocols: The protocols that should be used in the comms. May be nil.
67+
68+
- returns: An instance of `RxWebSocket`
69+
70+
The creation of a `RxWebSocket` object. The client is automatically connected to the server uppon initialization.
71+
*/
72+
public convenience init(url: URL, protocols: [String]? = nil) {
73+
self.init(
74+
request: URLRequest(url: url),
75+
protocols: protocols
76+
)
77+
}
7278
}
7379

7480

@@ -84,12 +90,12 @@ public extension Reactive where Base: RxWebSocket {
8490
return Observable.just(text)
8591
}
8692

87-
return ControlProperty(values: values, valueSink: AnyObserver { event in
93+
return ControlProperty(values: values, valueSink: AnyObserver { [weak base] event in
8894
guard case .next(let text) = event else {
8995
return
9096
}
9197

92-
self.base.write(string: text)
98+
base?.write(string: text)
9399
})
94100
}
95101

@@ -103,12 +109,12 @@ public extension Reactive where Base: RxWebSocket {
103109
return Observable.just(data)
104110
}
105111

106-
return ControlProperty(values: values, valueSink: AnyObserver { event in
112+
return ControlProperty(values: values, valueSink: AnyObserver { [weak base] event in
107113
guard case .next(let data) = event else {
108114
return
109115
}
110116

111-
self.base.write(data: data)
117+
base?.write(data: data)
112118
})
113119
}
114120

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ A lightweight abstraction layer over [Starscream](https://github.com/daltoniam/S
1515

1616
## Installation
1717

18-
RxWebSocket is available through [CocoaPods](http://cocoapods.org). To install
19-
it, simply add the following line to your Podfile:
18+
RxWebSocket is available through [CocoaPods](http://cocoapods.org) and
19+
[Carthage](https://github.com/Carthage/Carthage). To install it, simply add the
20+
following line to your depedencies file:
2021

22+
#### Cocoapods
2123
``` ruby
2224
pod "RxWebSocket"
2325
```
2426

27+
#### Carthage
28+
``` ruby
29+
github "fjcaetano/RxWebSocket"
30+
```
31+
2532
## Usage
2633

2734
Every websocket event will be sent to the `stream` which is an `Observable<StreamEvent>`.
@@ -41,12 +48,12 @@ You may receive and send text events by subscribing to the `text` property:
4148
``` swift
4249
let label = UILabel()
4350
socket.rx.text
44-
.bindTo(label.rx.text)
51+
.bind(to: label.rx.text)
4552

4653

4754
sendButton.rx.tap
4855
.flatMap { textField.text ?? "" }
49-
.bindTo(socket.rx.text)
56+
.bind(to: socket.rx.text)
5057
```
5158

5259
For further details, check the Example project.

install_dependencies.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ verify() {
1919
install_fastlane() {
2020
echo "Installing Fastlane"
2121

22-
if [ $(which fastlane) ]; then
22+
if [ $(which fastlane) ] || [ $(bundle check) ]; then
2323
echo ' -> Fastlane already installed'
2424
return
2525
fi
2626

27-
# Installing Homebrew
28-
if [ ! $(which brew) ]; then
29-
echo "Installing Homebrew"
30-
31-
# https://brew.sh/
32-
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" > "$LOGS_PATH/fastlane.log"
27+
# Bundle install
28+
if [ $(which bundle ) ]; then
29+
bundle install
30+
else
31+
gem install bundler
3332
fi
3433

35-
brew cask install fastlane
36-
37-
verify "fastlane"
34+
if [ ! $(bundle check) ]; then
35+
echo "ERROR: fastlane still not installed. Aborting"
36+
exit 1
37+
fi
3838
}
3939

4040
# Autobahn Test Suite

0 commit comments

Comments
 (0)