Giter VIP home page Giter VIP logo

reactivesse's Introduction

ReactiveSSE

CI Version License Platform

ReactiveSSE is a ReactiveSwift.SignalProducer acting as Server-Sent Events (SSE) parser. https://www.w3.org/TR/eventsource/

SSE stream is buffered and parsed in a background queue and can be observed via its signal.

Usage

let sse = ReactiveSSE(urlRequest: URLRequest(url: URL(string: endpoint)!))
sse.producer.observe(on: QueueScheduler.main).startWithValues { (v: SSEvent) in
    v.type // String: "message", "update", or whatever
    v.data // String: json payload string, any value string, or whatever
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

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

pod 'ReactiveSSE'

Author

@banjun

License

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

reactivesse's People

Contributors

banjun avatar dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tarag schmitzoide

reactivesse's Issues

Issue with event queue

Hello,
I implemented your library but I do not get all of the events from my SSE server (for example server sent 50 events, but I got only 17). Then, when a new event is sent from the server automatically I still get nothing on iOS until I force manually something new on the server then I get the previous one on iOS that was sent automatically. Like there is some queue in your library which caught it but is not displaying it in the Result <SSEvent, SSError>. We deduced that it's always one behind.

Is it possible that there is some queue in your library with some max value or some setting that I am unaware of?

Event Signal gets out of sync if several event are received in a single batch of data

SSEvent Signal gets out of sync if several events are received from network connection in a single URLSessionDataDelegate didReceiveData call, because only one event is parsed from the data.

Correction in ReactiveOperator.swift:

change

guard let parsed = try? EventStream.event.parse(AnyCollection(buffer)) else { return }
observer.send(value: SSEvent(parsed.output))
buffer = String(parsed.remainder)

to:

while let parsed = try? EventStream.event.parse(AnyCollection(buffer)) {
    observer.send(value: SSEvent(parsed.output))
    buffer = String(parsed.remainder)
 }

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.