Skip to content

oanhof/RxWebSocket

 
 

Repository files navigation

RxWebSocket

CI Status Version License Platform codecov


Reactive extensions for websockets.

A lightweight abstraction layer over Starscream to make it reactive.

Installation

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

pod "RxWebSocket"

Usage

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.

License

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

Packages

No packages published

Languages

  • Swift 90.1%
  • Ruby 9.9%