Git Product home page Git Product logo

rxstarscream's Introduction

RxStarscream

CircleCI pod Carthage compatible

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.2 >= 0.10 >= 4.3
< 4.2 >= 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.

rxstarscream's People

Contributors

cezarykopacz avatar fb55 avatar freak4pc avatar guykahlon avatar ivanbruel avatar pedrommcarrasco avatar rabidaudio avatar yysskk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxstarscream's Issues

Disconnected with optional error : "Connection refused"

When I tried to run the sample project with just basics to connect web socket, getting this error -Disconnected with optional error : Optional(Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused"

@_exported import RxSwift
@_exported import RxStarscream
import Starscream

  override func viewDidLoad() {
        super.viewDidLoad()
 private let disposeBag = DisposeBag()
 
socket = WebSocket(url: URL(string: "ws://localhost:8080/")!)
        socket.connect()

 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)
}

am I doing anything wrong, I could find the solution..

Socket.io connection

Hello ๐Ÿ‘‹,
I wondering is it possible to use RxStarscream with a serveur on Socket.io ? I know I should use Socket.io swift client but have you already try to make it work without the socket.io swift client ? I manage to connect but I get instant disconnect with code error 1000 but according to the RFC 6455 1000 is like a normal closure. If you have any idea or help to provide I will really appreciate it ๐Ÿ˜„ !

MainScheduler.ensureExecutingOnScheduler

RxCocoa DelegateProxyType.proxy(for:) need to excute on main scheduler.
What I think RxCocoa is designed for UI operations.

But websocket may not need to force on the main scheduler.

Update pod

Pod is not in actual state.
Dependency fix from d716e42 is not applied because spec.version is not changed

Update dependencies

  • Swift 4.2 and Xcode 10
  • newest RxSwift and Starscream
  • readme info about older Swift versions

Unable to use pod

Hi,

I'm getting this issue when I run pod update:
RxSwift (~> 2.5.0) required by RxStarscream (0.2)

I am running RxSwift 2.6
Could you please update the dependency.

Best regards,
ZkY.

Not compatible with latest RxSwift

I tried to do a pod install which resulted in the following:

[!] CocoaPods could not find compatible versions for pod "RxSwift":
  In snapshot (Podfile.lock):
    RxSwift (= 6.1.0)

  In Podfile:
    RxCocoa was resolved to 6.1.0, which depends on
      RxSwift (= 6.1.0)

    RxStarscream was resolved to 0.3, which depends on
      RxSwift (~> 2.5.0)

    RxSwift

My Podfile looks like this:

platform :ios, '10.0'

target 'MyApp' do
	use_frameworks!

	pod 'Firebase/Core'
	pod 'Firebase/Analytics'
	pod 'Firebase/Crashlytics'

	pod 'RxSwift'
	pod 'RxCocoa'

	pod 'RxStarscream'
end

Submitting to Cocoapods

Hey @rabidaudio I submitting some changes to comply with Swift 3.

As I'm not the owner or have access at Cocoapods, please feel free to submit a new version -> 0.6.

RxStarscream is not building with carthage

Getting this error when installing with carthage.

ld: '/xxx/Carthage/Checkouts/RxStarscream/Carthage/Build/iOS/RxTest.framework/RxTest' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

I've submitted a P.R. to fix this issue: #10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.