All Projects → PatilShreyas → Livestream Kt

PatilShreyas / Livestream Kt

Licence: mit
LiveStream is a simple class which makes communication easy among different modules of your application.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Livestream Kt

Vsalert
An drop-in replacement for UIAlertController with more power and better looks.
Stars: ✭ 48 (-47.83%)
Mutual labels:  thread
Exoplayer 2 Example
Android example apps
Stars: ✭ 70 (-23.91%)
Mutual labels:  livestream
Livetaiwan
直播地圖
Stars: ✭ 83 (-9.78%)
Mutual labels:  livestream
Mainthreadguard
💂 Tracking UIKit access on main thread
Stars: ✭ 53 (-42.39%)
Mutual labels:  thread
Oscpy
An efficient OSC implementation compatible with python2.7 and 3.5+
Stars: ✭ 65 (-29.35%)
Mutual labels:  thread
Laravel 5 Messenger
A Simple Laravel 5, 6, 7 & 8 Messenger with Pusher Capabilities
Stars: ✭ 75 (-18.48%)
Mutual labels:  thread
Spionio
Lightweight focus group management platform that can capture and replay user interaction on your site and improve the UX in everything you build
Stars: ✭ 40 (-56.52%)
Mutual labels:  livestream
Docker Multistreamer
Dockerized multistreamer
Stars: ✭ 90 (-2.17%)
Mutual labels:  livestream
Diskqueue
A thread-safe, multi-process(ish) persistent queue library for .Net and Mono
Stars: ✭ 66 (-28.26%)
Mutual labels:  thread
Aoe2tools
A lightweight program that lets you easily play your Steam version of Age of Empires 2 HD in Voobly format. In addition to Mega Utilities
Stars: ✭ 82 (-10.87%)
Mutual labels:  livestream
Threadly
Type-safe thread-local storage in Swift
Stars: ✭ 58 (-36.96%)
Mutual labels:  thread
Pelagia
Automatic parallelization (lock-free multithreading thread) tool developed by Surparallel Open Source.Pelagia is embedded key value database that implements a small, fast, high-reliability on ANSI C.
Stars: ✭ 1,132 (+1130.43%)
Mutual labels:  thread
Rpmalloc
Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C
Stars: ✭ 1,218 (+1223.91%)
Mutual labels:  thread
Webfsd
A simple HTTP server for mostly static content written in C
Stars: ✭ 50 (-45.65%)
Mutual labels:  thread
Live Dl
Download live streams from YouTube
Stars: ✭ 82 (-10.87%)
Mutual labels:  livestream
Lushi8
A tutorial for building your own collection of livestream
Stars: ✭ 47 (-48.91%)
Mutual labels:  livestream
Livestream Flutter
Dart package to which makes data communication easy among different modules of your application.
Stars: ✭ 75 (-18.48%)
Mutual labels:  livestream
Justforfunc
The repository for the YouTube series JustForFunc
Stars: ✭ 1,312 (+1326.09%)
Mutual labels:  livestream
Service
Service encapsulates an object which executes a bit of code in a loop that can be started or stopped and query whether it is running or not.
Stars: ✭ 86 (-6.52%)
Mutual labels:  thread
Easyble
Multi-devices process Bluetooth library for Android
Stars: ✭ 81 (-11.96%)
Mutual labels:  thread

LiveStream-Kt (Android) 📱

LiveStream is a data holder class which can observe change of data in real-time and emit values too. Unlike other observables, LiveStream uses different approach. Here's emitter subscriber pattern. It's developed in Kotlin and fully compatible with Java.

Build

Bintray API JavaDoc

Github Followers GitHub stars GitHub forks GitHub watchers Twitter Follow

💡 Introduction

LiveStream is different than any other data observables. As compared to Android Architecture Component's LiveData it's totally different. In LiveData, you need to share the instance and then you need to add observer to listen for changes. It's useful in ViewModel to share data. LiveStream is useful in background and UI data sharing. Here, you need to subscribe to data stream and just need to emit data values and subscribe data stream from anywhere in the application using multiple instances of LiveStream.

For e.g. You have following classes in app-

  • UI Class - MainActivity
  • Service Class - BackgroundService

To share data in both classes, you will just need to add subscriber in UI class (MainActivity). In MainActivity, you'll subscribe to httpResponse stream. In BackgroundService class, whenever you want to share data, you will just need to emit data on stream - ***httpResponse***. Then, those who subscribed for httpResponse data stream will be dispatched on value emission.

⚡️ Getting Started

This library is fully compatible with Java. Here we've demonstrated using Kotlin.

Add Dependency

Add below dependency in build.gradle of your app module.

Latest Build - Bintray

dependencies {
    implementation 'dev.shreyaspatil:LiveStream-kt:0.2'
}

Initialize LiveStream Class

LiveStream is a generic class. You can create instance as below.

        private val liveStream = LiveStream<String>()

Subscribe to Stream / Add Observer

LiveStream event will be dispatched when data is changed. See below code to add observer / subscriber.

Imagine, this code is in UI class of Android (e.g. MainActivity). Whenever value from background task (e.g. Service Class) is emitted, subscriber will listen live changes in data.

        val observer = liveStream.subscribe("httpResponse") { response ->
            showToast("This is HTTP response: $response")
        }

LiveStream#subscribe() method will return instance of StreamObserver. This instance will be useful to unsubscribe from LiveStream.

Emit Values/Data

You can emit values in LiveData from anywhere in the application. See below code.

From Main Thread :

To emit values from main thread, use LiveStream#set() method.

        val response = getResponse()
        liveStream.set("httpResponse", response)

From Other Thread :

To emit values from other thread, use LiveStream#post() method.

        val response = getResponse()
        liveStream.post("httpResponse", response)

Unsubscribe

To unsubscribe stream observer, use LiveStream#unsubscribe() method. It has to pass instance of StreamObserver which is obtained when you called subscribe() method. See below code.

    override fun onStop() {
        super.onStop()
        liveStream.unsubscribe(observer)
    }

🚀 Sample Usage

Sample code is available in /app directory. Both Java & Kotlin code sample available.

🤝 Contribute

If you want to contribute to this library, you're always welcome! See Contributing Guidelines.

✉️ Contact

If you need any help, you can connect with me.

Visit:- shreyaspatil.dev

📃 License

MIT License

Copyright (c) 2020 Shreyas Patil

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].