Latest | 0.9 |
---|---|
Homepage | https://github.com/RxSwiftCommunity/RxStarscream |
License | Apache License, Version 2.0 Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software |
Platforms | ios 8.0, osx 10.10, requires ARC |
Dependencies | Starscream, RxSwift, RxCocoa |
Authors |
A lightweight extension to Starscream to track websocket events using RxSwift observables.
Installation
CocoaPods
RxStarscream is available through CocoaPods.
Add the following line to your Podfile
:
pod 'RxStarscream'
Then run:
pod install
RxStarscream version vs Swift version.
Below is a table that shows which version of RxStarscream you should use for
your Swift version.
Swift | RxStarscream | RxSwift |
---|---|---|
4.X | >= 0.8 | >= 4.0 |
3.X | 0.7 | 3.0.0 – 3.6.1 |
Carthage
Add this to your Cartfile
github "RxSwiftCommunity/RxStarscream"
Then run:
carthage update
Usage examples
After installing via CococPods or Carthage, you should import the framework.
import RxStarscream
Once imported, you can open a connection to your WebSocket server.
socket = WebSocket(url: URL(string: "ws://localhost:8080/")!)
socket.connect()
Now you can subscribe e.g to all of the websocket events:
socket.rx.response.subscribe(onNext: { (response: WebSocketEvent) in
switch response {
case .connected:
print("Connected")
case .disconnected(let error):
print("Disconnected with optional error : (error)")
case .message(let msg):
print("Message : (msg)")
case .data(_):
print("Data")
case .pong:
print("Pong")
}
}).disposed(by: disposeBag)
Or just to a connect event:
socket.rx.connected.subscribe(onNext: { (isConnected: Bool) in
print("Is connected : (isConnected)")
}).disposed(by: disposeBag)
Or just to a message event:
socket.rx.text.subscribe(onNext: { (message: String) in
print("Message : (message)")
}).disposed(by: disposeBag)
Sample Project
There’s a sample project (you need to run carthage update
for it to compile).
The sample project uses echo server – https://www.websocket.org/echo.html
Have fun!
Thanks
Everyone in the RxSwift Slack channel.
Contributing
Bug reports and pull requests are welcome.
License
RxStarscream is available under the MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "RxStarscream", "version": "0.9", "license": { "type": "Apache License, Version 2.0", "text": " Licensed under the Apache License, Version 2.0 (the "License");n you may not use this file except in compliance with the License.n You may obtain a copy of the License atnn http://www.apache.org/licenses/LICENSE-2.0nn Unless required by applicable law or agreed to in writing, softwaren distributed under the License is distributed on an "AS IS" BASIS,n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.n See the License for the specific language governing permissions andn limitations under the License.n" }, "homepage": "https://github.com/RxSwiftCommunity/RxStarscream", "authors": { "Guy Kahlon": "[email protected]" }, "summary": "A lightweight extension to subscribe Starscream websocket events with RxSwift.", "source": { "git": "https://github.com/RxSwiftCommunity/RxStarscream.git", "tag": "0.9" }, "source_files": "Source/*.swift", "requires_arc": true, "platforms": { "ios": "8.0", "osx": "10.10" }, "dependencies": { "Starscream": [ "~> 3.0" ], "RxSwift": [ "~> 4.0" ], "RxCocoa": [ "~> 4.0" ] }, "pushed_with_swift_version": "4.0" }
Sun, 25 Mar 2018 15:00:04 +0000