Reactive extensions for websockets.
A lightweight abstraction layer over Starscream to make it reactive.
RxWebSocket is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "RxWebSocket"
Every websocket event will be sent to the stream
which is an Observable<StreamEvent>
.
public enum StreamEvent {
case connect
case disconnect(Error?)
case pong
case text(String)
case data(Data)
}
You may receive and send text events by subscribing to the text
property:
let label = UILabel()
socket.rx.text
.bindTo(label.rx.text)
sendButton.rx.tap
.flatMap { textField.text ?? "" }
.bindTo(socket.rx.text)
For further details, check the Example project.
RxWebSocket is available under the MIT license. See the LICENSE file for more info.